@@ -378,6 +378,129 @@ func TestClient_Fetch_Uid(t *testing.T) {
378378 }
379379}
380380
381+ func TestClient_Fetch_Unilateral (t * testing.T ) {
382+ c , s := newTestClient (t )
383+ defer s .Close ()
384+
385+ setClientState (c , imap .SelectedState , nil )
386+
387+ seqset , _ := imap .ParseSeqSet ("1:4" )
388+ fields := []imap.FetchItem {imap .FetchFlags }
389+
390+ done := make (chan error , 1 )
391+ messages := make (chan * imap.Message , 3 )
392+ go func () {
393+ done <- c .Fetch (seqset , fields , messages )
394+ }()
395+
396+ tag , cmd := s .ScanCmd ()
397+ if cmd != "FETCH 1:4 (FLAGS)" {
398+ t .Fatalf ("client sent command %v, want %v" , cmd , "FETCH 1:4 (FLAGS)" )
399+ }
400+
401+ s .WriteString ("* 2 FETCH (FLAGS (\\ Seen))\r \n " )
402+ s .WriteString ("* 123 FETCH (FLAGS (\\ Deleted))\r \n " )
403+ s .WriteString ("* 4 FETCH (FLAGS (\\ Seen))\r \n " )
404+ s .WriteString (tag + " OK FETCH completed\r \n " )
405+
406+ if err := <- done ; err != nil {
407+ t .Fatalf ("c.Fetch() = %v" , err )
408+ }
409+
410+ msg := <- messages
411+ if msg .SeqNum != 2 {
412+ t .Errorf ("First message has bad sequence number: %v" , msg .SeqNum )
413+ }
414+ msg = <- messages
415+ if msg .SeqNum != 4 {
416+ t .Errorf ("Second message has bad sequence number: %v" , msg .SeqNum )
417+ }
418+
419+ _ , ok := <- messages
420+ if ok {
421+ t .Errorf ("More than two messages" )
422+ }
423+ }
424+
425+ func TestClient_Fetch_Unilateral_Uid (t * testing.T ) {
426+ c , s := newTestClient (t )
427+ defer s .Close ()
428+
429+ setClientState (c , imap .SelectedState , nil )
430+
431+ seqset , _ := imap .ParseSeqSet ("1:4" )
432+ fields := []imap.FetchItem {imap .FetchFlags }
433+
434+ done := make (chan error , 1 )
435+ messages := make (chan * imap.Message , 3 )
436+ go func () {
437+ done <- c .UidFetch (seqset , fields , messages )
438+ }()
439+
440+ tag , cmd := s .ScanCmd ()
441+ if cmd != "UID FETCH 1:4 (FLAGS)" {
442+ t .Fatalf ("client sent command %v, want %v" , cmd , "UID FETCH 1:4 (FLAGS)" )
443+ }
444+
445+ s .WriteString ("* 23 FETCH (UID 2 FLAGS (\\ Seen))\r \n " )
446+ s .WriteString ("* 123 FETCH (FLAGS (\\ Deleted))\r \n " )
447+ s .WriteString ("* 49 FETCH (UID 4 FLAGS (\\ Seen))\r \n " )
448+ s .WriteString (tag + " OK FETCH completed\r \n " )
449+
450+ if err := <- done ; err != nil {
451+ t .Fatalf ("c.Fetch() = %v" , err )
452+ }
453+
454+ msg := <- messages
455+ if msg .Uid != 2 {
456+ t .Errorf ("First message has bad UID: %v" , msg .Uid )
457+ }
458+ msg = <- messages
459+ if msg .Uid != 4 {
460+ t .Errorf ("Second message has bad UID: %v" , msg .Uid )
461+ }
462+
463+ _ , ok := <- messages
464+ if ok {
465+ t .Errorf ("More than two messages" )
466+ }
467+ }
468+
469+ func TestClient_Fetch_Uid_Dynamic (t * testing.T ) {
470+ c , s := newTestClient (t )
471+ defer s .Close ()
472+
473+ setClientState (c , imap .SelectedState , nil )
474+
475+ seqset , _ := imap .ParseSeqSet ("4:*" )
476+ fields := []imap.FetchItem {imap .FetchFlags }
477+
478+ done := make (chan error , 1 )
479+ messages := make (chan * imap.Message , 1 )
480+ go func () {
481+ done <- c .UidFetch (seqset , fields , messages )
482+ }()
483+
484+ tag , cmd := s .ScanCmd ()
485+ if cmd != "UID FETCH 4:* (FLAGS)" {
486+ t .Fatalf ("client sent command %v, want %v" , cmd , "UID FETCH 4:* (FLAGS)" )
487+ }
488+
489+ s .WriteString ("* 23 FETCH (UID 2 FLAGS (\\ Seen))\r \n " )
490+ s .WriteString (tag + " OK FETCH completed\r \n " )
491+
492+ if err := <- done ; err != nil {
493+ t .Fatalf ("c.Fetch() = %v" , err )
494+ }
495+
496+ msg , ok := <- messages
497+ if ! ok {
498+ t .Errorf ("No message supplied" )
499+ } else if msg .Uid != 2 {
500+ t .Errorf ("First message has bad UID: %v" , msg .Uid )
501+ }
502+ }
503+
381504func TestClient_Store (t * testing.T ) {
382505 c , s := newTestClient (t )
383506 defer s .Close ()
0 commit comments