Importing to sent and inbox

This commit is contained in:
Michal Horejsek
2021-01-08 13:00:26 +01:00
parent 0cde1ab801
commit 76dda10572
14 changed files with 218 additions and 41 deletions

View File

@ -133,9 +133,6 @@ func (im *imapMailbox) CreateMessage(flags []string, date time.Time, body imap.L
// We didn't find the message in the store, so we are currently sending it.
logEntry.WithField("time", date).Info("No matching UID, continuing APPEND to Sent")
}
// This is an APPEND to the Sent folder, so we will set the sent flag
m.Flags |= pmapi.FlagSent
}
message.ParseFlags(m, flags)

View File

@ -22,6 +22,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net/mail"
"sync"
pkgMsg "github.com/ProtonMail/proton-bridge/pkg/message"
@ -238,7 +239,7 @@ func (p *PMAPIProvider) generateImportMsgReq(rules transferRules, progress *Prog
Body: body,
Unread: unread,
Time: message.Time,
Flags: computeMessageFlags(labelIDs),
Flags: computeMessageFlags(message.Header),
LabelIDs: labelIDs,
}, nil
}
@ -257,24 +258,11 @@ func (p *PMAPIProvider) encryptMessage(msg *pmapi.Message, attachmentReaders []i
return pkgMsg.BuildEncrypted(msg, attachmentReaders, p.keyRing)
}
func computeMessageFlags(labels []string) (flag int64) {
for _, labelID := range labels {
switch labelID {
case pmapi.SentLabel:
flag = (flag | pmapi.FlagSent)
case pmapi.ArchiveLabel, pmapi.InboxLabel:
flag = (flag | pmapi.FlagReceived)
case pmapi.DraftLabel:
log.Error("Found draft target in non-draft import")
}
func computeMessageFlags(header mail.Header) (flag int64) {
if header.Get("received") == "" {
return pmapi.FlagSent
}
// NOTE: if the labels are custom only
if flag == 0 {
flag = pmapi.FlagReceived
}
return flag
return pmapi.FlagReceived
}
func (p *PMAPIProvider) startImportWorkers(progress *Progress, preparedImportRequestsCh chan map[string]*pmapi.ImportMsgReq) *sync.WaitGroup {