diff options
author | Robin Jarry <robin@jarry.cc> | 2022-12-21 11:31:04 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-04 22:57:31 +0100 |
commit | 5677f93ff8e0f212be112a110fcfe09663c84f98 (patch) | |
tree | 9f47f430b312d1f0dc1acdd3735cfd76ad21e0f0 /worker/imap/imap.go | |
parent | 36fded03e762da97edde61559c8bf60d5749d6a2 (diff) | |
download | aerc-5677f93ff8e0f212be112a110fcfe09663c84f98.tar.gz |
model: change flags array to bitmask
Using a list of integers is not optimal. Use a bit mask instead.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'worker/imap/imap.go')
-rw-r--r-- | worker/imap/imap.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/worker/imap/imap.go b/worker/imap/imap.go index 6e1341b2..82ee2e2e 100644 --- a/worker/imap/imap.go +++ b/worker/imap/imap.go @@ -79,7 +79,7 @@ func translateAddresses(addrs []*imap.Address) []*mail.Address { return converted } -var imapToFlag = map[string]models.Flag{ +var imapToFlag = map[string]models.Flags{ imap.SeenFlag: models.SeenFlag, imap.RecentFlag: models.RecentFlag, imap.AnsweredFlag: models.AnsweredFlag, @@ -87,7 +87,7 @@ var imapToFlag = map[string]models.Flag{ imap.FlaggedFlag: models.FlaggedFlag, } -var flagToImap = map[models.Flag]string{ +var flagToImap = map[models.Flags]string{ models.SeenFlag: imap.SeenFlag, models.RecentFlag: imap.RecentFlag, models.AnsweredFlag: imap.AnsweredFlag, @@ -95,20 +95,20 @@ var flagToImap = map[models.Flag]string{ models.FlaggedFlag: imap.FlaggedFlag, } -func translateImapFlags(imapFlags []string) []models.Flag { - var flags []models.Flag +func translateImapFlags(imapFlags []string) models.Flags { + var flags models.Flags for _, imapFlag := range imapFlags { if flag, ok := imapToFlag[imapFlag]; ok { - flags = append(flags, flag) + flags |= flag } } return flags } -func translateFlags(flags []models.Flag) []string { +func translateFlags(flags models.Flags) []string { var imapFlags []string - for _, flag := range flags { - if imapFlag, ok := flagToImap[flag]; ok { + for flag, imapFlag := range flagToImap { + if flags.Has(flag) { imapFlags = append(imapFlags, imapFlag) } } |