1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-02-22 23:23:57 +01:00
aerc/worker/mbox/io.go
Robin Jarry 73dc39c6ee 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>
2024-08-28 12:06:01 +02:00

49 lines
908 B
Go

package mboxer
import (
"errors"
"io"
"time"
"git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/models"
"github.com/emersion/go-mbox"
)
func Read(r io.Reader) ([]rfc822.RawMessage, error) {
mbr := mbox.NewReader(r)
messages := make([]rfc822.RawMessage, 0)
for {
msg, err := mbr.NextMessage()
if errors.Is(err, io.EOF) {
break
} else if err != nil {
return nil, err
}
content, err := io.ReadAll(msg)
if err != nil {
return nil, err
}
messages = append(messages, &message{
uid: uidFromContents(content),
flags: models.SeenFlag,
content: content,
})
}
return messages, nil
}
func Write(w io.Writer, reader io.Reader, from string, date time.Time) error {
wc := mbox.NewWriter(w)
mw, err := wc.CreateMessage(from, time.Now())
if err != nil {
return err
}
_, err = io.Copy(mw, reader)
if err != nil {
return err
}
return wc.Close()
}