mirror of
https://github.com/mjl-/mox.git
synced 2024-12-28 01:13:47 +03:00
bf04fb8a1a
before, we used heuristics to decide when to train/untrain a message as junk or nonjunk: the message had to be seen, be in certain mailboxes. then if a message was marked as junk, it was junk. and otherwise it was nonjunk. this wasn't good enough: you may want to keep some messages around as neither junk or nonjunk. and that wasn't possible. ideally, we would just look at the imap $Junk and $NotJunk flags. the problem is that mail clients don't set these flags, or don't make it easy. thunderbird can set the flags based on its own bayesian filter. it has a shortcut for marking Junk and moving it to the junk folder (good), but the counterpart of notjunk only marks a message as notjunk without showing in the UI that it was marked as notjunk. there is also no "move and mark as notjunk" mechanism. e.g. "archive" does not mark a message as notjunk. ios mail and mutt don't appear to have any way to see or change the $Junk and $NotJunk flags. what email clients do have is the ability to move messages to other mailboxes/folders. so mox now has a mechanism that allows you to configure mailboxes that automatically set $Junk or $NotJunk (or clear both) when a message is moved/copied/delivered to that folder. e.g. a mailbox called junk or spam or rejects marks its messags as junk. inbox, postmaster, dmarc, tlsrpt, neutral* mark their messages as neither junk or notjunk. other folders mark their messages as notjunk. e.g. list/*, archive. this functionality is optional, but enabled with the quickstart and for new accounts. also, mox now keeps track of the previous training of a message and will only untrain/train if needed. before, there probably have been duplicate or missing (un)trainings. this also includes a new subcommand "retrain" to recreate the junkfilter for an account. you should run it after updating to this version. and you should probably also modify your account config to include the AutomaticJunkFlags.
61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
package imapserver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mjl-/mox/imapclient"
|
|
)
|
|
|
|
func TestCopy(t *testing.T) {
|
|
defer mockUIDValidity()()
|
|
tc := start(t)
|
|
defer tc.close()
|
|
|
|
tc2 := startNoSwitchboard(t)
|
|
defer tc2.close()
|
|
|
|
tc.client.Login("mjl@mox.example", "testtest")
|
|
tc.client.Select("inbox")
|
|
|
|
tc2.client.Login("mjl@mox.example", "testtest")
|
|
tc2.client.Select("Trash")
|
|
|
|
tc.transactf("bad", "copy") // Missing params.
|
|
tc.transactf("bad", "copy 1") // Missing params.
|
|
tc.transactf("bad", "copy 1 inbox ") // Leftover.
|
|
|
|
// Seqs 1,2 and UIDs 3,4.
|
|
tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
|
|
tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
|
|
tc.client.StoreFlagsSet("1:2", true, `\Deleted`)
|
|
tc.client.Expunge()
|
|
tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
|
|
tc.client.Append("inbox", nil, nil, []byte(exampleMsg))
|
|
|
|
tc.transactf("no", "copy 1 nonexistent")
|
|
tc.xcode("TRYCREATE")
|
|
|
|
tc.transactf("no", "copy 1 inbox") // Cannot copy to same mailbox.
|
|
|
|
tc2.transactf("ok", "noop") // Drain.
|
|
|
|
tc.transactf("ok", "copy 1:* Trash")
|
|
ptr := func(v uint32) *uint32 { return &v }
|
|
tc.xcodeArg(imapclient.CodeCopyUID{DestUIDValidity: 1, From: []imapclient.NumRange{{First: 3, Last: ptr(4)}}, To: []imapclient.NumRange{{First: 1, Last: ptr(2)}}})
|
|
tc2.transactf("ok", "noop")
|
|
tc2.xuntagged(
|
|
imapclient.UntaggedExists(2),
|
|
imapclient.UntaggedFetch{Seq: 1, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(1), imapclient.FetchFlags(nil)}},
|
|
imapclient.UntaggedFetch{Seq: 2, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(2), imapclient.FetchFlags(nil)}},
|
|
)
|
|
|
|
tc.transactf("no", "uid copy 1,2 Trash") // No match.
|
|
tc.transactf("ok", "uid copy 4,3 Trash")
|
|
tc.xcodeArg(imapclient.CodeCopyUID{DestUIDValidity: 1, From: []imapclient.NumRange{{First: 3, Last: ptr(4)}}, To: []imapclient.NumRange{{First: 3, Last: ptr(4)}}})
|
|
tc2.transactf("ok", "noop")
|
|
tc2.xuntagged(
|
|
imapclient.UntaggedExists(4),
|
|
imapclient.UntaggedFetch{Seq: 3, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(3), imapclient.FetchFlags(nil)}},
|
|
imapclient.UntaggedFetch{Seq: 4, Attrs: []imapclient.FetchAttr{imapclient.FetchUID(4), imapclient.FetchFlags(nil)}},
|
|
)
|
|
}
|