mirror of
https://github.com/mjl-/mox.git
synced 2025-07-19 03:26:37 +03:00
imapclient: first step towards making package usable as imap client with other imap servers, and minor imapserver bug fix
The imapclient needs more changes, like more strict parsing, before it can be a generally usable IMAP client, these are a few steps towards that. - Fix a bug in the imapserver METADATA responses for TOOMANY and MAXSIZE. - Split low-level IMAP protocol handling (new Proto type) from the higher-level client command handling (existing Conn type). The idea is that some simple uses of IMAP can get by with just using these commands, while more intricate uses of IMAP (like a synchronizing client that needs to talk to all kinds of servers with different behaviours and implemented extensions) can write custom commands and read untagged responses or command completion results explicitly. The lower-level method names have clearer names now, like ReadResponse instead of Response. - Merge the untagged responses and (command completion) "Result" into a new type Response. Makes function signatures simpler. And make Response implement the error interface, and change command methods to return the Response as error if the result is NO or BAD. Simplifies error handling, and still provides the option to continue after a NO or BAD. - Add UIDSearch/MSNSearch commands, with a custom "search program", so mostly to indicate these commands exist. - More complete coverage of types for response codes, for easier handling. - Automatically handle any ENABLED or CAPABILITY untagged response or response code for IMAP command methods on type Conn. - Make difference between MSN vs UID versions of FETCH/STORE/SEARCH/COPY/MOVE/REPLACE commands more clear. The original MSN commands now have MSN prefixed to their name, so they are grouped together in the documentation. - Document which capabilities are needed for a command.
This commit is contained in:
@ -42,9 +42,9 @@ func testNotify(t *testing.T, uidonly bool) {
|
||||
tc.transactf("bad", "Notify Set Status (Selected (flagChange))") // flagChange must come with MessageNew and MessageExpunge.
|
||||
tc.transactf("bad", "Notify Set Status (Selected (mailboxName)) (Selected-Delayed (mailboxName))") // Duplicate selected.
|
||||
tc.transactf("no", "Notify Set Status (Selected (annotationChange))") // We don't implement annotation change.
|
||||
tc.xcode("BADEVENT")
|
||||
tc.xcode(imapclient.CodeBadEvent{"MessageNew", "MessageExpunge", "FlagChange", "MailboxName", "SubscriptionChange", "MailboxMetadataChange", "ServerMetadataChange"})
|
||||
tc.transactf("no", "Notify Set Status (Personal (unknownEvent))")
|
||||
tc.xcode("BADEVENT")
|
||||
tc.xcode(imapclient.CodeBadEvent{"MessageNew", "MessageExpunge", "FlagChange", "MailboxName", "SubscriptionChange", "MailboxMetadataChange", "ServerMetadataChange"})
|
||||
|
||||
tc2 := startNoSwitchboard(t, uidonly)
|
||||
defer tc2.closeNoWait()
|
||||
@ -76,7 +76,7 @@ func testNotify(t *testing.T, uidonly bool) {
|
||||
// Enable notify, will first result in a the pending changes, then status.
|
||||
tc.transactf("ok", "Notify Set Status (Selected (messageNew (Uid Modseq Bodystructure Preview) messageExpunge flagChange)) (personal (messageNew messageExpunge flagChange mailboxName subscriptionChange mailboxMetadataChange serverMetadataChange))")
|
||||
tc.xuntagged(
|
||||
imapclient.UntaggedResult{Status: imapclient.OK, RespText: imapclient.RespText{Code: "HIGHESTMODSEQ", CodeArg: imapclient.CodeHighestModSeq(modseq), More: "after condstore-enabling command"}},
|
||||
imapclient.UntaggedResult{Status: imapclient.OK, Code: imapclient.CodeHighestModSeq(modseq), Text: "after condstore-enabling command"},
|
||||
// note: no status for Inbox since it is selected.
|
||||
imapclient.UntaggedStatus{Mailbox: "Drafts", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusMessages: 0, imapclient.StatusUIDNext: 1, imapclient.StatusUIDValidity: 1, imapclient.StatusUnseen: 0, imapclient.StatusHighestModSeq: 2}},
|
||||
imapclient.UntaggedStatus{Mailbox: "Sent", Attrs: map[imapclient.StatusAttr]int64{imapclient.StatusMessages: 0, imapclient.StatusUIDNext: 1, imapclient.StatusUIDValidity: 1, imapclient.StatusUnseen: 0, imapclient.StatusHighestModSeq: 2}},
|
||||
@ -108,7 +108,12 @@ func testNotify(t *testing.T, uidonly bool) {
|
||||
Octets: 21,
|
||||
},
|
||||
Lines: 1,
|
||||
Ext: &imapclient.BodyExtension1Part{},
|
||||
Ext: &imapclient.BodyExtension1Part{
|
||||
Disposition: ptr((*string)(nil)),
|
||||
DispositionParams: ptr([][2]string(nil)),
|
||||
Language: ptr([]string(nil)),
|
||||
Location: ptr((*string)(nil)),
|
||||
},
|
||||
},
|
||||
imapclient.BodyTypeText{
|
||||
MediaType: "TEXT",
|
||||
@ -118,12 +123,21 @@ func testNotify(t *testing.T, uidonly bool) {
|
||||
Octets: 15,
|
||||
},
|
||||
Lines: 1,
|
||||
Ext: &imapclient.BodyExtension1Part{},
|
||||
Ext: &imapclient.BodyExtension1Part{
|
||||
Disposition: ptr((*string)(nil)),
|
||||
DispositionParams: ptr([][2]string(nil)),
|
||||
Language: ptr([]string(nil)),
|
||||
Location: ptr((*string)(nil)),
|
||||
},
|
||||
},
|
||||
},
|
||||
MediaSubtype: "ALTERNATIVE",
|
||||
Ext: &imapclient.BodyExtensionMpart{
|
||||
Params: [][2]string{{"BOUNDARY", "x"}},
|
||||
Params: [][2]string{{"BOUNDARY", "x"}},
|
||||
Disposition: ptr((*string)(nil)), // Present but nil.
|
||||
DispositionParams: ptr([][2]string(nil)),
|
||||
Language: ptr([]string(nil)),
|
||||
Location: ptr((*string)(nil)),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -413,12 +427,7 @@ func testNotify(t *testing.T, uidonly bool) {
|
||||
// modseq++
|
||||
tc.readuntagged(
|
||||
imapclient.UntaggedExists(3),
|
||||
imapclient.UntaggedResult{
|
||||
Status: "NO",
|
||||
RespText: imapclient.RespText{
|
||||
More: "generating notify fetch response: requested part does not exist",
|
||||
},
|
||||
},
|
||||
imapclient.UntaggedResult{Status: "NO", Text: "generating notify fetch response: requested part does not exist"},
|
||||
tc.untaggedFetchUID(3, 4),
|
||||
)
|
||||
|
||||
@ -457,15 +466,7 @@ func testNotifyOverflow(t *testing.T, uidonly bool) {
|
||||
tc2.client.Append("inbox", makeAppend(searchMsg))
|
||||
|
||||
tc.transactf("ok", "noop")
|
||||
tc.xuntagged(
|
||||
imapclient.UntaggedResult{
|
||||
Status: "OK",
|
||||
RespText: imapclient.RespText{
|
||||
Code: "NOTIFICATIONOVERFLOW",
|
||||
More: "out of sync after too many pending changes",
|
||||
},
|
||||
},
|
||||
)
|
||||
tc.xuntagged(imapclient.UntaggedResult{Status: "OK", Code: imapclient.CodeWord("NOTIFICATIONOVERFLOW"), Text: "out of sync after too many pending changes"})
|
||||
|
||||
// Won't be getting any more notifications until we enable them again with NOTIFY.
|
||||
tc2.client.Append("inbox", makeAppend(searchMsg))
|
||||
@ -500,15 +501,7 @@ func testNotifyOverflow(t *testing.T, uidonly bool) {
|
||||
tc2.client.UIDStoreFlagsAdd("1", true, `\Seen`)
|
||||
tc2.client.UIDStoreFlagsClear("1", true, `\Seen`)
|
||||
tc.transactf("ok", "noop")
|
||||
tc.xuntagged(
|
||||
imapclient.UntaggedResult{
|
||||
Status: "OK",
|
||||
RespText: imapclient.RespText{
|
||||
Code: "NOTIFICATIONOVERFLOW",
|
||||
More: "out of sync after too many pending changes for selected mailbox",
|
||||
},
|
||||
},
|
||||
)
|
||||
tc.xuntagged(imapclient.UntaggedResult{Status: "OK", Code: imapclient.CodeWord("NOTIFICATIONOVERFLOW"), Text: "out of sync after too many pending changes for selected mailbox"})
|
||||
|
||||
// Again, no new notifications until we select and enable again.
|
||||
tc2.client.UIDStoreFlagsAdd("1", true, `\Seen`)
|
||||
|
Reference in New Issue
Block a user