Append duplicate of emails with References

This commit is contained in:
Jakub
2020-10-14 09:48:51 +02:00
parent 12403785af
commit a21bb130e1
4 changed files with 17 additions and 15 deletions

View File

@ -8,6 +8,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
### Fixed ### Fixed
* GODT-798 Replace, don't add, transfer encoding when making body 7-bit clean. * GODT-798 Replace, don't add, transfer encoding when making body 7-bit clean.
* Move/Copy duplicate for emails with References in Outlook
## [Bridge 1.4.3] Forth ## [Bridge 1.4.3] Forth

View File

@ -24,7 +24,6 @@ import (
"mime/multipart" "mime/multipart"
"net/mail" "net/mail"
"net/textproto" "net/textproto"
"regexp"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -141,18 +140,19 @@ func (im *imapMailbox) CreateMessage(flags []string, date time.Time, body imap.L
references := m.Header.Get("References") references := m.Header.Get("References")
referenceList := strings.Fields(references) referenceList := strings.Fields(references)
if len(referenceList) > 0 { // In case there is a mail client which corrupts headers, try
// "References" too.
if internalID == "" && len(referenceList) > 0 {
lastReference := referenceList[len(referenceList)-1] lastReference := referenceList[len(referenceList)-1]
// In case we are using a mail client which corrupts headers, try "References" too. match := pmapi.RxInternalReferenceFormat.FindStringSubmatch(lastReference)
re := regexp.MustCompile(pmapi.InternalReferenceFormat) if len(match) == 2 {
match := re.FindStringSubmatch(lastReference) internalID = match[1]
if len(match) > 0 {
internalID = match[0]
} }
} }
// Avoid appending a message which is already on the server. Apply the new // Avoid appending a message which is already on the server. Apply the
// label instead. This sometimes happens which Outlook (it uses APPEND instead of COPY). // new label instead. This always happens with Outlook (it uses APPEND
// instead of COPY).
if internalID != "" { if internalID != "" {
// Check to see if this belongs to a different address in split mode or another ProtonMail account. // Check to see if this belongs to a different address in split mode or another ProtonMail account.
msg, err := im.storeMailbox.GetMessage(internalID) msg, err := im.storeMailbox.GetMessage(internalID)

View File

@ -25,7 +25,6 @@ import (
"io" "io"
"mime" "mime"
"net/mail" "net/mail"
"regexp"
"strings" "strings"
"time" "time"
@ -408,9 +407,9 @@ func (su *smtpUser) handleReferencesHeader(m *pmapi.Message) (draftID, parentID
if !strings.Contains(reference, "@"+pmapi.InternalIDDomain) { if !strings.Contains(reference, "@"+pmapi.InternalIDDomain) {
newReferences = append(newReferences, reference) newReferences = append(newReferences, reference)
} else { // internalid is the parentID. } else { // internalid is the parentID.
idMatch := regexp.MustCompile(pmapi.InternalReferenceFormat).FindStringSubmatch(reference) idMatch := pmapi.RxInternalReferenceFormat.FindStringSubmatch(reference)
if len(idMatch) > 0 { if len(idMatch) == 2 {
lastID := strings.TrimSuffix(strings.Trim(idMatch[0], "<>"), "@protonmail.internalid") lastID := idMatch[1]
filter := &pmapi.MessagesFilter{ID: []string{lastID}} filter := &pmapi.MessagesFilter{ID: []string{lastID}}
if su.addressID != "" { if su.addressID != "" {
filter.AddressID = su.addressID filter.AddressID = su.addressID

View File

@ -29,6 +29,7 @@ import (
"net/http" "net/http"
"net/mail" "net/mail"
"net/url" "net/url"
"regexp"
"strconv" "strconv"
"strings" "strings"
@ -149,8 +150,9 @@ const ConversationIDDomain = `protonmail.conversationid`
// InternalIDDomain is used as a placeholder for reference/message ID headers to improve compatibility with various clients. // InternalIDDomain is used as a placeholder for reference/message ID headers to improve compatibility with various clients.
const InternalIDDomain = `protonmail.internalid` const InternalIDDomain = `protonmail.internalid`
// InternalReferenceFormat describes format of the message ID (as regex) used for parsing reference headers. // RxInternalReferenceFormat is compiled regexp which describes the match for
const InternalReferenceFormat = `(?U)<.*@` + InternalIDDomain + `>` // a message ID used in reference headers.
var RxInternalReferenceFormat = regexp.MustCompile(`(?U)<(.+)@` + regexp.QuoteMeta(InternalIDDomain) + `>`) //nolint[gochecknoglobals]
// Message structure. // Message structure.
type Message struct { type Message struct {