-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement storing non-system/well-known flags (keywords) for messages…
… and mailboxes, with imap the mailbox select/examine responses now return all flags used in a mailbox in the FLAGS response. and indicate in the PERMANENTFLAGS response that clients can set new keywords. we store these values on the new Message.Keywords field. system/well-known flags are still in Message.Flags, so we're recognizing those and handling them separately. the imap store command handles the new flags. as does the append command, and the search command. we store keywords in a mailbox when a message in that mailbox gets the keyword. we don't automatically remove the keywords from a mailbox. there is currently no way at all to remove a keyword from a mailbox. the import commands now handle non-system/well-known keywords too, when importing from mbox/maildir. jmap requires keyword support, so best to get it out of the way now.
- Loading branch information
Showing
30 changed files
with
1,926 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,19 @@ import ( | |
"os" | ||
"path" | ||
"path/filepath" | ||
"sort" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/mjl-/bstore" | ||
|
||
"github.com/mjl-/mox/mlog" | ||
"github.com/mjl-/mox/mox-" | ||
"github.com/mjl-/mox/store" | ||
) | ||
|
||
var ctxbg = context.Background() | ||
|
||
func tcheck(t *testing.T, err error, msg string) { | ||
t.Helper() | ||
if err != nil { | ||
|
@@ -50,7 +55,7 @@ func TestAccount(t *testing.T) { | |
if authHdr != "" { | ||
r.Header.Add("Authorization", authHdr) | ||
} | ||
ok := checkAccountAuth(context.Background(), log, w, r) | ||
ok := checkAccountAuth(ctxbg, log, w, r) | ||
if ok != expect { | ||
t.Fatalf("got %v, expected %v", ok, expect) | ||
} | ||
|
@@ -59,7 +64,7 @@ func TestAccount(t *testing.T) { | |
const authOK = "Basic bWpsQG1veC5leGFtcGxlOnRlc3QxMjM0" // [email protected]:test1234 | ||
const authBad = "Basic bWpsQG1veC5leGFtcGxlOmJhZHBhc3N3b3Jk" // [email protected]:badpassword | ||
|
||
authCtx := context.WithValue(context.Background(), authCtxKey, "mjl") | ||
authCtx := context.WithValue(ctxbg, authCtxKey, "mjl") | ||
|
||
test(authOK, "") // No password set yet. | ||
Account{}.SetPassword(authCtx, "test1234") | ||
|
@@ -132,6 +137,39 @@ func TestAccount(t *testing.T) { | |
testImport("../testdata/importtest.mbox.zip", 2) | ||
testImport("../testdata/importtest.maildir.tgz", 2) | ||
|
||
// Check there are messages, with the right flags. | ||
acc.DB.Read(ctxbg, func(tx *bstore.Tx) error { | ||
_, err = bstore.QueryTx[store.Message](tx).FilterIn("Keywords", "other").FilterIn("Keywords", "test").Get() | ||
tcheck(t, err, `fetching message with keywords "other" and "test"`) | ||
|
||
mb, err := acc.MailboxFind(tx, "importtest") | ||
tcheck(t, err, "looking up mailbox importtest") | ||
if mb == nil { | ||
t.Fatalf("missing mailbox importtest") | ||
} | ||
sort.Strings(mb.Keywords) | ||
if strings.Join(mb.Keywords, " ") != "other test" { | ||
t.Fatalf(`expected mailbox keywords "other" and "test", got %v`, mb.Keywords) | ||
} | ||
|
||
n, err := bstore.QueryTx[store.Message](tx).FilterIn("Keywords", "custom").Count() | ||
tcheck(t, err, `fetching message with keyword "custom"`) | ||
if n != 2 { | ||
t.Fatalf(`got %d messages with keyword "custom", expected 2`, n) | ||
} | ||
|
||
mb, err = acc.MailboxFind(tx, "maildir") | ||
tcheck(t, err, "looking up mailbox maildir") | ||
if mb == nil { | ||
t.Fatalf("missing mailbox maildir") | ||
} | ||
if strings.Join(mb.Keywords, " ") != "custom" { | ||
t.Fatalf(`expected mailbox keywords "custom", got %v`, mb.Keywords) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
testExport := func(httppath string, iszip bool, expectFiles int) { | ||
t.Helper() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.