Pop-out messageID format into constants

This commit is contained in:
Pavel Škoda
2020-05-11 16:17:59 +02:00
committed by Pavel Škoda
parent 30425d5fcd
commit 70fca64a36
5 changed files with 21 additions and 12 deletions

View File

@ -148,10 +148,10 @@ func (im *imapMailbox) CreateMessage(flags []string, date time.Time, body imap.L
if len(referenceList) > 0 {
lastReference := referenceList[len(referenceList)-1]
// In case we are using a mail client which corrupts headers, try "References" too.
re := regexp.MustCompile(`(?U)<.*@protonmail.internalid>`)
match := re.FindString(lastReference)
if match != "" {
internalID = match[1 : len(match)-len("@protonmail.internalid>")]
re := regexp.MustCompile(pmapi.InternalReferenceFormat)
match := re.FindStringSubmatch(lastReference)
if len(match) > 0 {
internalID = match[1]
}
}

View File

@ -370,12 +370,12 @@ func (su *smtpUser) handleReferencesHeader(m *pmapi.Message) (draftID, parentID
references := m.Header.Get("References")
newReferences := []string{}
for _, reference := range strings.Fields(references) {
if !strings.Contains(reference, "@protonmail.internalid") {
if !strings.Contains(reference, "@"+pmapi.InternalIDDomain) {
newReferences = append(newReferences, reference)
} else { // internalid is the parentID.
idMatch := regexp.MustCompile(`(?U)<.*@protonmail.internalid>`).FindString(reference)
if idMatch != "" {
lastID := idMatch[1 : len(idMatch)-len("@protonmail.internalid>")]
idMatch := regexp.MustCompile(pmapi.InternalReferenceFormat).FindStringSubmatch(reference)
if len(idMatch) > 0 {
lastID := idMatch[1]
filter := &pmapi.MessagesFilter{ID: []string{lastID}}
if su.addressID != "" {
filter.AddressID = su.addressID