aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-17 14:40:08 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:24:55 +0200
commit57088312fdd8e602a084bd5736a0e22a34be9ec0 (patch)
tree8c5544262cf8c1772ec661748cfa4d5491ff4c77
parent591659b52867cb118d1f82d41693a02123935e0c (diff)
downloadaerc-57088312fdd8e602a084bd5736a0e22a34be9ec0.tar.gz
worker: move shared code to lib
Avoid importing code from worker/lib into lib. It should only be the other way around. Move the message parsing code used by maildir, notmuch, mbox and the eml viewer into a lib/rfc822 package. Adapt imports accordingly. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
-rw-r--r--lib/emlview.go10
-rw-r--r--lib/messageview.go12
-rw-r--r--lib/parse/daterange.go (renamed from worker/lib/daterange.go)8
-rw-r--r--lib/parse/daterange_test.go (renamed from worker/lib/daterange_test.go)34
-rw-r--r--lib/rfc822/message.go (renamed from worker/lib/parse.go)34
-rw-r--r--lib/rfc822/message_test.go (renamed from worker/lib/parse_test.go)7
-rw-r--r--lib/rfc822/testdata/message/invalid/hexa (renamed from worker/lib/testdata/message/invalid/hexa)0
-rw-r--r--lib/rfc822/testdata/message/valid/quoted-mime-type (renamed from worker/lib/testdata/message/valid/quoted-mime-type)0
-rw-r--r--worker/imap/search.go4
-rw-r--r--worker/jmap/search.go4
-rw-r--r--worker/lib/headers.go29
-rw-r--r--worker/lib/search.go10
-rw-r--r--worker/lib/size.go15
-rw-r--r--worker/maildir/message.go9
-rw-r--r--worker/maildir/search.go4
-rw-r--r--worker/mbox/io.go6
-rw-r--r--worker/mbox/models.go8
-rw-r--r--worker/mbox/worker.go13
-rw-r--r--worker/notmuch/message.go7
19 files changed, 116 insertions, 98 deletions
diff --git a/lib/emlview.go b/lib/emlview.go
index ab3ce87e..e27edcb0 100644
--- a/lib/emlview.go
+++ b/lib/emlview.go
@@ -8,8 +8,8 @@ import (
_ "github.com/emersion/go-message/charset"
"git.sr.ht/~rjarry/aerc/lib/crypto"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/models"
- "git.sr.ht/~rjarry/aerc/worker/lib"
)
// EmlMessage implements the RawMessage interface
@@ -37,7 +37,7 @@ func NewEmlMessageView(full []byte, pgp crypto.Provider,
decryptKeys openpgp.PromptFunction, cb func(MessageView, error),
) {
eml := EmlMessage(full)
- messageInfo, err := lib.MessageInfo(&eml)
+ messageInfo, err := rfc822.MessageInfo(&eml)
if err != nil {
cb(nil, err)
return
@@ -52,7 +52,7 @@ func NewEmlMessageView(full []byte, pgp crypto.Provider,
}
if usePGP(messageInfo.BodyStructure) {
- reader := lib.NewCRLFReader(bytes.NewReader(full))
+ reader := rfc822.NewCRLFReader(bytes.NewReader(full))
md, err := pgp.Decrypt(reader, decryptKeys)
if err != nil {
cb(nil, err)
@@ -65,12 +65,12 @@ func NewEmlMessageView(full []byte, pgp crypto.Provider,
return
}
}
- entity, err := lib.ReadMessage(bytes.NewBuffer(msv.message))
+ entity, err := rfc822.ReadMessage(bytes.NewBuffer(msv.message))
if err != nil {
cb(nil, err)
return
}
- bs, err := lib.ParseEntityStructure(entity)
+ bs, err := rfc822.ParseEntityStructure(entity)
if err != nil {
cb(nil, err)
return
diff --git a/lib/messageview.go b/lib/messageview.go
index f2d30086..6c478c6e 100644
--- a/lib/messageview.go
+++ b/lib/messageview.go
@@ -10,9 +10,9 @@ import (
_ "github.com/emersion/go-message/charset"
"git.sr.ht/~rjarry/aerc/lib/crypto"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
- "git.sr.ht/~rjarry/aerc/worker/lib"
"git.sr.ht/~rjarry/aerc/worker/types"
)
@@ -94,7 +94,7 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool,
if usePGP(messageInfo.BodyStructure) {
msv.FetchFull(func(fm io.Reader) {
- reader := lib.NewCRLFReader(fm)
+ reader := rfc822.NewCRLFReader(fm)
md, err := pgp.Decrypt(reader, decryptKeys)
if err != nil {
cb(nil, err)
@@ -105,12 +105,12 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool,
cb(nil, err)
return
}
- decrypted, err := lib.ReadMessage(bytes.NewBuffer(msv.message))
+ decrypted, err := rfc822.ReadMessage(bytes.NewBuffer(msv.message))
if err != nil {
cb(nil, err)
return
}
- bs, err := lib.ParseEntityStructure(decrypted)
+ bs, err := rfc822.ParseEntityStructure(decrypted)
if err != nil {
cb(nil, err)
return
@@ -162,11 +162,11 @@ func (msv *MessageStoreView) FetchBodyPart(part []int, cb func(io.Reader)) {
}
buf := bytes.NewBuffer(msv.message)
- msg, err := lib.ReadMessage(buf)
+ msg, err := rfc822.ReadMessage(buf)
if err != nil {
panic(err)
}
- reader, err := lib.FetchEntityPartReader(msg, part)
+ reader, err := rfc822.FetchEntityPartReader(msg, part)
if err != nil {
errMsg := fmt.Errorf("Failed to fetch message part: %w", err)
log.Errorf(errMsg.Error())
diff --git a/worker/lib/daterange.go b/lib/parse/daterange.go
index b08bf177..bd984ed5 100644
--- a/worker/lib/daterange.go
+++ b/lib/parse/daterange.go
@@ -1,4 +1,4 @@
-package lib
+package parse
import (
"fmt"
@@ -20,7 +20,7 @@ const dateFmt = "2006-01-02"
// allowed.
//
// Relative date terms (such as "1 week 1 day" or "1w 1d") can be used, too.
-func ParseDateRange(s string) (start, end time.Time, err error) {
+func DateRange(s string) (start, end time.Time, err error) {
s = cleanInput(s)
s = ensureRangeOp(s)
i := strings.Index(s, "..")
@@ -294,7 +294,7 @@ func translate(s string) (time.Time, error) {
// if next characters is integer, then parse a relative date
if '0' <= s[0] && s[0] <= '9' && hasUnit(s) {
- relDate, err := ParseRelativeDate(s)
+ relDate, err := RelativeDate(s)
if err != nil {
log.Errorf("could not parse relative date from '%s': %v",
s0, err)
@@ -372,7 +372,7 @@ func (d RelDate) Apply(t time.Time) time.Time {
// 5w1d
//
// Adapted from the Go stdlib in src/time/format.go
-func ParseRelativeDate(s string) (RelDate, error) {
+func RelativeDate(s string) (RelDate, error) {
s0 := s
s = cleanInput(s)
var da RelDate
diff --git a/worker/lib/daterange_test.go b/lib/parse/daterange_test.go
index 807e7ac7..ff2ae078 100644
--- a/worker/lib/daterange_test.go
+++ b/lib/parse/daterange_test.go
@@ -1,16 +1,16 @@
-package lib_test
+package parse_test
import (
"reflect"
"testing"
"time"
- "git.sr.ht/~rjarry/aerc/worker/lib"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
)
func TestParseDateRange(t *testing.T) {
dateFmt := "2006-01-02"
- parse := func(s string) time.Time { d, _ := time.Parse(dateFmt, s); return d }
+ date := func(s string) time.Time { d, _ := time.Parse(dateFmt, s); return d }
tests := []struct {
s string
start time.Time
@@ -18,26 +18,26 @@ func TestParseDateRange(t *testing.T) {
}{
{
s: "2022-11-01",
- start: parse("2022-11-01"),
- end: parse("2022-11-02"),
+ start: date("2022-11-01"),
+ end: date("2022-11-02"),
},
{
s: "2022-11-01..",
- start: parse("2022-11-01"),
+ start: date("2022-11-01"),
},
{
s: "..2022-11-05",
- end: parse("2022-11-05"),
+ end: date("2022-11-05"),
},
{
s: "2022-11-01..2022-11-05",
- start: parse("2022-11-01"),
- end: parse("2022-11-05"),
+ start: date("2022-11-01"),
+ end: date("2022-11-05"),
},
}
for _, test := range tests {
- start, end, err := lib.ParseDateRange(test.s)
+ start, end, err := parse.DateRange(test.s)
if err != nil {
t.Errorf("ParseDateRange return error for %s: %v",
test.s, err)
@@ -58,32 +58,32 @@ func TestParseDateRange(t *testing.T) {
func TestParseRelativeDate(t *testing.T) {
tests := []struct {
s string
- want lib.RelDate
+ want parse.RelDate
}{
{
s: "5 weeks 1 day",
- want: lib.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
+ want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5_weeks 1_day",
- want: lib.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
+ want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5weeks1day",
- want: lib.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
+ want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5w1d",
- want: lib.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
+ want: parse.RelDate{Year: 0, Month: 0, Day: 5*7 + 1},
},
{
s: "5y4m3w1d",
- want: lib.RelDate{Year: 5, Month: 4, Day: 3*7 + 1},
+ want: parse.RelDate{Year: 5, Month: 4, Day: 3*7 + 1},
},
}
for _, test := range tests {
- da, err := lib.ParseRelativeDate(test.s)
+ da, err := parse.RelativeDate(test.s)
if err != nil {
t.Errorf("ParseRelativeDate return error for %s: %v",
test.s, err)
diff --git a/worker/lib/parse.go b/lib/rfc822/message.go
index 8e20e904..979d4595 100644
--- a/worker/lib/parse.go
+++ b/lib/rfc822/message.go
@@ -1,4 +1,4 @@
-package lib
+package rfc822
import (
"bufio"
@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
- "os"
"regexp"
"strings"
"time"
@@ -310,28 +309,6 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) {
}, nil
}
-// LimitHeaders returns a new Header with the specified headers included or
-// excluded
-func LimitHeaders(hdr *mail.Header, fields []string, exclude bool) *mail.Header {
- fieldMap := make(map[string]struct{}, len(fields))
- for _, f := range fields {
- fieldMap[strings.ToLower(f)] = struct{}{}
- }
- nh := &mail.Header{}
- curFields := hdr.Fields()
- for curFields.Next() {
- key := strings.ToLower(curFields.Key())
- _, present := fieldMap[key]
- // XOR exclude and present. When they are equal, it means we
- // should not add the header to the new header struct
- if exclude == present {
- continue
- }
- nh.Add(key, curFields.Value())
- }
- return nh
-}
-
// MessageHeaders populates a models.MessageInfo struct for the message.
// based on the reader returned by NewReader. Minimal information is included.
// There is no body structure or RFC822Headers set
@@ -404,12 +381,3 @@ func ReadMessage(r io.Reader) (*message.Entity, error) {
}
return entity, nil
}
-
-// FileSize returns the size of the file specified by name
-func FileSize(name string) (uint32, error) {
- fileInfo, err := os.Stat(name)
- if err != nil {
- return 0, fmt.Errorf("failed to obtain fileinfo: %w", err)
- }
- return uint32(fileInfo.Size()), nil
-}
diff --git a/worker/lib/parse_test.go b/lib/rfc822/message_test.go
index 4bf95431..8730afe2 100644
--- a/worker/lib/parse_test.go
+++ b/lib/rfc822/message_test.go
@@ -1,4 +1,4 @@
-package lib
+package rfc822_test
import (
"io"
@@ -6,6 +6,7 @@ import (
"path/filepath"
"testing"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/models"
)
@@ -22,7 +23,7 @@ func TestMessageInfoParser(t *testing.T) {
p := fi.Name()
t.Run(p, func(t *testing.T) {
m := newMockRawMessageFromPath(filepath.Join(rootDir, p))
- mi, err := MessageInfo(m)
+ mi, err := rfc822.MessageInfo(m)
if err != nil {
t.Fatal("Failed to create MessageInfo with:", err)
}
@@ -47,7 +48,7 @@ func TestMessageInfoHandledError(t *testing.T) {
p := fi.Name()
t.Run(p, func(t *testing.T) {
m := newMockRawMessageFromPath(filepath.Join(rootDir, p))
- mi, err := MessageInfo(m)
+ mi, err := rfc822.MessageInfo(m)
if err != nil {
t.Fatal(err)
}
diff --git a/worker/lib/testdata/message/invalid/hexa b/lib/rfc822/testdata/message/invalid/hexa
index 56b352ff..56b352ff 100644
--- a/worker/lib/testdata/message/invalid/hexa
+++ b/lib/rfc822/testdata/message/invalid/hexa
diff --git a/worker/lib/testdata/message/valid/quoted-mime-type b/lib/rfc822/testdata/message/valid/quoted-mime-type
index d9af28a2..d9af28a2 100644
--- a/worker/lib/testdata/message/valid/quoted-mime-type
+++ b/lib/rfc822/testdata/message/valid/quoted-mime-type
diff --git a/worker/imap/search.go b/worker/imap/search.go
index 77a18990..e9238190 100644
--- a/worker/imap/search.go
+++ b/worker/imap/search.go
@@ -6,8 +6,8 @@ import (
"github.com/emersion/go-imap"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
"git.sr.ht/~rjarry/aerc/log"
- "git.sr.ht/~rjarry/aerc/worker/lib"
"git.sr.ht/~sircmpwn/getopt"
)
@@ -56,7 +56,7 @@ func parseSearch(args []string) (*imap.SearchCriteria, error) {
case 'a':
text = true
case 'd':
- start, end, err := lib.ParseDateRange(opt.Value)
+ start, end, err := parse.DateRange(opt.Value)
if err != nil {
log.Errorf("failed to parse start date: %v", err)
continue
diff --git a/worker/jmap/search.go b/worker/jmap/search.go
index a751b700..17b5ca11 100644
--- a/worker/jmap/search.go
+++ b/worker/jmap/search.go
@@ -3,8 +3,8 @@ package jmap
import (
"strings"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
"git.sr.ht/~rjarry/aerc/log"
- "git.sr.ht/~rjarry/aerc/worker/lib"
"git.sr.ht/~rockorager/go-jmap/mail/email"
"git.sr.ht/~sircmpwn/getopt"
)
@@ -38,7 +38,7 @@ func parseSearch(args []string) (*email.FilterCondition, error) {
case 'a':
text = true
case 'd':
- start, end, err := lib.ParseDateRange(opt.Value)
+ start, end, err := parse.DateRange(opt.Value)
if err != nil {
log.Errorf("failed to parse start date: %v", err)
continue
diff --git a/worker/lib/headers.go b/worker/lib/headers.go
new file mode 100644
index 00000000..391d1d2a
--- /dev/null
+++ b/worker/lib/headers.go
@@ -0,0 +1,29 @@
+package lib
+
+import (
+ "strings"
+
+ "github.com/emersion/go-message/mail"
+)
+
+// LimitHeaders returns a new Header with the specified headers included or
+// excluded
+func LimitHeaders(hdr *mail.Header, fields []string, exclude bool) *mail.Header {
+ fieldMap := make(map[string]struct{}, len(fields))
+ for _, f := range fields {
+ fieldMap[strings.ToLower(f)] = struct{}{}
+ }
+ nh := &mail.Header{}
+ curFields := hdr.Fields()
+ for curFields.Next() {
+ key := strings.ToLower(curFields.Key())
+ _, present := fieldMap[key]
+ // XOR exclude and present. When they are equal, it means we
+ // should not add the header to the new header struct
+ if exclude == present {
+ continue
+ }
+ nh.Add(key, curFields.Value())
+ }
+ return nh
+}
diff --git a/worker/lib/search.go b/worker/lib/search.go
index 11fc1b11..cd372aae 100644
--- a/worker/lib/search.go
+++ b/worker/lib/search.go
@@ -9,6 +9,8 @@ import (
"git.sr.ht/~sircmpwn/getopt"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
)
@@ -60,7 +62,7 @@ func GetSearchCriteria(args []string) (*searchCriteria, error) {
case 'b':
body = true
case 'd':
- start, end, err := ParseDateRange(opt.Value)
+ start, end, err := parse.DateRange(opt.Value)
if err != nil {
log.Errorf("failed to parse start date: %v", err)
continue
@@ -99,7 +101,7 @@ func getParsedFlag(name string) models.Flags {
return f
}
-func Search(messages []RawMessage, criteria *searchCriteria) ([]uint32, error) {
+func Search(messages []rfc822.RawMessage, criteria *searchCriteria) ([]uint32, error) {
requiredParts := getRequiredParts(criteria)
matchedUids := []uint32{}
@@ -117,7 +119,7 @@ func Search(messages []RawMessage, criteria *searchCriteria) ([]uint32, error) {
// searchMessage executes the search criteria for the given RawMessage,
// returns true if search succeeded
-func searchMessage(message RawMessage, criteria *searchCriteria,
+func searchMessage(message rfc822.RawMessage, criteria *searchCriteria,
parts MsgParts,
) (bool, error) {
// setup parts of the message to use in the search
@@ -137,7 +139,7 @@ func searchMessage(message RawMessage, criteria *searchCriteria,
}
}
if parts&HEADER > 0 || parts&DATE > 0 {
- header, err = MessageInfo(message)
+ header, err = rfc822.MessageInfo(message)
if err != nil {
return false, err
}
diff --git a/worker/lib/size.go b/worker/lib/size.go
new file mode 100644
index 00000000..f00437c3
--- /dev/null
+++ b/worker/lib/size.go
@@ -0,0 +1,15 @@
+package lib
+
+import (
+ "fmt"
+ "os"
+)
+
+// FileSize returns the size of the file specified by name
+func FileSize(name string) (uint32, error) {
+ fileInfo, err := os.Stat(name)
+ if err != nil {
+ return 0, fmt.Errorf("failed to obtain fileinfo: %w", err)
+ }
+ return uint32(fileInfo.Size()), nil
+}
diff --git a/worker/maildir/message.go b/worker/maildir/message.go
index 778673a2..1f89cfe3 100644
--- a/worker/maildir/message.go
+++ b/worker/maildir/message.go
@@ -6,6 +6,7 @@ import (
"github.com/emersion/go-maildir"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/lib"
@@ -74,7 +75,7 @@ func (m Message) Remove() error {
// MessageInfo populates a models.MessageInfo struct for the message.
func (m Message) MessageInfo() (*models.MessageInfo, error) {
- info, err := lib.MessageInfo(m)
+ info, err := rfc822.MessageInfo(m)
if err != nil {
return nil, err
}
@@ -101,7 +102,7 @@ func (m Message) Size() (uint32, error) {
// MessageHeaders populates a models.MessageInfo struct for the message with
// minimal information, used for sorting and threading.
func (m Message) MessageHeaders() (*models.MessageInfo, error) {
- info, err := lib.MessageHeaders(m)
+ info, err := rfc822.MessageHeaders(m)
if err != nil {
return nil, err
}
@@ -121,11 +122,11 @@ func (m Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) {
return nil, err
}
defer f.Close()
- msg, err := lib.ReadMessage(f)
+ msg, err := rfc822.ReadMessage(f)
if err != nil {
return nil, fmt.Errorf("could not read message: %w", err)
}
- return lib.FetchEntityPartReader(msg, requestedParts)
+ return rfc822.FetchEntityPartReader(msg, requestedParts)
}
func (m Message) UID() uint32 {
diff --git a/worker/maildir/search.go b/worker/maildir/search.go
index 8286de67..c1ea4de2 100644
--- a/worker/maildir/search.go
+++ b/worker/maildir/search.go
@@ -15,9 +15,9 @@ import (
"git.sr.ht/~sircmpwn/getopt"
"git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
- wlib "git.sr.ht/~rjarry/aerc/worker/lib"
)
type searchCriteria struct {
@@ -69,7 +69,7 @@ func parseSearch(args []string) (*searchCriteria, error) {
case 'a':
text = true
case 'd':
- start, end, err := wlib.ParseDateRange(opt.Value)
+ start, end, err := parse.DateRange(opt.Value)
if err != nil {
log.Errorf("failed to parse start date: %v", err)
continue
diff --git a/worker/mbox/io.go b/worker/mbox/io.go
index 2fe39813..f5fbc596 100644
--- a/worker/mbox/io.go
+++ b/worker/mbox/io.go
@@ -5,15 +5,15 @@ import (
"io"
"time"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/models"
- "git.sr.ht/~rjarry/aerc/worker/lib"
"github.com/emersion/go-mbox"
)
-func Read(r io.Reader) ([]lib.RawMessage, error) {
+func Read(r io.Reader) ([]rfc822.RawMessage, error) {
mbr := mbox.NewReader(r)
uid := uint32(0)
- messages := make([]lib.RawMessage, 0)
+ messages := make([]rfc822.RawMessage, 0)
for {
msg, err := mbr.NextMessage()
if errors.Is(err, io.EOF) {
diff --git a/worker/mbox/models.go b/worker/mbox/models.go
index 491128c5..5acd6f5a 100644
--- a/worker/mbox/models.go
+++ b/worker/mbox/models.go
@@ -5,8 +5,8 @@ import (
"fmt"
"io"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/models"
- "git.sr.ht/~rjarry/aerc/worker/lib"
)
type mailboxContainer struct {
@@ -91,7 +91,7 @@ func (md *mailboxContainer) Copy(dest, src string, uids []uint32) error {
type container struct {
filename string
- messages []lib.RawMessage
+ messages []rfc822.RawMessage
}
func (f *container) Uids() []uint32 {
@@ -102,7 +102,7 @@ func (f *container) Uids() []uint32 {
return uids
}
-func (f *container) Message(uid uint32) (lib.RawMessage, error) {
+func (f *container) Message(uid uint32) (rfc822.RawMessage, error) {
for _, m := range f.messages {
if uid == m.UID() {
return m, nil
@@ -112,7 +112,7 @@ func (f *container) Message(uid uint32) (lib.RawMessage, error) {
}
func (f *container) Delete(uids []uint32) (deleted []uint32) {
- newMessages := make([]lib.RawMessage, 0)
+ newMessages := make([]rfc822.RawMessage, 0)
for _, m := range f.messages {
del := false
for _, uid := range uids {
diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go
index ab853b1c..160dfa55 100644
--- a/worker/mbox/worker.go
+++ b/worker/mbox/worker.go
@@ -10,6 +10,7 @@ import (
"path/filepath"
"sort"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/handlers"
@@ -201,13 +202,13 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
break
}
- fullMsg, err := lib.ReadMessage(contentReader)
+ fullMsg, err := rfc822.ReadMessage(contentReader)
if err != nil {
reterr = fmt.Errorf("could not read message: %w", err)
break
}
- r, err := lib.FetchEntityPartReader(fullMsg, msg.Part)
+ r, err := rfc822.FetchEntityPartReader(fullMsg, msg.Part)
if err != nil {
w.worker.Errorf(
"could not get body part reader for message=%d, parts=%#v: %w",
@@ -282,7 +283,7 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
msg.Flags, msg.Enable, err)
continue
}
- info, err := lib.MessageInfo(m)
+ info, err := rfc822.MessageInfo(m)
if err != nil {
w.worker.Errorf("could not get message info: %v", err)
continue
@@ -410,7 +411,7 @@ func filterUids(folder *container, uids []uint32, args []string) ([]uint32, erro
return nil, err
}
log.Debugf("Search with parsed criteria: %#v", criteria)
- m := make([]lib.RawMessage, 0, len(uids))
+ m := make([]rfc822.RawMessage, 0, len(uids))
for _, uid := range uids {
msg, err := folder.Message(uid)
if err != nil {
@@ -448,8 +449,8 @@ func sortUids(folder *container, uids []uint32,
return lib.Sort(infos, criteria)
}
-func messageInfo(m lib.RawMessage, needSize bool) (*models.MessageInfo, error) {
- info, err := lib.MessageInfo(m)
+func messageInfo(m rfc822.RawMessage, needSize bool) (*models.MessageInfo, error) {
+ info, err := rfc822.MessageInfo(m)
if err != nil {
return nil, err
}
diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go
index f78adeff..19011679 100644
--- a/worker/notmuch/message.go
+++ b/worker/notmuch/message.go
@@ -12,6 +12,7 @@ import (
"github.com/emersion/go-maildir"
+ "git.sr.ht/~rjarry/aerc/lib/rfc822"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/lib"
@@ -35,7 +36,7 @@ func (m *Message) NewReader() (io.ReadCloser, error) {
// MessageInfo populates a models.MessageInfo struct for the message.
func (m *Message) MessageInfo() (*models.MessageInfo, error) {
- info, err := lib.MessageInfo(m)
+ info, err := rfc822.MessageInfo(m)
if err != nil {
return nil, err
}
@@ -62,11 +63,11 @@ func (m *Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) {
return nil, err
}
defer f.Close()
- msg, err := lib.ReadMessage(f)
+ msg, err := rfc822.ReadMessage(f)
if err != nil {
return nil, fmt.Errorf("could not read message: %w", err)
}
- return lib.FetchEntityPartReader(msg, requestedParts)
+ return rfc822.FetchEntityPartReader(msg, requestedParts)
}
// SetFlag adds or removes a flag from the message.