@@ -466,6 +466,259 @@ public void TestNotSupportedExceptions ()
466
466
}
467
467
468
468
static readonly string [ ] PreviewTextValues = {
469
+ "Planet Fitness https://view.email.planetfitness.com/?qs=9a098a031cabde68c0a4260051cd6fe473a2e997a53678ff26b4b199a711a9d2ad0536530d6f837c246b09f644d42016ecfb298f930b7af058e9e454b34f3d818ceb3052ae317b1ac4594aab28a2d788 View web ver" ,
470
+ "Don't miss our celebrity guest Monday evening" ,
471
+ "Planet Fitness https://view.email.planetfitness.com/?qs=9a098a031cabde68c0a4260051cd6fe473a2e997a53678ff26b4b199a711a9d2ad0536530d6f837c246b09f644d42016ecfb298f930b7af058e9e454b34f3d818ceb3052ae317b1ac4594aab28a2d788 View web ver" ,
472
+ "Planet Fitness https://view.email.planetfitness.com/?qs=9a098a031cabde68c0a4260051cd6fe473a2e997a53678ff26b4b199a711a9d2ad0536530d6f837c246b09f644d42016ecfb298f930b7af058e9e454b34f3d818ceb3052ae317b1ac4594aab28a2d788 View web ver" ,
473
+ "Don't miss our celebrity guest Monday evening" ,
474
+ "Planet Fitness https://view.email.planetfitness.com/?qs=9a098a031cabde68c0a4260051cd6fe473a2e997a53678ff26b4b199a711a9d2ad0536530d6f837c246b09f644d42016ecfb298f930b7af058e9e454b34f3d818ceb3052ae317b1ac4594aab28a2d788 View web ver"
475
+ } ;
476
+
477
+ static List < ImapReplayCommand > CreateFetchPreviewTextCommands ( )
478
+ {
479
+ return new List < ImapReplayCommand > {
480
+ new ImapReplayCommand ( "" , "gmail.greeting.txt" ) ,
481
+ new ImapReplayCommand ( "A00000000 CAPABILITY\r \n " , "gmail.capability.txt" ) ,
482
+ new ImapReplayCommand ( "A00000001 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r \n " , "gmail.authenticate+preview.txt" ) ,
483
+ new ImapReplayCommand ( "A00000002 NAMESPACE\r \n " , "gmail.namespace.txt" ) ,
484
+ new ImapReplayCommand ( "A00000003 LIST \" \" \" INBOX\" RETURN (SUBSCRIBED CHILDREN)\r \n " , "gmail.list-inbox.txt" ) ,
485
+ new ImapReplayCommand ( "A00000004 XLIST \" \" \" *\" \r \n " , "gmail.xlist.txt" ) ,
486
+ new ImapReplayCommand ( "A00000005 LIST \" \" \" %\" \r \n " , "gmail.list-personal.txt" ) ,
487
+ new ImapReplayCommand ( "A00000006 EXAMINE INBOX (CONDSTORE)\r \n " , "gmail.examine-inbox.txt" ) ,
488
+ new ImapReplayCommand ( "A00000007 UID FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE PREVIEW)\r \n " , "gmail.fetch-preview.txt" ) ,
489
+ new ImapReplayCommand ( "A00000008 FETCH 1:6 (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE PREVIEW)\r \n " , "gmail.fetch-preview.txt" ) ,
490
+ new ImapReplayCommand ( "A00000009 FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE PREVIEW)\r \n " , "gmail.fetch-preview.txt" )
491
+ } ;
492
+ }
493
+
494
+ [ Test ]
495
+ public void TestFetchPreviewText ( )
496
+ {
497
+ var commands = CreateFetchPreviewTextCommands ( ) ;
498
+
499
+ using ( var client = new ImapClient ( ) ) {
500
+ try {
501
+ client . ReplayConnect ( "localhost" , new ImapReplayStream ( commands , false ) ) ;
502
+ } catch ( Exception ex ) {
503
+ Assert . Fail ( "Did not expect an exception in Connect: {0}" , ex ) ;
504
+ }
505
+
506
+ // Note: Do not try XOAUTH2
507
+ client . AuthenticationMechanisms . Remove ( "XOAUTH2" ) ;
508
+
509
+ try {
510
+ client . Authenticate ( "username" , "password" ) ;
511
+ } catch ( Exception ex ) {
512
+ Assert . Fail ( "Did not expect an exception in Authenticate: {0}" , ex ) ;
513
+ }
514
+
515
+ // disable LIST-EXTENDED
516
+ client . Capabilities &= ~ ImapCapabilities . ListExtended ;
517
+
518
+ var personal = client . GetFolder ( client . PersonalNamespaces [ 0 ] ) ;
519
+ var folders = personal . GetSubfolders ( ) ;
520
+ Assert . AreEqual ( client . Inbox , folders [ 0 ] , "Expected the first folder to be the Inbox." ) ;
521
+ Assert . AreEqual ( "[Gmail]" , folders [ 1 ] . FullName , "Expected the second folder to be [Gmail]." ) ;
522
+ Assert . AreEqual ( FolderAttributes . NoSelect | FolderAttributes . HasChildren , folders [ 1 ] . Attributes , "Expected [Gmail] folder to be \\ Noselect \\ HasChildren." ) ;
523
+
524
+ var inbox = client . Inbox ;
525
+
526
+ inbox . Open ( FolderAccess . ReadOnly ) ;
527
+
528
+ var messages = inbox . Fetch ( UniqueIdRange . All , MessageSummaryItems . All | MessageSummaryItems . PreviewText ) ;
529
+ for ( int i = 0 ; i < messages . Count ; i ++ )
530
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
531
+
532
+ messages = inbox . Fetch ( new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } , MessageSummaryItems . All | MessageSummaryItems . PreviewText ) ;
533
+ for ( int i = 0 ; i < messages . Count ; i ++ )
534
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
535
+
536
+ messages = inbox . Fetch ( 0 , - 1 , MessageSummaryItems . All | MessageSummaryItems . PreviewText ) ;
537
+ for ( int i = 0 ; i < messages . Count ; i ++ )
538
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
539
+
540
+ client . Disconnect ( false ) ;
541
+ }
542
+ }
543
+
544
+ [ Test ]
545
+ public async Task TestFetchPreviewTextAsync ( )
546
+ {
547
+ var commands = CreateFetchPreviewTextCommands ( ) ;
548
+
549
+ using ( var client = new ImapClient ( ) ) {
550
+ try {
551
+ await client . ReplayConnectAsync ( "localhost" , new ImapReplayStream ( commands , true ) ) ;
552
+ } catch ( Exception ex ) {
553
+ Assert . Fail ( "Did not expect an exception in Connect: {0}" , ex ) ;
554
+ }
555
+
556
+ // Note: Do not try XOAUTH2
557
+ client . AuthenticationMechanisms . Remove ( "XOAUTH2" ) ;
558
+
559
+ try {
560
+ await client . AuthenticateAsync ( "username" , "password" ) ;
561
+ } catch ( Exception ex ) {
562
+ Assert . Fail ( "Did not expect an exception in Authenticate: {0}" , ex ) ;
563
+ }
564
+
565
+ // disable LIST-EXTENDED
566
+ client . Capabilities &= ~ ImapCapabilities . ListExtended ;
567
+
568
+ var personal = client . GetFolder ( client . PersonalNamespaces [ 0 ] ) ;
569
+ var folders = await personal . GetSubfoldersAsync ( ) ;
570
+ Assert . AreEqual ( client . Inbox , folders [ 0 ] , "Expected the first folder to be the Inbox." ) ;
571
+ Assert . AreEqual ( "[Gmail]" , folders [ 1 ] . FullName , "Expected the second folder to be [Gmail]." ) ;
572
+ Assert . AreEqual ( FolderAttributes . NoSelect | FolderAttributes . HasChildren , folders [ 1 ] . Attributes , "Expected [Gmail] folder to be \\ Noselect \\ HasChildren." ) ;
573
+
574
+ var inbox = client . Inbox ;
575
+
576
+ await inbox . OpenAsync ( FolderAccess . ReadOnly ) ;
577
+
578
+ var messages = await inbox . FetchAsync ( UniqueIdRange . All , MessageSummaryItems . All | MessageSummaryItems . PreviewText ) ;
579
+ for ( int i = 0 ; i < messages . Count ; i ++ )
580
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
581
+
582
+ messages = await inbox . FetchAsync ( new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } , MessageSummaryItems . All | MessageSummaryItems . PreviewText ) ;
583
+ for ( int i = 0 ; i < messages . Count ; i ++ )
584
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
585
+
586
+ messages = await inbox . FetchAsync ( 0 , - 1 , MessageSummaryItems . All | MessageSummaryItems . PreviewText ) ;
587
+ for ( int i = 0 ; i < messages . Count ; i ++ )
588
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
589
+
590
+ await client . DisconnectAsync ( false ) ;
591
+ }
592
+ }
593
+
594
+ #if ENABLE_LAZY_PREVIEW_API
595
+ static List < ImapReplayCommand > CreateFetchLazyPreviewTextCommands ( )
596
+ {
597
+ return new List < ImapReplayCommand > {
598
+ new ImapReplayCommand ( "" , "gmail.greeting.txt" ) ,
599
+ new ImapReplayCommand ( "A00000000 CAPABILITY\r \n " , "gmail.capability.txt" ) ,
600
+ new ImapReplayCommand ( "A00000001 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r \n " , "gmail.authenticate+preview.txt" ) ,
601
+ new ImapReplayCommand ( "A00000002 NAMESPACE\r \n " , "gmail.namespace.txt" ) ,
602
+ new ImapReplayCommand ( "A00000003 LIST \" \" \" INBOX\" RETURN (SUBSCRIBED CHILDREN)\r \n " , "gmail.list-inbox.txt" ) ,
603
+ new ImapReplayCommand ( "A00000004 XLIST \" \" \" *\" \r \n " , "gmail.xlist.txt" ) ,
604
+ new ImapReplayCommand ( "A00000005 LIST \" \" \" %\" \r \n " , "gmail.list-personal.txt" ) ,
605
+ new ImapReplayCommand ( "A00000006 EXAMINE INBOX (CONDSTORE)\r \n " , "gmail.examine-inbox.txt" ) ,
606
+ new ImapReplayCommand ( "A00000007 UID FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE PREVIEW (LAZY))\r \n " , "gmail.fetch-preview.txt" ) ,
607
+ new ImapReplayCommand ( "A00000008 FETCH 1:6 (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE PREVIEW (LAZY))\r \n " , "gmail.fetch-preview.txt" ) ,
608
+ new ImapReplayCommand ( "A00000009 FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE PREVIEW (LAZY))\r \n " , "gmail.fetch-preview.txt" )
609
+ } ;
610
+ }
611
+
612
+ [ Test ]
613
+ public void TestFetchLazyPreviewText ( )
614
+ {
615
+ var commands = CreateFetchLazyPreviewTextCommands ( ) ;
616
+
617
+ using ( var client = new ImapClient ( ) ) {
618
+ try {
619
+ client . ReplayConnect ( "localhost" , new ImapReplayStream ( commands , false ) ) ;
620
+ } catch ( Exception ex ) {
621
+ Assert . Fail ( "Did not expect an exception in Connect: {0}" , ex ) ;
622
+ }
623
+
624
+ // Note: Do not try XOAUTH2
625
+ client . AuthenticationMechanisms . Remove ( "XOAUTH2" ) ;
626
+
627
+ try {
628
+ client . Authenticate ( "username" , "password" ) ;
629
+ } catch ( Exception ex ) {
630
+ Assert . Fail ( "Did not expect an exception in Authenticate: {0}" , ex ) ;
631
+ }
632
+
633
+ // disable LIST-EXTENDED
634
+ client . Capabilities &= ~ ImapCapabilities . ListExtended ;
635
+
636
+ var personal = client . GetFolder ( client . PersonalNamespaces [ 0 ] ) ;
637
+ var folders = personal . GetSubfolders ( ) ;
638
+ Assert . AreEqual ( client . Inbox , folders [ 0 ] , "Expected the first folder to be the Inbox." ) ;
639
+ Assert . AreEqual ( "[Gmail]" , folders [ 1 ] . FullName , "Expected the second folder to be [Gmail]." ) ;
640
+ Assert . AreEqual ( FolderAttributes . NoSelect | FolderAttributes . HasChildren , folders [ 1 ] . Attributes , "Expected [Gmail] folder to be \\ Noselect \\ HasChildren." ) ;
641
+
642
+ var inbox = client . Inbox ;
643
+
644
+ inbox . Open ( FolderAccess . ReadOnly ) ;
645
+
646
+ var request = new FetchRequest ( MessageSummaryItems . All | MessageSummaryItems . PreviewText ) {
647
+ PreviewOptions = PreviewOptions . Lazy
648
+ } ;
649
+
650
+ var messages = inbox . Fetch ( UniqueIdRange . All , request ) ;
651
+ for ( int i = 0 ; i < messages . Count ; i ++ )
652
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
653
+
654
+ messages = inbox . Fetch ( new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } , request ) ;
655
+ for ( int i = 0 ; i < messages . Count ; i ++ )
656
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
657
+
658
+ messages = inbox . Fetch ( 0 , - 1 , request ) ;
659
+ for ( int i = 0 ; i < messages . Count ; i ++ )
660
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
661
+
662
+ client . Disconnect ( false ) ;
663
+ }
664
+ }
665
+
666
+ [ Test ]
667
+ public async Task TestFetchLazyPreviewTextAsync ( )
668
+ {
669
+ var commands = CreateFetchLazyPreviewTextCommands ( ) ;
670
+
671
+ using ( var client = new ImapClient ( ) ) {
672
+ try {
673
+ await client . ReplayConnectAsync ( "localhost" , new ImapReplayStream ( commands , true ) ) ;
674
+ } catch ( Exception ex ) {
675
+ Assert . Fail ( "Did not expect an exception in Connect: {0}" , ex ) ;
676
+ }
677
+
678
+ // Note: Do not try XOAUTH2
679
+ client . AuthenticationMechanisms . Remove ( "XOAUTH2" ) ;
680
+
681
+ try {
682
+ await client . AuthenticateAsync ( "username" , "password" ) ;
683
+ } catch ( Exception ex ) {
684
+ Assert . Fail ( "Did not expect an exception in Authenticate: {0}" , ex ) ;
685
+ }
686
+
687
+ // disable LIST-EXTENDED
688
+ client . Capabilities &= ~ ImapCapabilities . ListExtended ;
689
+
690
+ var personal = client . GetFolder ( client . PersonalNamespaces [ 0 ] ) ;
691
+ var folders = await personal . GetSubfoldersAsync ( ) ;
692
+ Assert . AreEqual ( client . Inbox , folders [ 0 ] , "Expected the first folder to be the Inbox." ) ;
693
+ Assert . AreEqual ( "[Gmail]" , folders [ 1 ] . FullName , "Expected the second folder to be [Gmail]." ) ;
694
+ Assert . AreEqual ( FolderAttributes . NoSelect | FolderAttributes . HasChildren , folders [ 1 ] . Attributes , "Expected [Gmail] folder to be \\ Noselect \\ HasChildren." ) ;
695
+
696
+ var inbox = client . Inbox ;
697
+
698
+ await inbox . OpenAsync ( FolderAccess . ReadOnly ) ;
699
+
700
+ var request = new FetchRequest ( MessageSummaryItems . All | MessageSummaryItems . PreviewText ) {
701
+ PreviewOptions = PreviewOptions . Lazy
702
+ } ;
703
+
704
+ var messages = await inbox . FetchAsync ( UniqueIdRange . All , request ) ;
705
+ for ( int i = 0 ; i < messages . Count ; i ++ )
706
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
707
+
708
+ messages = await inbox . FetchAsync ( new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } , request ) ;
709
+ for ( int i = 0 ; i < messages . Count ; i ++ )
710
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
711
+
712
+ messages = await inbox . FetchAsync ( 0 , - 1 , request ) ;
713
+ for ( int i = 0 ; i < messages . Count ; i ++ )
714
+ Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
715
+
716
+ await client . DisconnectAsync ( false ) ;
717
+ }
718
+ }
719
+ #endif
720
+
721
+ static readonly string [ ] SimulatedPreviewTextValues = {
469
722
"Planet Fitness https://view.email.planetfitness.com/?qs=9a098a031cabde68c0a4260051cd6fe473a2e997a53678ff26b4b199a711a9d2ad0536530d6f837c246b09f644d42016ecfb298f930b7af058e9e454b34f3d818ceb3052ae317b1ac4594aab28a2d788 View web ver…" ,
470
723
"Don’t miss our celebrity guest Monday evening" ,
471
724
"Planet Fitness https://view.email.planetfitness.com/?qs=9a098a031cabde68c0a4260051cd6fe473a2e997a53678ff26b4b199a711a9d2ad0536530d6f837c246b09f644d42016ecfb298f930b7af058e9e454b34f3d818ceb3052ae317b1ac4594aab28a2d788 View web ver…" ,
@@ -474,7 +727,7 @@ public void TestNotSupportedExceptions ()
474
727
"Planet Fitness https://view.email.planetfitness.com/?qs=9a098a031cabde68c0a4260051cd6fe473a2e997a53678ff26b4b199a711a9d2ad0536530d6f837c246b09f644d42016ecfb298f930b7af058e9e454b34f3d818ceb3052ae317b1ac4594aab28a2d788 View web ver…"
475
728
} ;
476
729
477
- static List < ImapReplayCommand > CreateFetchPreviewTextCommands ( )
730
+ static List < ImapReplayCommand > CreateFetchSimulatedPreviewTextCommands ( )
478
731
{
479
732
return new List < ImapReplayCommand > {
480
733
new ImapReplayCommand ( "" , "gmail.greeting.txt" ) ,
@@ -501,9 +754,9 @@ static List<ImapReplayCommand> CreateFetchPreviewTextCommands ()
501
754
}
502
755
503
756
[ Test ]
504
- public void TestFetchPreviewText ( )
757
+ public void TestFetchSimulatedPreviewText ( )
505
758
{
506
- var commands = CreateFetchPreviewTextCommands ( ) ;
759
+ var commands = CreateFetchSimulatedPreviewTextCommands ( ) ;
507
760
508
761
using ( var client = new ImapClient ( ) ) {
509
762
try {
@@ -536,24 +789,24 @@ public void TestFetchPreviewText ()
536
789
537
790
var messages = inbox . Fetch ( UniqueIdRange . All , MessageSummaryItems . Full | MessageSummaryItems . PreviewText ) ;
538
791
for ( int i = 0 ; i < messages . Count ; i ++ )
539
- Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
792
+ Assert . AreEqual ( SimulatedPreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
540
793
541
794
messages = inbox . Fetch ( new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } , MessageSummaryItems . Full | MessageSummaryItems . PreviewText ) ;
542
795
for ( int i = 0 ; i < messages . Count ; i ++ )
543
- Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
796
+ Assert . AreEqual ( SimulatedPreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
544
797
545
798
messages = inbox . Fetch ( 0 , - 1 , MessageSummaryItems . Full | MessageSummaryItems . PreviewText ) ;
546
799
for ( int i = 0 ; i < messages . Count ; i ++ )
547
- Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
800
+ Assert . AreEqual ( SimulatedPreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
548
801
549
802
client . Disconnect ( false ) ;
550
803
}
551
804
}
552
805
553
806
[ Test ]
554
- public async Task TestFetchPreviewTextAsync ( )
807
+ public async Task TestFetchSimulatedPreviewTextAsync ( )
555
808
{
556
- var commands = CreateFetchPreviewTextCommands ( ) ;
809
+ var commands = CreateFetchSimulatedPreviewTextCommands ( ) ;
557
810
558
811
using ( var client = new ImapClient ( ) ) {
559
812
try {
@@ -586,15 +839,15 @@ public async Task TestFetchPreviewTextAsync ()
586
839
587
840
var messages = await inbox . FetchAsync ( UniqueIdRange . All , MessageSummaryItems . Full | MessageSummaryItems . PreviewText ) ;
588
841
for ( int i = 0 ; i < messages . Count ; i ++ )
589
- Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
842
+ Assert . AreEqual ( SimulatedPreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
590
843
591
844
messages = await inbox . FetchAsync ( new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } , MessageSummaryItems . Full | MessageSummaryItems . PreviewText ) ;
592
845
for ( int i = 0 ; i < messages . Count ; i ++ )
593
- Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
846
+ Assert . AreEqual ( SimulatedPreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
594
847
595
848
messages = await inbox . FetchAsync ( 0 , - 1 , MessageSummaryItems . Full | MessageSummaryItems . PreviewText ) ;
596
849
for ( int i = 0 ; i < messages . Count ; i ++ )
597
- Assert . AreEqual ( PreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
850
+ Assert . AreEqual ( SimulatedPreviewTextValues [ i ] , messages [ i ] . PreviewText ) ;
598
851
599
852
await client . DisconnectAsync ( false ) ;
600
853
}
0 commit comments