fix: better draft detection for parentID

This commit is contained in:
James Houlahan
2020-04-29 12:45:59 +02:00
parent 44233e5bd3
commit 23f492705b
3 changed files with 9 additions and 10 deletions

View File

@ -30,6 +30,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
### Fixed ### Fixed
* Use correct binary name when finding location of addcert.scpt * 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) ## [v1.2.6] Donghai - beta (2020-03-31)

View File

@ -382,7 +382,7 @@ func (su *smtpUser) handleReferencesHeader(m *pmapi.Message) (draftID, parentID
} }
metadata, _, _ := su.client.ListMessages(filter) metadata, _, _ := su.client.ListMessages(filter)
for _, m := range metadata { for _, m := range metadata {
if isDraft(m) { if m.IsDraft() {
draftID = m.ID draftID = m.ID
} else { } else {
parentID = m.ID parentID = m.ID
@ -411,15 +411,6 @@ func (su *smtpUser) handleReferencesHeader(m *pmapi.Message) (draftID, parentID
return 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) { func (su *smtpUser) handleSenderAndRecipients(m *pmapi.Message, addr *pmapi.Address, from string, to []string) (err error) {
from = pmapi.ConstructAddress(from, addr.Email) from = pmapi.ConstructAddress(from, addr.Email)

View File

@ -219,6 +219,13 @@ func (m *Message) UnmarshalJSON(b []byte) error {
return nil 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 { func (m *Message) IsBodyEncrypted() bool {
trimmedBody := strings.TrimSpace(m.Body) trimmedBody := strings.TrimSpace(m.Body)
return strings.HasPrefix(trimmedBody, MessageHeader) && return strings.HasPrefix(trimmedBody, MessageHeader) &&