diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-05-10 23:46:00 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-05-10 23:46:00 +0200 |
commit | 983e2becf835048d06e0d76b2c24b8db23d7a238 (patch) | |
tree | 84727c735f6af626277bb6750714be9888f2750c /internal | |
parent | c9a3ba964784512b739699254b79be7aa9acc994 (diff) | |
download | feed2imap-go-983e2becf835048d06e0d76b2c24b8db23d7a238.tar.gz feed2imap-go-983e2becf835048d06e0d76b2c24b8db23d7a238.tar.bz2 feed2imap-go-983e2becf835048d06e0d76b2c24b8db23d7a238.zip |
#47 Consume all messages and filter by UID
Original bug is probably caused by unilateral messages of the server, notifying the client about flag changes of other mails. Solution: Ignore those
Diffstat (limited to '')
-rw-r--r-- | internal/imap/connection.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/internal/imap/connection.go b/internal/imap/connection.go index 3d537ea..b93a61f 100644 --- a/internal/imap/connection.go +++ b/internal/imap/connection.go @@ -1,6 +1,7 @@ package imap import ( + "errors" "fmt" "strings" "time" @@ -165,25 +166,29 @@ func (conn *connection) fetchFlags(uid uint32) ([]string, error) { seqSet.AddNum(uid) messages := make(chan *imap.Message, 1) - done := make(chan error, 1) + done := make(chan error) go func() { done <- conn.c.UidFetch(seqSet, fetchItem, messages) }() - var msg *imap.Message + var flags []string for m := range messages { - if msg == nil { - msg = m - } else { - panic(fmt.Sprintf("Duplicate message for uid %d. Found: %s(%d) and %s(%d)", uid, msg.Envelope.MessageId, msg.SeqNum, m.Envelope.MessageId, m.SeqNum)) + // unilateral flags messages may be sent by the server, which then clutter our messages + // --> filter for our selected UID + if m.Uid == uid { + flags = m.Flags } } err := <-done + if err == nil && flags == nil { + err = errors.New("no flags returned") + } + if err != nil { - return nil, fmt.Errorf("fetching flags: %w", err) + return nil, fmt.Errorf("fetching flags for UID %d: %w", uid, err) } - return msg.Flags, nil + return flags, nil } func (conn *connection) replace(folder Folder, header, value, newContent string, force bool) error { |