fix handling of reputation for messages that were moved out of the rejects mailbox

the idea of the rejects mailbox is to show messages that were rejected.  you can
look there, and if you see a message that should have been delivered, you can
move it to your inbox or archive.  next time a deliver attempt by that user is
attempted, they should be accepted, because you corrected the reject.  but that
wasn't happening, because the reputation-calculation is per-delivery mailbox
(e.g. Inbox) and we look at MailboxOrigID when calculating the reputation. and
that was set to the Rejects mailbox id, so the message wasn't considered. the
same applies to moving messages from Rejects to Junk (to train your filter).

we now keep track of a MailboxDestinedID, that is set to the mailbox that we
would have delivered to if we would not have rejected the message. then, when a
message is moved out of the Rejects mailbox, we change MailboxOrigID to
MailboxDestinedID. this essentially makes the message look like it was
delivered normally.
This commit is contained in:
Mechiel Lukkien
2023-03-03 13:19:27 +01:00
parent 30c79faff2
commit 73bfc58453
3 changed files with 43 additions and 9 deletions

View File

@ -2967,7 +2967,11 @@ func (c *conn) cmdxCopy(isUID bool, tag, cmd string, p *parser) {
m.ID = 0
m.UID = uidFirst + store.UID(i)
m.MailboxID = mbDst.ID
m.MailboxOrigID = mbSrc.ID
if mbSrc.Name == conf.RejectsMailbox && m.MailboxDestinedID != 0 {
// Incorrectly delivered to Rejects mailbox. Adjust MailboxOrigID so this message
// is used for reputation calculation during future deliveries.
m.MailboxOrigID = m.MailboxDestinedID
}
m.TrainedJunk = nil
m.JunkFlagsForMailbox(mbDst.Name, conf)
err := tx.Insert(&m)
@ -3092,7 +3096,7 @@ func (c *conn) cmdxMove(isUID bool, tag, cmd string, p *parser) {
c.account.WithWLock(func() {
c.xdbwrite(func(tx *bstore.Tx) {
c.xmailboxID(tx, c.mailboxID) // Validate.
mbSrc := c.xmailboxID(tx, c.mailboxID) // Validate.
mbDst = c.xmailbox(tx, name, "TRYCREATE")
if mbDst.ID == c.mailboxID {
xuserErrorf("cannot move to currently selected mailbox")
@ -3128,6 +3132,11 @@ func (c *conn) cmdxMove(isUID bool, tag, cmd string, p *parser) {
xserverErrorf("internal error: got uid %d, expected %d, for index %d", m.UID, uids[i], i)
}
m.MailboxID = mbDst.ID
if mbSrc.Name == conf.RejectsMailbox && m.MailboxDestinedID != 0 {
// Incorrectly delivered to Rejects mailbox. Adjust MailboxOrigID so this message
// is used for reputation calculation during future deliveries.
m.MailboxOrigID = m.MailboxDestinedID
}
m.UID = uidnext
m.JunkFlagsForMailbox(mbDst.Name, conf)
uidnext++