aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--worker/jmap/cache/cache.go15
-rw-r--r--worker/jmap/configure.go16
2 files changed, 15 insertions, 16 deletions
diff --git a/worker/jmap/cache/cache.go b/worker/jmap/cache/cache.go
index ab264744..07d23493 100644
--- a/worker/jmap/cache/cache.go
+++ b/worker/jmap/cache/cache.go
@@ -5,6 +5,7 @@ import (
"os"
"path"
+ "git.sr.ht/~rjarry/aerc/log"
"github.com/mitchellh/go-homedir"
"github.com/syndtr/goleveldb/leveldb"
)
@@ -15,29 +16,31 @@ type JMAPCache struct {
blobsDir string
}
-func NewJMAPCache(state, blobs bool, accountName string) (*JMAPCache, error) {
+func NewJMAPCache(state, blobs bool, accountName string) *JMAPCache {
c := new(JMAPCache)
cacheDir, err := os.UserCacheDir()
if err != nil {
cacheDir, err = homedir.Expand("~/.cache")
if err != nil {
- return nil, err
+ log.Errorf("homedir.Expand: %s", err)
+ cacheDir = ""
}
}
- if state {
+ if state && cacheDir != "" {
dir := path.Join(cacheDir, "aerc", accountName, "state")
_ = os.MkdirAll(dir, 0o700)
c.file, err = leveldb.OpenFile(dir, nil)
if err != nil {
- return nil, err
+ log.Errorf("failed to open goleveldb: %s", err)
+ c.mem = make(map[string][]byte)
}
} else {
c.mem = make(map[string][]byte)
}
- if blobs {
+ if blobs && cacheDir != "" {
c.blobsDir = path.Join(cacheDir, "aerc", accountName, "blobs")
}
- return c, nil
+ return c
}
var notfound = errors.New("key not found")
diff --git a/worker/jmap/configure.go b/worker/jmap/configure.go
index f57dbd73..dd6f3f36 100644
--- a/worker/jmap/configure.go
+++ b/worker/jmap/configure.go
@@ -11,6 +11,12 @@ import (
)
func (w *JMAPWorker) handleConfigure(msg *types.Configure) error {
+ w.config.cacheState = parseBool(msg.Config.Params["cache-state"])
+ w.config.cacheBlobs = parseBool(msg.Config.Params["cache-blobs"])
+ w.config.useLabels = parseBool(msg.Config.Params["use-labels"])
+ w.cache = cache.NewJMAPCache(
+ w.config.cacheState, w.config.cacheBlobs, msg.Config.Name)
+
u, err := url.Parse(msg.Config.Source)
if err != nil {
return err
@@ -36,9 +42,6 @@ func (w *JMAPWorker) handleConfigure(msg *types.Configure) error {
w.config.endpoint = u.String()
w.config.account = msg.Config
- w.config.cacheState = parseBool(msg.Config.Params["cache-state"])
- w.config.cacheBlobs = parseBool(msg.Config.Params["cache-blobs"])
- w.config.useLabels = parseBool(msg.Config.Params["use-labels"])
w.config.allMail = msg.Config.Params["all-mail"]
if w.config.allMail == "" {
w.config.allMail = "All mail"
@@ -51,13 +54,6 @@ func (w *JMAPWorker) handleConfigure(msg *types.Configure) error {
w.config.serverPing = dur
}
- c, err := cache.NewJMAPCache(
- w.config.cacheState, w.config.cacheBlobs, msg.Config.Name)
- if err != nil {
- return err
- }
- w.cache = c
-
return nil
}