mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
when moving message to mailbox with special-use flag "Junk", mark the message as junk too, for retraining
i had been using the AutomaticJunkFlags option, so hadn't noticed the special use flag wasn't used.
This commit is contained in:
parent
79774c15ec
commit
2e16d8025d
5 changed files with 13 additions and 8 deletions
|
@ -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")
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue