diff options
author | Moritz Poldrack <git@moritz.sh> | 2023-05-09 17:19:42 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-05-16 13:56:58 +0200 |
commit | 2040fc1885ca4b4bea07d91e9fc6a0aaebfe7133 (patch) | |
tree | 0df09ba088414a5d74081e6a61c68afc2141c5a8 /worker | |
parent | 0eaf05d3fa6295e7df06793a967d3389d2a0f7d8 (diff) | |
download | aerc-2040fc1885ca4b4bea07d91e9fc6a0aaebfe7133.tar.gz |
imap: use delimiter from server
To accommodate servers that use a delimiter other than "/" ("." being a
common alternative), the delimiter is fetched from the server when
connecting.
Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/connect.go | 11 | ||||
-rw-r--r-- | worker/imap/worker.go | 18 | ||||
-rw-r--r-- | worker/maildir/worker.go | 7 | ||||
-rw-r--r-- | worker/mbox/worker.go | 4 | ||||
-rw-r--r-- | worker/notmuch/worker.go | 7 | ||||
-rw-r--r-- | worker/types/worker.go | 5 |
6 files changed, 47 insertions, 5 deletions
diff --git a/worker/imap/connect.go b/worker/imap/connect.go index 6f341753..f0ed8043 100644 --- a/worker/imap/connect.go +++ b/worker/imap/connect.go @@ -94,6 +94,17 @@ func (w *IMAPWorker) connect() (*client.Client, error) { return nil, err } + info := make(chan *imap.MailboxInfo, 1) + if err := c.List("", "", info); err != nil { + return nil, fmt.Errorf("failed to retrieve delimiter: %w", err) + } + mailboxinfo := <-info + w.delimiter = mailboxinfo.Delimiter + if w.delimiter == "" { + // just in case some implementation does not follow standards + w.delimiter = "/" + } + return c, nil } diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 1f61f458..f9a722e6 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -61,11 +61,12 @@ type imapConfig struct { type IMAPWorker struct { config imapConfig - client *imapClient - selected *imap.MailboxStatus - updates chan client.Update - worker *types.Worker - seqMap SeqMap + client *imapClient + selected *imap.MailboxStatus + updates chan client.Update + worker *types.Worker + seqMap SeqMap + delimiter string idler *idler observer *observer @@ -311,3 +312,10 @@ func (w *IMAPWorker) Run() { func (w *IMAPWorker) Capabilities() *models.Capabilities { return w.caps } + +func (w *IMAPWorker) PathSeparator() string { + if w.delimiter == "" { + return "/" + } + return w.delimiter +} diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index ba72432c..b222aab8 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -108,6 +108,13 @@ func (w *Worker) Capabilities() *models.Capabilities { return w.capabilities } +func (w *Worker) PathSeparator() string { + if w.maildirpp { + return "." + } + return string(os.PathSeparator) +} + func (w *Worker) handleAction(action types.WorkerMessage) { msg := w.worker.ProcessAction(action) switch msg := msg.(type) { diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go index fbdbec36..47713048 100644 --- a/worker/mbox/worker.go +++ b/worker/mbox/worker.go @@ -383,6 +383,10 @@ func (w *mboxWorker) Capabilities() *models.Capabilities { return w.capabilities } +func (w *mboxWorker) PathSeparator() string { + return "/" +} + func filterUids(folder *container, uids []uint32, args []string) ([]uint32, error) { criteria, err := lib.GetSearchCriteria(args) if err != nil { diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 6b1b64d9..d5c012ad 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -109,6 +109,13 @@ func (w *worker) Capabilities() *models.Capabilities { return w.capabilities } +func (w *worker) PathSeparator() string { + // make it configurable? + // <rockorager> You can use those in query maps to force a tree + // <rockorager> Might be nice to be configurable? I see some notmuch people namespace with "::" + return "/" +} + func (w *worker) done(msg types.WorkerMessage) { w.w.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil) } diff --git a/worker/types/worker.go b/worker/types/worker.go index 55e00faf..7033bf77 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -15,6 +15,7 @@ var lastId int64 = 1 // access via atomic type Backend interface { Run() Capabilities() *models.Capabilities + PathSeparator() string } type Worker struct { @@ -179,3 +180,7 @@ func (worker *Worker) PostMessageInfoError(msg WorkerMessage, uid uint32, err er Message: RespondTo(msg), }, nil) } + +func (worker *Worker) PathSeparator() string { + return worker.Backend.PathSeparator() +} |