diff --git a/Changelog.md b/Changelog.md index c7956b98..08c75e4c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -30,6 +30,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) ### Fixed * Use correct binary name when finding location of addcert.scpt +* Correctly detect if a message is a draft even if does not have DraftLabel ## [v1.2.6] Donghai - beta (2020-03-31) diff --git a/internal/smtp/user.go b/internal/smtp/user.go index aeae38c5..9507dcb3 100644 --- a/internal/smtp/user.go +++ b/internal/smtp/user.go @@ -382,7 +382,7 @@ func (su *smtpUser) handleReferencesHeader(m *pmapi.Message) (draftID, parentID } metadata, _, _ := su.client.ListMessages(filter) for _, m := range metadata { - if isDraft(m) { + if m.IsDraft() { draftID = m.ID } else { parentID = m.ID @@ -411,15 +411,6 @@ func (su *smtpUser) handleReferencesHeader(m *pmapi.Message) (draftID, parentID return draftID, parentID } -func isDraft(m *pmapi.Message) bool { - for _, labelID := range m.LabelIDs { - if labelID == pmapi.DraftLabel { - return true - } - } - return false -} - func (su *smtpUser) handleSenderAndRecipients(m *pmapi.Message, addr *pmapi.Address, from string, to []string) (err error) { from = pmapi.ConstructAddress(from, addr.Email) diff --git a/pkg/pmapi/messages.go b/pkg/pmapi/messages.go index ab0a8180..696fb443 100644 --- a/pkg/pmapi/messages.go +++ b/pkg/pmapi/messages.go @@ -219,6 +219,13 @@ func (m *Message) UnmarshalJSON(b []byte) error { return nil } +// IsDraft returns whether the message should be considered to be a draft. +// A draft is complicated. It might have pmapi.DraftLabel but it might not. +// The real API definition of IsDraft is that it is neither sent nor received -- we should use that here. +func (m *Message) IsDraft() bool { + return (m.Flags & (FlagReceived | FlagSent)) == 0 +} + func (m *Message) IsBodyEncrypted() bool { trimmedBody := strings.TrimSpace(m.Body) return strings.HasPrefix(trimmedBody, MessageHeader) &&