diff options
author | Robin Jarry <robin@jarry.cc> | 2024-08-14 16:59:11 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-08-28 12:06:01 +0200 |
commit | 73dc39c6ee0827fc68b93af8dc438b0e1c14e929 (patch) | |
tree | aff067600ea6326ff179447ed968b6712013b889 /worker/imap/extensions/xgmext | |
parent | 2950d919a5c5a55bd0eb53d6c41f989d8b70bd55 (diff) | |
download | aerc-73dc39c6ee0827fc68b93af8dc438b0e1c14e929.tar.gz |
treewide: replace uint32 uids with opaque strings
Add a new models.UID type (an alias to string). Replace all occurrences
of uint32 being used as message UID or thread UID with models.UID.
Update all workers to only expose models.UID values and deal with the
conversion internally. Only IMAP needs to convert these to uint32. All
other backends already use plain strings as message identifiers, in
which case no conversion is even needed.
The directory tree implementation needed to be heavily refactored in
order to accommodate thread UID not being usable as a list index.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'worker/imap/extensions/xgmext')
-rw-r--r-- | worker/imap/extensions/xgmext/client.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/worker/imap/extensions/xgmext/client.go b/worker/imap/extensions/xgmext/client.go index 65f11e74..e6e34a44 100644 --- a/worker/imap/extensions/xgmext/client.go +++ b/worker/imap/extensions/xgmext/client.go @@ -5,6 +5,7 @@ import ( "fmt" "git.sr.ht/~rjarry/aerc/lib/log" + "git.sr.ht/~rjarry/aerc/models" "github.com/emersion/go-imap" "github.com/emersion/go-imap/client" "github.com/emersion/go-imap/commands" @@ -19,7 +20,7 @@ func NewHandler(c *client.Client) *handler { return &handler{client: c} } -func (h handler) FetchEntireThreads(requested []uint32) ([]uint32, error) { +func (h handler) FetchEntireThreads(requested []models.UID) ([]models.UID, error) { threadIds, err := h.fetchThreadIds(requested) if err != nil { return nil, @@ -33,7 +34,7 @@ func (h handler) FetchEntireThreads(requested []uint32) ([]uint32, error) { return uids, nil } -func (h handler) fetchThreadIds(uids []uint32) ([]string, error) { +func (h handler) fetchThreadIds(uids []models.UID) ([]string, error) { messages := make(chan *imap.Message) done := make(chan error) @@ -58,7 +59,9 @@ func (h handler) fetchThreadIds(uids []uint32) ([]string, error) { }() var set imap.SeqSet - set.AddNum(uids...) + for _, uid := range uids { + set.AddNum(models.UidToUint32(uid)) + } err := h.client.UidFetch(&set, items, messages) <-done @@ -69,18 +72,18 @@ func (h handler) fetchThreadIds(uids []uint32) ([]string, error) { return thrid, err } -func (h handler) searchUids(thrid []string) ([]uint32, error) { +func (h handler) searchUids(thrid []string) ([]models.UID, error) { if len(thrid) == 0 { return nil, errors.New("no thread IDs provided") } return h.runSearch(NewThreadIDSearch(thrid)) } -func (h handler) RawSearch(rawSearch string) ([]uint32, error) { +func (h handler) RawSearch(rawSearch string) ([]models.UID, error) { return h.runSearch(NewRawSearch(rawSearch)) } -func (h handler) runSearch(cmd imap.Commander) ([]uint32, error) { +func (h handler) runSearch(cmd imap.Commander) ([]models.UID, error) { if h.client.State() != imap.SelectedState { return nil, errors.New("no mailbox selected") } @@ -90,5 +93,9 @@ func (h handler) runSearch(cmd imap.Commander) ([]uint32, error) { if err != nil { return nil, fmt.Errorf("imap execute failed: %w", err) } - return res.Ids, status.Err() + var uids []models.UID + for _, i := range res.Ids { + uids = append(uids, models.Uint32ToUid(i)) + } + return uids, status.Err() } |