@@ -680,11 +680,13 @@ Pop3Engine Engine {
680680
681681 void OnDataReceived ( Pop3Engine pop3 , Pop3Command pc , string text , CancellationToken cancellationToken )
682682 {
683+ pop3 . CheckConnected ( ) ;
684+
683685 while ( pc . Status == Pop3CommandStatus . Continue && ! mechanism . IsAuthenticated ) {
684686 var challenge = mechanism . Challenge ( text , cancellationToken ) ;
685687 var buf = Encoding . ASCII . GetBytes ( challenge + "\r \n " ) ;
686688
687- pop3 . Stream ! . Write ( buf , 0 , buf . Length , cancellationToken ) ;
689+ pop3 . Stream . Write ( buf , 0 , buf . Length , cancellationToken ) ;
688690 pop3 . Stream . Flush ( cancellationToken ) ;
689691
690692 var response = pop3 . ReadLine ( cancellationToken ) . TrimEnd ( ) ;
@@ -700,11 +702,13 @@ void OnDataReceived (Pop3Engine pop3, Pop3Command pc, string text, CancellationT
700702
701703 async Task OnDataReceivedAsync ( Pop3Engine pop3 , Pop3Command pc , string text , CancellationToken cancellationToken )
702704 {
705+ pop3 . CheckConnected ( ) ;
706+
703707 while ( pc . Status == Pop3CommandStatus . Continue && ! mechanism . IsAuthenticated ) {
704708 var challenge = await mechanism . ChallengeAsync ( text , cancellationToken ) . ConfigureAwait ( false ) ;
705709 var buf = Encoding . ASCII . GetBytes ( challenge + "\r \n " ) ;
706710
707- await pop3 . Stream ! . WriteAsync ( buf , 0 , buf . Length , cancellationToken ) . ConfigureAwait ( false ) ;
711+ await pop3 . Stream . WriteAsync ( buf , 0 , buf . Length , cancellationToken ) . ConfigureAwait ( false ) ;
708712 await pop3 . Stream . FlushAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
709713
710714 var response = ( await pop3 . ReadLineAsync ( cancellationToken ) . ConfigureAwait ( false ) ) . TrimEnd ( ) ;
@@ -764,12 +768,12 @@ public async Task<Pop3Command> AuthenticateAsync (CancellationToken cancellation
764768 }
765769 }
766770
767- void CheckCanAuthenticate ( SaslMechanism mechanism , CancellationToken cancellationToken )
771+ Uri CheckCanAuthenticate ( SaslMechanism mechanism , CancellationToken cancellationToken )
768772 {
769773 if ( mechanism == null )
770774 throw new ArgumentNullException ( nameof ( mechanism ) ) ;
771775
772- if ( ! IsConnected )
776+ if ( ! engine . IsConnected )
773777 throw new ServiceNotConnectedException ( "The Pop3Client must be connected before you can authenticate." ) ;
774778
775779 if ( IsAuthenticated )
@@ -778,6 +782,8 @@ void CheckCanAuthenticate (SaslMechanism mechanism, CancellationToken cancellati
778782 CheckDisposed ( ) ;
779783
780784 cancellationToken . ThrowIfCancellationRequested ( ) ;
785+
786+ return new Uri ( "pop://" + engine . Uri . Host ) ;
781787 }
782788
783789 SaslAuthContext GetSaslAuthContext ( SaslMechanism mechanism , Uri saslUri )
@@ -841,12 +847,11 @@ void OnAuthenticated (string message, CancellationToken cancellationToken)
841847 /// </exception>
842848 public override void Authenticate ( SaslMechanism mechanism , CancellationToken cancellationToken = default )
843849 {
844- CheckCanAuthenticate ( mechanism , cancellationToken ) ;
850+ var saslUri = CheckCanAuthenticate ( mechanism , cancellationToken ) ;
845851
846852 using var operation = engine . StartNetworkOperation ( NetworkOperationKind . Authenticate ) ;
847853
848854 try {
849- var saslUri = new Uri ( "pop://" + engine . Uri ! . Host ) ;
850855 var ctx = GetSaslAuthContext ( mechanism , saslUri ) ;
851856
852857 var pc = ctx . Authenticate ( cancellationToken ) ;
@@ -863,21 +868,25 @@ public override void Authenticate (SaslMechanism mechanism, CancellationToken ca
863868 }
864869 }
865870
866- void CheckCanAuthenticate ( Encoding encoding , ICredentials credentials , CancellationToken cancellationToken )
871+ Uri CheckCanAuthenticate ( Encoding encoding , ICredentials credentials , CancellationToken cancellationToken )
867872 {
868873 if ( encoding == null )
869874 throw new ArgumentNullException ( nameof ( encoding ) ) ;
870875
871876 if ( credentials == null )
872877 throw new ArgumentNullException ( nameof ( credentials ) ) ;
873878
874- if ( ! IsConnected )
879+ if ( ! engine . IsConnected )
875880 throw new ServiceNotConnectedException ( "The Pop3Client must be connected before you can authenticate." ) ;
876881
877882 if ( IsAuthenticated )
878883 throw new InvalidOperationException ( "The Pop3Client is already authenticated." ) ;
879884
880885 CheckDisposed ( ) ;
886+
887+ cancellationToken . ThrowIfCancellationRequested ( ) ;
888+
889+ return new Uri ( "pop://" + engine . Uri . Host ) ;
881890 }
882891
883892 string GetApopCommand ( Encoding encoding , NetworkCredential cred )
@@ -956,12 +965,11 @@ string GetApopCommand (Encoding encoding, NetworkCredential cred)
956965 /// </exception>
957966 public override void Authenticate ( Encoding encoding , ICredentials credentials , CancellationToken cancellationToken = default )
958967 {
959- CheckCanAuthenticate ( encoding , credentials , cancellationToken ) ;
968+ var saslUri = CheckCanAuthenticate ( encoding , credentials , cancellationToken ) ;
960969
961970 using var operation = engine . StartNetworkOperation ( NetworkOperationKind . Authenticate ) ;
962971
963972 try {
964- var saslUri = new Uri ( "pop://" + engine . Uri ! . Host ) ;
965973 string userName , password ;
966974 NetworkCredential ? cred ;
967975 string ? message = null ;
@@ -2264,35 +2272,39 @@ protected void Update (int n)
22642272
22652273 void OnDataReceived ( Pop3Engine engine , Pop3Command pc , CancellationToken cancellationToken )
22662274 {
2275+ engine . CheckConnected ( ) ;
2276+
22672277 try {
2268- engine . Stream ! . Mode = Pop3StreamMode . Data ;
2278+ engine . Stream . Mode = Pop3StreamMode . Data ;
22692279
22702280 var item = Parse ( engine . Stream , cancellationToken ) ;
22712281
22722282 downloaded ! [ idx ++ ] = item ;
22732283 } catch ( FormatException ex ) {
22742284 pc . Exception = CreatePop3ParseException ( ex , "Failed to parse data." ) ;
22752285
2276- engine . Stream ! . CopyTo ( Stream . Null , 4096 ) ;
2286+ engine . Stream . CopyTo ( Stream . Null , 4096 ) ;
22772287 } finally {
2278- engine . Stream ! . Mode = Pop3StreamMode . Line ;
2288+ engine . Stream . Mode = Pop3StreamMode . Line ;
22792289 }
22802290 }
22812291
22822292 async Task OnDataReceivedAsync ( Pop3Engine engine , Pop3Command pc , CancellationToken cancellationToken )
22832293 {
2294+ engine . CheckConnected ( ) ;
2295+
22842296 try {
2285- engine . Stream ! . Mode = Pop3StreamMode . Data ;
2297+ engine . Stream . Mode = Pop3StreamMode . Data ;
22862298
22872299 var item = await ParseAsync ( engine . Stream , cancellationToken ) . ConfigureAwait ( false ) ;
22882300
22892301 downloaded ! [ idx ++ ] = item ;
22902302 } catch ( FormatException ex ) {
22912303 pc . Exception = CreatePop3ParseException ( ex , "Failed to parse data." ) ;
22922304
2293- await engine . Stream ! . CopyToAsync ( Stream . Null , 4096 , cancellationToken ) . ConfigureAwait ( false ) ;
2305+ await engine . Stream . CopyToAsync ( Stream . Null , 4096 , cancellationToken ) . ConfigureAwait ( false ) ;
22942306 } finally {
2295- engine . Stream ! . Mode = Pop3StreamMode . Line ;
2307+ engine . Stream . Mode = Pop3StreamMode . Line ;
22962308 }
22972309 }
22982310
0 commit comments