aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2024-08-14 16:59:11 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-28 12:06:01 +0200
commit73dc39c6ee0827fc68b93af8dc438b0e1c14e929 (patch)
treeaff067600ea6326ff179447ed968b6712013b889 /models
parent2950d919a5c5a55bd0eb53d6c41f989d8b70bd55 (diff)
downloadaerc-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 'models')
-rw-r--r--models/models.go34
1 files changed, 31 insertions, 3 deletions
diff --git a/models/models.go b/models/models.go
index 749d14d9..0f7c8445 100644
--- a/models/models.go
+++ b/models/models.go
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
+ "strconv"
"strings"
"time"
@@ -107,6 +108,33 @@ func (c *Capabilities) Has(s string) bool {
return false
}
+type UID string
+
+func UidToUint32(uid UID) uint32 {
+ u, _ := strconv.ParseUint(string(uid), 10, 32)
+ return uint32(u)
+}
+
+func Uint32ToUid(u uint32) UID {
+ return UID(strconv.FormatUint(uint64(u), 10))
+}
+
+func UidToUint32List(uids []UID) []uint32 {
+ ulist := make([]uint32, 0, len(uids))
+ for _, uid := range uids {
+ ulist = append(ulist, UidToUint32(uid))
+ }
+ return ulist
+}
+
+func Uint32ToUidList(ulist []uint32) []UID {
+ uids := make([]UID, 0, len(ulist))
+ for _, u := range ulist {
+ uids = append(uids, Uint32ToUid(u))
+ }
+ return uids
+}
+
// A MessageInfo holds information about the structure of a message
type MessageInfo struct {
BodyStructure *BodyStructure
@@ -118,7 +146,7 @@ type MessageInfo struct {
RFC822Headers *mail.Header
Refs []string
Size uint32
- Uid uint32
+ Uid UID
Error error
}
@@ -169,13 +197,13 @@ func (mi *MessageInfo) References() ([]string, error) {
// A MessageBodyPart can be displayed in the message viewer
type MessageBodyPart struct {
Reader io.Reader
- Uid uint32
+ Uid UID
}
// A FullMessage is the entire message
type FullMessage struct {
Reader io.Reader
- Uid uint32
+ Uid UID
}
type BodyStructure struct {