diff --git a/imapserver/server.go b/imapserver/server.go index 539b254..6381a37 100644 --- a/imapserver/server.go +++ b/imapserver/server.go @@ -3227,7 +3227,7 @@ func (c *conn) cmdxCopy(isUID bool, tag, cmd string, p *parser) { m.IsReject = false } m.TrainedJunk = nil - m.JunkFlagsForMailbox(mbDst.Name, conf) + m.JunkFlagsForMailbox(mbDst, conf) err := tx.Insert(&m) xcheckf(err, "inserting message") msgs[uid] = m @@ -3397,7 +3397,7 @@ func (c *conn) cmdxMove(isUID bool, tag, cmd string, p *parser) { } m.UID = uidnext m.ModSeq = modseq - m.JunkFlagsForMailbox(mbDst.Name, conf) + m.JunkFlagsForMailbox(mbDst, conf) uidnext++ err := tx.Update(m) xcheckf(err, "updating moved message in database") diff --git a/import.go b/import.go index fb0b170..c25e806 100644 --- a/import.go +++ b/import.go @@ -352,7 +352,7 @@ func importctl(ctx context.Context, ctl *ctl, mbox bool) { // We set the flags that Deliver would set now and train ourselves. This prevents // Deliver from training, which would open the junk filter, change it, and write it // back to disk, for each message (slow). - m.JunkFlagsForMailbox(mb.Name, conf) + m.JunkFlagsForMailbox(mb, conf) if jf != nil && m.NeedsTraining() { if words, err := jf.ParseMessage(p); err != nil { ctl.log.Infox("parsing message for updating junk filter", err, mlog.Field("parse", ""), mlog.Field("path", origPath)) diff --git a/store/account.go b/store/account.go index e5eb8f8..36dc98f 100644 --- a/store/account.go +++ b/store/account.go @@ -611,12 +611,17 @@ func (m Message) NeedsTraining() bool { // used when delivering/moving/copying messages to a mailbox. Mail clients are not // very helpful with setting junk/notjunk flags. But clients can move/copy messages // to other mailboxes. So we set flags when clients move a message. -func (m *Message) JunkFlagsForMailbox(mailbox string, conf config.Account) { +func (m *Message) JunkFlagsForMailbox(mb Mailbox, conf config.Account) { + if mb.Junk { + m.Junk = true + m.Notjunk = false + } + if !conf.AutomaticJunkFlags.Enabled { return } - lmailbox := strings.ToLower(mailbox) + lmailbox := strings.ToLower(mb.Name) if conf.JunkMailbox != nil && conf.JunkMailbox.MatchString(lmailbox) { m.Junk = true @@ -1220,7 +1225,7 @@ func (a *Account) DeliverMessage(log *mlog.Log, tx *bstore.Tx, m *Message, msgFi } conf, _ := a.Conf() - m.JunkFlagsForMailbox(mb.Name, conf) + m.JunkFlagsForMailbox(mb, conf) mr := FileMsgReader(m.MsgPrefix, msgFile) // We don't close, it would close the msgFile. var part *message.Part diff --git a/webaccount/import.go b/webaccount/import.go index c848273..cd00140 100644 --- a/webaccount/import.go +++ b/webaccount/import.go @@ -537,7 +537,7 @@ func importMessages(ctx context.Context, log *mlog.Log, token string, acc *store // We set the flags that Deliver would set now and train ourselves. This prevents // Deliver from training, which would open the junk filter, change it, and write it // back to disk, for each message (slow). - m.JunkFlagsForMailbox(mb.Name, conf) + m.JunkFlagsForMailbox(mb, conf) if jf != nil && m.NeedsTraining() { trainMessage(m, p, pos) } diff --git a/webmail/api.go b/webmail/api.go index f7ad092..a0e4c84 100644 --- a/webmail/api.go +++ b/webmail/api.go @@ -848,7 +848,7 @@ func (Webmail) MessageMove(ctx context.Context, messageIDs []int64, mailboxID in m.UID = mbDst.UIDNext m.ModSeq = modseq mbDst.UIDNext++ - m.JunkFlagsForMailbox(mbDst.Name, conf) + m.JunkFlagsForMailbox(mbDst, conf) err = tx.Update(&m) xcheckf(ctx, err, "updating moved message in database")