10 "github.com/mjl-/mox/imapclient"
13var searchMsg = strings.ReplaceAll(`Date: Mon, 1 Jan 2022 10:00:00 +0100 (CEST)
14From: mjl <mjl@mox.example>
16To: mox <mox@mox.example>
19Reply-To: <noreply@mox.example>
20Message-Id: <123@mox.example>
22Content-Type: multipart/alternative; boundary=x
25Content-Type: text/plain; charset=utf-8
30Content-Type: text/html; charset=utf-8
37func uint32ptr(v uint32) *uint32 {
41func (tc *testconn) xsearch(nums ...uint32) {
44 tc.xuntagged(imapclient.UntaggedSearch(nums))
47func (tc *testconn) xsearchmodseq(modseq int64, nums ...uint32) {
54 tc.xuntagged(imapclient.UntaggedSearchModSeq{Nums: nums, ModSeq: modseq})
57func (tc *testconn) xesearch(exp imapclient.UntaggedEsearch) {
60 exp.Tag = tc.client.LastTag()
64func TestSearch(t *testing.T) {
68func TestSearchUIDOnly(t *testing.T) {
72func testSearch(t *testing.T, uidonly bool) {
73 tc := start(t, uidonly)
75 tc.login("mjl@mox.example", password0)
76 tc.client.Select("inbox")
78 // Add 5 and delete first 4 messages. So UIDs start at 5.
79 received := time.Date(2020, time.January, 1, 10, 0, 0, 0, time.UTC)
80 saveDate := time.Now()
82 tc.client.Append("inbox", makeAppendTime(exampleMsg, received))
84 tc.client.UIDStoreFlagsSet("1:4", true, `\Deleted`)
87 received = time.Date(2022, time.January, 1, 9, 0, 0, 0, time.UTC)
88 tc.client.Append("inbox", makeAppendTime(searchMsg, received))
90 received = time.Date(2022, time.January, 1, 9, 0, 0, 0, time.UTC)
91 mostFlags := []string{
105 tc.client.Append("inbox", imapclient.Append{Flags: mostFlags, Received: &received, Size: int64(len(searchMsg)), Data: strings.NewReader(searchMsg)})
107 // We now have sequence numbers 1,2,3 and UIDs 5,6,7.
110 // We need to be selected. Not the case for ESEARCH command.
112 tc.transactf("no", "uid search all")
113 tc.client.Select("inbox")
115 // We need to be selected. Not the case for ESEARCH command.
117 tc.transactf("no", "search all")
118 tc.client.Select("inbox")
120 tc.transactf("ok", "search all")
124 tc.transactf("ok", "uid search all")
127 esearchall := func(ss string) imapclient.UntaggedEsearch {
128 return imapclient.UntaggedEsearch{All: esearchall0(ss)}
132 tc.transactf("ok", "search answered")
135 tc.transactf("ok", `search bcc "bcc@mox.example"`)
138 tc.transactf("ok", "search before 1-Jan-2038")
140 tc.transactf("ok", "search before 1-Jan-2020")
141 tc.xsearch() // Before is about received, not date header of message.
143 // WITHIN extension with OLDER & YOUNGER.
144 tc.transactf("ok", "search older 60")
146 tc.transactf("ok", "search younger 60")
149 // SAVEDATE extension.
150 tc.transactf("ok", "search savedbefore %s", saveDate.Add(24*time.Hour).Format("2-Jan-2006"))
152 tc.transactf("ok", "search savedbefore %s", saveDate.Add(-24*time.Hour).Format("2-Jan-2006"))
154 tc.transactf("ok", "search savedon %s", saveDate.Format("2-Jan-2006"))
156 tc.transactf("ok", "search savedon %s", saveDate.Add(-24*time.Hour).Format("2-Jan-2006"))
158 tc.transactf("ok", "search savedsince %s", saveDate.Add(-24*time.Hour).Format("2-Jan-2006"))
160 tc.transactf("ok", "search savedsince %s", saveDate.Add(24*time.Hour).Format("2-Jan-2006"))
163 tc.transactf("ok", `search body "Joe"`)
165 tc.transactf("ok", `search body "Joe" body "bogus"`)
167 tc.transactf("ok", `search body "Joe" text "Blurdybloop"`)
169 tc.transactf("ok", `search body "Joe" not text "mox"`)
171 tc.transactf("ok", `search body "Joe" not not body "Joe"`)
173 tc.transactf("ok", `search body "this is plain text"`)
175 tc.transactf("ok", `search body "this is html"`)
178 tc.transactf("ok", `search cc "xcc@mox.example"`)
181 tc.transactf("ok", `search deleted`)
184 tc.transactf("ok", `search flagged`)
187 tc.transactf("ok", `search from "foobar@Blurdybloop.example"`)
190 tc.transactf("ok", `search keyword $Forwarded`)
193 tc.transactf("ok", `search keyword Custom1`)
196 tc.transactf("ok", `search keyword custom2`)
199 tc.transactf("ok", `search new`)
200 tc.xsearch() // New requires a message to be recent. We pretend all messages are not recent.
202 tc.transactf("ok", `search old`)
205 tc.transactf("ok", `search on 1-Jan-2022`)
208 tc.transactf("ok", `search recent`)
211 tc.transactf("ok", `search seen`)
214 tc.transactf("ok", `search since 1-Jan-2020`)
217 tc.transactf("ok", `search subject "afternoon"`)
220 tc.transactf("ok", `search text "Joe"`)
223 tc.transactf("ok", `search to "mooch@owatagu.siam.edu.example"`)
226 tc.transactf("ok", `search unanswered`)
229 tc.transactf("ok", `search undeleted`)
232 tc.transactf("ok", `search unflagged`)
235 tc.transactf("ok", `search unkeyword $Junk`)
238 tc.transactf("ok", `search unkeyword custom1`)
241 tc.transactf("ok", `search unseen`)
244 tc.transactf("ok", `search draft`)
247 tc.transactf("ok", `search header "subject" "afternoon"`)
250 tc.transactf("ok", `search larger 1`)
253 tc.transactf("ok", `search not text "mox"`)
256 tc.transactf("ok", `search or seen unseen`)
259 tc.transactf("ok", `search or unseen seen`)
262 tc.transactf("ok", `search sentbefore 8-Feb-1994`)
265 tc.transactf("ok", `search senton 7-Feb-1994`)
268 tc.transactf("ok", `search sentsince 6-Feb-1994`)
271 tc.transactf("ok", `search smaller 9999999`)
274 tc.transactf("ok", `search uid 1`)
277 tc.transactf("ok", `search uid 5`)
280 tc.transactf("ok", `search or larger 1000000 smaller 1`)
283 tc.transactf("ok", `search undraft`)
286 tc.transactf("no", `search charset unknown text "mox"`)
287 tc.transactf("ok", `search charset us-ascii text "mox"`)
289 tc.transactf("ok", `search charset utf-8 text "mox"`)
292 // Check for properly formed INPROGRESS response code.
293 orig := inProgressPeriod
295 tc.cmdf("tag1", "search undraft")
298 inprogress := func(cur, goal uint32) imapclient.UntaggedResult {
299 return imapclient.UntaggedResult{
301 Code: imapclient.CodeInProgress{Tag: "tag1", Current: &cur, Goal: &goal},
302 Text: "still searching",
306 imapclient.UntaggedSearch([]uint32{1, 2}),
307 // Due to inProgressPeriod 0, we get an inprogress response for each message in the mailbox.
312 inProgressPeriod = orig
314 // Do new-style ESEARCH requests with RETURN. We should get an ESEARCH response.
315 tc.transactf("ok", "search return () all")
316 tc.xesearch(esearchall("1:3")) // Without any options, "ALL" is implicit.
318 tc.transactf("ok", "search return (min max count all) all")
319 tc.xesearch(imapclient.UntaggedEsearch{Min: 1, Max: 3, Count: uint32ptr(3), All: esearchall0("1:3")})
321 tc.transactf("ok", "search return (min) all")
322 tc.xesearch(imapclient.UntaggedEsearch{Min: 1})
324 tc.transactf("ok", "search return (min) 3")
325 tc.xesearch(imapclient.UntaggedEsearch{Min: 3})
327 tc.transactf("ok", "search return (min) NOT all")
328 tc.xesearch(imapclient.UntaggedEsearch{}) // Min not present if no match.
330 tc.transactf("ok", "search return (max) all")
331 tc.xesearch(imapclient.UntaggedEsearch{Max: 3})
333 tc.transactf("ok", "search return (max) 1")
334 tc.xesearch(imapclient.UntaggedEsearch{Max: 1})
336 tc.transactf("ok", "search return (max) not all")
337 tc.xesearch(imapclient.UntaggedEsearch{}) // Max not present if no match.
339 tc.transactf("ok", "search return (min max) all")
340 tc.xesearch(imapclient.UntaggedEsearch{Min: 1, Max: 3})
342 tc.transactf("ok", "search return (min max) 1")
343 tc.xesearch(imapclient.UntaggedEsearch{Min: 1, Max: 1})
345 tc.transactf("ok", "search return (min max) not all")
346 tc.xesearch(imapclient.UntaggedEsearch{})
348 tc.transactf("ok", "search return (all) not all")
349 tc.xesearch(imapclient.UntaggedEsearch{}) // All not present if no match.
351 tc.transactf("ok", "search return (min max all) not all")
352 tc.xesearch(imapclient.UntaggedEsearch{})
354 tc.transactf("ok", "search return (min max all count) not all")
355 tc.xesearch(imapclient.UntaggedEsearch{Count: uint32ptr(0)})
357 tc.transactf("ok", "search return (min max count all) 1,3")
358 tc.xesearch(imapclient.UntaggedEsearch{Min: 1, Max: 3, Count: uint32ptr(2), All: esearchall0("1,3")})
360 tc.transactf("ok", "search return (min max count all) UID 5,7")
361 tc.xesearch(imapclient.UntaggedEsearch{Min: 1, Max: 3, Count: uint32ptr(2), All: esearchall0("1,3")})
364 tc.transactf("ok", "UID search return (min max count all) all")
365 tc.xesearch(imapclient.UntaggedEsearch{UID: true, Min: 5, Max: 7, Count: uint32ptr(3), All: esearchall0("5:7")})
368 tc.transactf("ok", "uid search return (min max count all) 1,3")
369 tc.xesearch(imapclient.UntaggedEsearch{UID: true, Min: 5, Max: 7, Count: uint32ptr(2), All: esearchall0("5,7")})
372 tc.transactf("ok", "uid search return (min max count all) UID 5,7")
373 tc.xesearch(imapclient.UntaggedEsearch{UID: true, Min: 5, Max: 7, Count: uint32ptr(2), All: esearchall0("5,7")})
376 tc.transactf("no", `search return () charset unknown text "mox"`)
377 tc.transactf("ok", `search return () charset us-ascii text "mox"`)
378 tc.xesearch(esearchall("2:3"))
379 tc.transactf("ok", `search return () charset utf-8 text "mox"`)
380 tc.xesearch(esearchall("2:3"))
382 tc.transactf("bad", `search return (unknown) all`)
384 tc.transactf("ok", "search return (save) 2")
386 tc.transactf("ok", "fetch $ (uid)")
387 tc.xuntagged(tc.untaggedFetch(2, 6))
389 tc.transactf("ok", "search return (all) $")
390 tc.xesearch(esearchall("2"))
392 tc.transactf("ok", "search return (save) $")
395 tc.transactf("ok", "search return (save all) all")
396 tc.xesearch(esearchall("1:3"))
398 tc.transactf("ok", "search return (all save) all")
399 tc.xesearch(esearchall("1:3"))
401 tc.transactf("ok", "search return (min save) all")
402 tc.xesearch(imapclient.UntaggedEsearch{Min: 1})
403 tc.transactf("ok", "fetch $ (uid)")
404 tc.xuntagged(tc.untaggedFetch(1, 5))
407 // Do a seemingly old-style search command with IMAP4rev2 enabled. We'll still get ESEARCH responses.
408 tc.client.Enable(imapclient.CapIMAP4rev2)
411 tc.transactf("ok", `search undraft`)
412 tc.xesearch(esearchall("1:2"))
415 // Long commands should be rejected, not allocating too much memory.
416 lit := make([]byte, 100*1024+1)
420 writeTextLit := func(n int, expok bool) {
421 _, err := fmt.Fprintf(tc.client, " TEXT ")
422 tcheck(t, err, "write text")
424 _, err = fmt.Fprintf(tc.client, "{%d}\r\n", n)
425 tcheck(t, err, "write literal size")
426 line, err := tc.client.Readline()
427 tcheck(t, err, "read line")
428 if expok && !strings.HasPrefix(line, "+") {
429 tcheck(t, fmt.Errorf("no continuation after writing size: %s", line), "sending literal")
430 } else if !expok && !strings.HasPrefix(line, "x0 BAD [TOOBIG]") {
431 tcheck(t, fmt.Errorf("got line %s", line), "expected TOOBIG error")
436 _, err = tc.client.Write(lit[:n])
437 tcheck(t, err, "write literal data")
440 // More than 100k for a literal.
441 _, err := fmt.Fprintf(tc.client, "x0 uid search")
442 tcheck(t, err, "write start of uit search")
443 writeTextLit(100*1024+1, false)
445 // More than 1mb total for literals.
446 _, err = fmt.Fprintf(tc.client, "x0 uid search")
447 tcheck(t, err, "write start of uit search")
449 writeTextLit(100*1024, true)
451 writeTextLit(1, false)
453 // More than 1000 literals.
454 _, err = fmt.Fprintf(tc.client, "x0 uid search")
455 tcheck(t, err, "write start of uit search")
457 writeTextLit(1, true)
459 writeTextLit(1, false)
462// esearchall makes an UntaggedEsearch response with All set, for comparisons.
463func esearchall0(ss string) imapclient.NumSet {
464 seqset := imapclient.NumSet{}
465 for _, rs := range strings.Split(ss, ",") {
466 t := strings.Split(rs, ":")
473 v, err := strconv.ParseUint(t[0], 10, 32)
481 v, err := strconv.ParseUint(t[1], 10, 32)
489 seqset.Ranges = append(seqset.Ranges, imapclient.NumRange{First: first, Last: last})
494func TestSearchMultiUnselected(t *testing.T) {
495 testSearchMulti(t, false, false)
498func TestSearchMultiSelected(t *testing.T) {
499 testSearchMulti(t, true, false)
502func TestSearchMultiSelectedUIDOnly(t *testing.T) {
503 testSearchMulti(t, true, true)
506// Test the MULTISEARCH extension, with and without selected mailbx. Operating
507// without messag sequence numbers, and return untagged esearch responses that
508// include the mailbox and uidvalidity.
509func testSearchMulti(t *testing.T, selected, uidonly bool) {
510 defer mockUIDValidity()()
512 tc := start(t, uidonly)
514 tc.login("mjl@mox.example", password0)
515 tc.client.Select("inbox")
517 // Add 5 messages to Inbox and delete first 4 messages. So UIDs start at 5.
518 received := time.Date(2020, time.January, 1, 10, 0, 0, 0, time.UTC)
520 tc.client.Append("inbox", makeAppendTime(exampleMsg, received))
522 tc.client.UIDStoreFlagsSet("1:4", true, `\Deleted`)
525 // Unselecting mailbox, esearch works in authenticated state.
530 received = time.Date(2022, time.January, 1, 9, 0, 0, 0, time.UTC)
531 tc.client.Append("inbox", makeAppendTime(searchMsg, received))
533 received = time.Date(2022, time.January, 1, 9, 0, 0, 0, time.UTC)
534 mostFlags := []string{
548 tc.client.Append("Archive", imapclient.Append{Flags: mostFlags, Received: &received, Size: int64(len(searchMsg)), Data: strings.NewReader(searchMsg)})
550 // We now have sequence numbers 1,2,3 and UIDs 5,6,7 in Inbox, and UID 1 in Archive.
552 // Basic esearch with mailboxes.
553 tc.cmdf("Tag1", `Esearch In (Personal) Return () All`)
556 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:7")},
557 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, All: esearchall0("1")},
560 // Again, but with progress information.
561 orig := inProgressPeriod
563 inprogress := func(cur, goal uint32) imapclient.UntaggedResult {
564 return imapclient.UntaggedResult{
566 Code: imapclient.CodeInProgress{Tag: "Tag1", Current: &cur, Goal: &goal},
567 Text: "still searching",
570 tc.cmdf("Tag1", `Esearch In (Personal) Return () All`)
573 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:7")},
574 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, All: esearchall0("1")},
580 inProgressPeriod = orig
582 // Explicit mailboxes listed, including non-existent one that is ignored,
583 // duplicates are ignored as well.
584 tc.cmdf("Tag1", `Esearch In (Mailboxes (INBOX Archive Archive)) Return (Min Max Count All) All`)
587 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5, Max: 7, Count: uint32ptr(3), All: esearchall0("5:7")},
588 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, Min: 1, Max: 1, Count: uint32ptr(1), All: esearchall0("1")},
591 // No response if none of the mailboxes exist.
592 tc.cmdf("Tag1", `Esearch In (Mailboxes bogus Mailboxes (nonexistent)) Return (Min Max Count All) All`)
596 // Inboxes evaluates to just inbox on new account. We'll add more mailboxes
597 // matching "inboxes" later on.
598 tc.cmdf("Tag1", `Esearch In (Inboxes) Return () All`)
601 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:7")},
604 // Subscribed is set for created mailboxes by default.
605 tc.cmdf("Tag1", `Esearch In (Subscribed) Return (Max) All`)
608 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Max: 7},
609 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, Max: 1},
612 // Asking for max does a reverse search.
613 tc.cmdf("Tag1", `Esearch In (Personal) Return (Max) All`)
616 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Max: 7},
617 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, Max: 1},
621 tc.cmdf("Tag1", `Esearch In (Personal) Return (Min) All`)
624 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5},
625 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, Min: 1},
628 // Min and max do forward and reverse search, stopping early.
629 tc.cmdf("Tag1", `Esearch In (Personal) Return (Min Max) All`)
632 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5, Max: 7},
633 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, Min: 1, Max: 1},
637 // With only 1 inbox, we can use SAVE with Inboxes. Can't anymore when we have multiple.
638 tc.transactf("ok", `Esearch In (Inboxes) Return (Save) All`)
641 // Using search result ($) works with selected mailbox.
642 tc.cmdf("Tag1", `Esearch In (Selected) Return () $`)
645 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:7")},
648 // Cannot use "selected" if we are not in selected state.
649 tc.transactf("bad", `Esearch In (Selected) Return () All`)
652 // Add more "inboxes", and other mailboxes for testing "subtree" and "subtree-one".
659 "Other/Sub1", // sub1@mox.example in config.
661 "Other/Sub2/SubA", // ruleset for sub2@mox.example in config.
663 "List", // ruleset for a mailing list
665 for _, name := range more {
666 tc.client.Create(name, nil)
667 tc.client.Append(name, makeAppendTime(exampleMsg, received))
670 // Cannot use SAVE with multiple mailboxes that match.
671 tc.transactf("bad", `Esearch In (Inboxes) Return (Save) All`)
673 // "inboxes" includes everything below Inbox, and also anything that we might
674 // deliver to based on account addresses and rulesets, but not mailing lists.
675 tc.cmdf("Tag1", `Esearch In (Inboxes) Return () All`)
678 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:7")},
679 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox/Sub1", UIDValidity: 3, UID: true, All: esearchall0("1")},
680 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox/Sub2", UIDValidity: 4, UID: true, All: esearchall0("1")},
681 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox/Sub2/SubA", UIDValidity: 5, UID: true, All: esearchall0("1")},
682 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox/Sub2/SubB", UIDValidity: 6, UID: true, All: esearchall0("1")},
683 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub1", UIDValidity: 8, UID: true, All: esearchall0("1")},
684 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub2/SubA", UIDValidity: 10, UID: true, All: esearchall0("1")},
688 tc.cmdf("Tag1", `Esearch In (Subtree Other) Return () All`)
691 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other", UIDValidity: 7, UID: true, All: esearchall0("1")},
692 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub1", UIDValidity: 8, UID: true, All: esearchall0("1")},
693 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub2", UIDValidity: 9, UID: true, All: esearchall0("1")},
694 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub2/SubA", UIDValidity: 10, UID: true, All: esearchall0("1")},
695 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub2/SubB", UIDValidity: 11, UID: true, All: esearchall0("1")},
699 tc.cmdf("Tag1", `Esearch In (Subtree-One Other) Return () All`)
702 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other", UIDValidity: 7, UID: true, All: esearchall0("1")},
703 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub1", UIDValidity: 8, UID: true, All: esearchall0("1")},
704 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Other/Sub2", UIDValidity: 9, UID: true, All: esearchall0("1")},
707 // Search with sequence set also for non-selected mailboxes(!). The min/max would
708 // get the first and last message, but the message sequence set forces a scan. Not
709 // allowed with UIDONLY.
711 tc.cmdf("Tag1", `Esearch In (Mailboxes Inbox) Return (Min Max) 1:*`)
714 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5, Max: 7},
718 // Search with uid set with "$highnum:*" forces getting highest uid.
719 tc.cmdf("Tag1", `Esearch In (Mailboxes Inbox) Return (Min Max) Uid *:100`)
722 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 7, Max: 7},
724 tc.cmdf("Tag1", `Esearch In (Mailboxes Inbox) Return (Min Max) Uid 100:*`)
727 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 7, Max: 7},
729 tc.cmdf("Tag1", `Esearch In (Mailboxes Inbox) Return (Min Max) Uid 1:*`)
732 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5, Max: 7},
735 // We use another session to add a new message to Inbox and to Archive. Searching
736 // with Inbox selected will not return the new message since it isn't available in
737 // the session yet. The message in Archive is returned, since there is no session
739 tc2 := startNoSwitchboard(t, uidonly)
740 defer tc2.closeNoWait()
741 tc2.login("mjl@mox.example", password0)
742 tc2.client.Append("inbox", makeAppendTime(searchMsg, received))
743 tc2.client.Append("Archive", makeAppendTime(searchMsg, received))
745 tc.cmdf("Tag1", `Esearch In (Mailboxes (Inbox Archive)) Return (Count) All`)
749 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Count: uint32ptr(3)},
750 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, Count: uint32ptr(2)},
751 imapclient.UntaggedExists(4),
752 tc.untaggedFetch(4, 8, imapclient.FetchFlags(nil)),
756 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Count: uint32ptr(4)},
757 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Archive", UIDValidity: 1, UID: true, Count: uint32ptr(2)},
762 // Saving a search result, and then using it with another mailbox results in error.
763 tc.transactf("ok", `Esearch In (Mailboxes Inbox) Return (Save) All`)
764 tc.transactf("no", `Esearch In (Mailboxes Archive) Return () $`)
766 tc.transactf("bad", `Esearch In (Inboxes) Return (Save) All`) // Need a selected mailbox with SAVE.
767 tc.transactf("no", `Esearch In (Inboxes) Return () $`) // Cannot use saved result with non-selected mailbox.
770 tc.transactf("bad", `Esearch In () Return () All`) // Missing values for "IN"-list.
771 tc.transactf("bad", `Esearch In (Bogus) Return () All`) // Bogus word for "IN".
772 tc.transactf("bad", `Esearch In ("Selected") Return () All`) // IN-words can't be quoted.
773 tc.transactf("bad", `Esearch In (Selected-Delayed) Return () All`) // From NOTIFY, not in ESEARCH.
774 tc.transactf("bad", `Esearch In (Subtree-One) Return () All`) // After subtree-one we need a list.
775 tc.transactf("bad", `Esearch In (Subtree-One ) Return () All`) // After subtree-one we need a list.
776 tc.transactf("bad", `Esearch In (Subtree-One (Test) ) Return () All`) // Bogus space.
781 // From now on, we are in selected state.
783 tc.cmdf("Tag1", `Esearch In (Selected) Return () All`)
786 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:8")},
790 tc.transactf("ok", `Esearch In (Selected) Return (Save) All`)
793 tc.cmdf("Tag1", `Esearch In (Selected) Return () $`)
796 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:8")},
799 // Inbox happens to be the selected mailbox, so OK.
800 tc.cmdf("Tag1", `Esearch In (Mailboxes Inbox) Return () $`)
803 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:8")},
806 // Non-selected mailboxes aren't allowed to use the saved result.
807 tc.transactf("no", `Esearch In (Mailboxes Archive) Return () $`)
808 tc.transactf("no", `Esearch In (Mailboxes Archive) Return () uid $`)
810 tc.cmdf("Tag1", `Esearch In (Selected) Return (Save Min Max) All`)
813 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5, Max: 8},
815 tc.cmdf("Tag1", `Esearch In (Selected) Return () $`)
818 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5,8")},
821 tc.cmdf("Tag1", `Esearch In (Selected) Return (Save Min) All`)
824 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5},
827 tc.cmdf("Tag1", `Esearch In (Selected) Return () $`)
830 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5")},
833 tc.cmdf("Tag1", `Esearch In (Selected) Return (Save Max) All`)
836 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Max: 8},
839 tc.cmdf("Tag1", `Esearch In (Selected) Return () $`)
842 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("8")},
845 tc.cmdf("Tag1", `Esearch In (Selected) Return (Save Min Max Count) All`)
848 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, Min: 5, Max: 8, Count: uint32ptr(4)},
851 tc.cmdf("Tag1", `Esearch In (Selected) Return () $`)
854 imapclient.UntaggedEsearch{Tag: "Tag1", Mailbox: "Inbox", UIDValidity: 1, UID: true, All: esearchall0("5:8")},