fastmail imap double message fix
This commit is contained in:
parent
2c76d36be1
commit
f8bb80a803
|
@ -210,7 +210,19 @@ func (im *IMAP) Messages(folder string) ([]*Message, error) {
|
|||
return []*Message{}, fmt.Errorf("%w: %v", ErrIMAPServerProblem, err)
|
||||
}
|
||||
|
||||
return messages, nil
|
||||
// for reasons yet unknown, with some imap providers (i.e. Fastmail) the code
|
||||
// above sometimes returns the same message twice, but with a different uid.
|
||||
dedupMessages := []*Message{}
|
||||
for _, m := range messages {
|
||||
for _, dm := range dedupMessages {
|
||||
if m.Equal(dm) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
dedupMessages = append(dedupMessages, m)
|
||||
}
|
||||
|
||||
return dedupMessages, nil
|
||||
}
|
||||
|
||||
func (im *IMAP) Add(folder, subject, body string) error {
|
||||
|
|
|
@ -23,6 +23,20 @@ func (m *Message) Valid() bool {
|
|||
return m.Uid != 0 && m.Subject != "" && m.Folder != ""
|
||||
}
|
||||
|
||||
func (m *Message) Equal(n *Message) bool {
|
||||
if m.Folder != n.Folder {
|
||||
return false
|
||||
}
|
||||
if m.Subject != n.Subject {
|
||||
return false
|
||||
}
|
||||
if m.Body != n.Body {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
type MStorer interface {
|
||||
Folders() ([]string, error)
|
||||
Messages(folder string) ([]*Message, error)
|
||||
|
|
Loading…
Reference in New Issue