aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2023-03-11 13:26:58 +0900
committerRobin Jarry <robin@jarry.cc>2023-03-26 21:02:18 +0200
commit94a763920f5ee8b54b8ba7f819be373d80a4805d (patch)
treeccff19f3bb7c35dc02af49f04fe6adfce251498f /worker
parentc09b17a930cc58c13dd5dd2ba8e7a261833eb05a (diff)
downloadaerc-94a763920f5ee8b54b8ba7f819be373d80a4805d.tar.gz
parse msg-id lists more liberally
Some user agents deliberately generate non-standard message identifier lists in In-Reply-To and References headers. Instead of failing silently, aerc now falls back to a desperate parser scavaging whatever looking like <id-left@id-right>. As the more liberal parser being substituted with, References header are now stored for IMAP not only when there's a parsing error. Fixes: 31d2f5be3cec ("message-info: add explicit References field") Signed-off-by: Nguyễn Gia Phong <mcsinyx@disroot.org> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/cache.go6
-rw-r--r--worker/imap/fetch.go6
-rw-r--r--worker/lib/parse.go17
3 files changed, 8 insertions, 21 deletions
diff --git a/worker/imap/cache.go b/worker/imap/cache.go
index 352ef313..c5d3dcc0 100644
--- a/worker/imap/cache.go
+++ b/worker/imap/cache.go
@@ -9,6 +9,7 @@ import (
"path"
"time"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -117,10 +118,7 @@ func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 {
Flags: models.SeenFlag, // Always return a SEEN flag
Uid: ch.Uid,
RFC822Headers: hdr,
- }
- refs, err := hdr.MsgIDList("references")
- if err != nil {
- mi.Refs = refs
+ Refs: parse.MsgIDList(hdr, "references"),
}
log.Tracef("located cached header %s.%s", uv, u)
w.worker.PostMessage(&types.MessageInfo{
diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go
index 62451308..a8245784 100644
--- a/worker/imap/fetch.go
+++ b/worker/imap/fetch.go
@@ -10,6 +10,7 @@ import (
"github.com/emersion/go-message/mail"
"github.com/emersion/go-message/textproto"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -64,12 +65,9 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders(
Flags: translateImapFlags(_msg.Flags),
InternalDate: _msg.InternalDate,
RFC822Headers: header,
+ Refs: parse.MsgIDList(header, "references"),
Uid: _msg.Uid,
}
- refs, err := header.MsgIDList("references")
- if err != nil {
- info.Refs = refs
- }
imapw.worker.PostMessage(&types.MessageInfo{
Message: types.RespondTo(msg),
Info: info,
diff --git a/worker/lib/parse.go b/worker/lib/parse.go
index c2923c86..3baaa459 100644
--- a/worker/lib/parse.go
+++ b/worker/lib/parse.go
@@ -10,6 +10,7 @@ import (
"strings"
"time"
+ "git.sr.ht/~rjarry/aerc/lib/parse"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"github.com/emersion/go-message"
@@ -165,14 +166,8 @@ func parseEnvelope(h *mail.Header) (*models.Envelope, error) {
}
}
var irt string
- irtList, err := h.MsgIDList("in-reply-to")
- if err != nil {
- // proper parsing failed, so fall back to whatever is there
- irt, err = h.Text("in-reply-to")
- if err != nil {
- return nil, err
- }
- } else if len(irtList) > 0 {
+ irtList := parse.MsgIDList(h, "in-reply-to")
+ if len(irtList) > 0 {
irt = irtList[0]
}
date, err := parseDate(h)
@@ -351,16 +346,12 @@ func MessageHeaders(raw RawMessage) (*models.MessageInfo, error) {
if err != nil {
return nil, err
}
- refs, err := h.MsgIDList("references")
- if err != nil {
- return nil, err
- }
return &models.MessageInfo{
Envelope: env,
Flags: flags,
Labels: labels,
InternalDate: recDate,
- Refs: refs,
+ Refs: parse.MsgIDList(h, "references"),
Size: 0,
Uid: raw.UID(),
Error: parseErr,