@@ -74,7 +74,6 @@ public partial class ImapClient : MailStore, IImapClient
7474 bool disconnecting ;
7575 bool connecting ;
7676 bool disposed ;
77- bool secure ;
7877
7978 /// <summary>
8079 /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapClient"/> class.
@@ -666,7 +665,7 @@ public override HashSet<ThreadingAlgorithm> ThreadingAlgorithms {
666665 public override int Timeout {
667666 get { return timeout ; }
668667 set {
669- if ( IsConnected && engine . Stream ! . CanTimeout ) {
668+ if ( engine . IsConnected && engine . Stream . CanTimeout ) {
670669 engine . Stream . WriteTimeout = value ;
671670 engine . Stream . ReadTimeout = value ;
672671 }
@@ -701,7 +700,7 @@ public override bool IsConnected {
701700 /// </remarks>
702701 /// <value><see langword="true" /> if the connection is secure; otherwise, <see langword="false" />.</value>
703702 public override bool IsSecure {
704- get { return IsConnected && secure ; }
703+ get { return engine . IsSecure ; }
705704 }
706705
707706 /// <summary>
@@ -712,7 +711,7 @@ public override bool IsSecure {
712711 /// </remarks>
713712 /// <value><see langword="true" /> if the connection is encrypted; otherwise, <see langword="false" />.</value>
714713 public override bool IsEncrypted {
715- get { return IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) && sslStream . IsEncrypted ; }
714+ get { return engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) && sslStream . IsEncrypted ; }
716715 }
717716
718717 /// <summary>
@@ -723,7 +722,7 @@ public override bool IsEncrypted {
723722 /// </remarks>
724723 /// <value><see langword="true" /> if the connection is signed; otherwise, <see langword="false" />.</value>
725724 public override bool IsSigned {
726- get { return IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) && sslStream . IsSigned ; }
725+ get { return engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) && sslStream . IsSigned ; }
727726 }
728727
729728 /// <summary>
@@ -738,7 +737,7 @@ public override bool IsSigned {
738737 /// <value>The negotiated SSL or TLS protocol version.</value>
739738 public override SslProtocols SslProtocol {
740739 get {
741- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
740+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
742741 return sslStream . SslProtocol ;
743742
744743 return SslProtocols . None ;
@@ -760,7 +759,7 @@ public override SslProtocols SslProtocol {
760759#endif
761760 public override CipherAlgorithmType ? SslCipherAlgorithm {
762761 get {
763- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
762+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
764763 return sslStream . CipherAlgorithm ;
765764
766765 return null ;
@@ -782,7 +781,7 @@ public override CipherAlgorithmType? SslCipherAlgorithm {
782781#endif
783782 public override int ? SslCipherStrength {
784783 get {
785- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
784+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
786785 return sslStream . CipherStrength ;
787786
788787 return null ;
@@ -799,7 +798,7 @@ public override int? SslCipherStrength {
799798 /// <value>The negotiated SSL or TLS cipher suite.</value>
800799 public override TlsCipherSuite ? SslCipherSuite {
801800 get {
802- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
801+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
803802 return sslStream . NegotiatedCipherSuite ;
804803
805804 return null ;
@@ -822,7 +821,7 @@ public override TlsCipherSuite? SslCipherSuite {
822821#endif
823822 public override HashAlgorithmType ? SslHashAlgorithm {
824823 get {
825- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
824+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
826825 return sslStream . HashAlgorithm ;
827826
828827 return null ;
@@ -844,7 +843,7 @@ public override HashAlgorithmType? SslHashAlgorithm {
844843#endif
845844 public override int ? SslHashStrength {
846845 get {
847- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
846+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
848847 return sslStream . HashStrength ;
849848
850849 return null ;
@@ -866,7 +865,7 @@ public override int? SslHashStrength {
866865#endif
867866 public override ExchangeAlgorithmType ? SslKeyExchangeAlgorithm {
868867 get {
869- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
868+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
870869 return sslStream . KeyExchangeAlgorithm ;
871870
872871 return null ;
@@ -888,7 +887,7 @@ public override ExchangeAlgorithmType? SslKeyExchangeAlgorithm {
888887#endif
889888 public override int ? SslKeyExchangeStrength {
890889 get {
891- if ( IsSecure && ( engine . Stream ! . Stream is SslStream sslStream ) )
890+ if ( engine . IsSecure && ( engine . Stream . Stream is SslStream sslStream ) )
892891 return sslStream . KeyExchangeStrength ;
893892
894893 return null ;
@@ -1460,17 +1459,17 @@ void PostConnect (Stream stream, string host, int port, SecureSocketOptions opti
14601459 ProtocolLogger . LogConnect ( engine . Uri ! ) ;
14611460 } catch {
14621461 stream . Dispose ( ) ;
1463- secure = false ;
14641462 throw ;
14651463 }
14661464
14671465 connecting = true ;
14681466
1467+ var imap = new ImapStream ( stream , ProtocolLogger ) ;
1468+
14691469 try {
1470- engine . Connect ( new ImapStream ( stream , ProtocolLogger ) , cancellationToken ) ;
1470+ engine . Connect ( imap , cancellationToken ) ;
14711471 } catch {
14721472 connecting = false ;
1473- secure = false ;
14741473 throw ;
14751474 }
14761475
@@ -1490,14 +1489,14 @@ void PostConnect (Stream stream, string host, int port, SecureSocketOptions opti
14901489 if ( ic . Response == ImapCommandResponse . Ok ) {
14911490 try {
14921491 var tls = new SslStream ( stream , false , ValidateRemoteCertificate ) ;
1493- engine . Stream ! . Stream = tls ;
1492+ imap . Stream = tls ;
14941493
14951494 SslHandshake ( tls , host , cancellationToken ) ;
14961495 } catch ( Exception ex ) {
14971496 throw SslHandshakeException . Create ( ref sslValidationInfo , ex , true , "IMAP" , host , port , 993 , 143 ) ;
14981497 }
14991498
1500- secure = true ;
1499+ engine . IsSecure = true ;
15011500
15021501 // Query the CAPABILITIES again if the server did not include an
15031502 // untagged CAPABILITIES response to the STARTTLS command.
@@ -1508,7 +1507,6 @@ void PostConnect (Stream stream, string host, int port, SecureSocketOptions opti
15081507 }
15091508 }
15101509 } catch ( Exception ex ) {
1511- secure = false ;
15121510 engine . Disconnect ( ex ) ;
15131511 throw ;
15141512 } finally {
@@ -1611,10 +1609,7 @@ public override void Connect (string host, int port = 0, SecureSocketOptions opt
16111609 throw SslHandshakeException . Create ( ref sslValidationInfo , ex , false , "IMAP" , host , port , 993 , 143 ) ;
16121610 }
16131611
1614- secure = true ;
16151612 stream = ssl ;
1616- } else {
1617- secure = false ;
16181613 }
16191614
16201615 PostConnect ( stream , host , port , options , starttls , cancellationToken ) ;
@@ -1795,10 +1790,8 @@ public override void Connect (Stream stream, string host, int port = 0, SecureSo
17951790 }
17961791
17971792 network = ssl ;
1798- secure = true ;
17991793 } else {
18001794 network = stream ;
1801- secure = false ;
18021795 }
18031796
18041797 if ( network . CanTimeout ) {
@@ -2810,7 +2803,6 @@ void OnEngineDisconnected (object? sender, EventArgs e)
28102803 var uri = engine . Uri ;
28112804
28122805 disconnecting = false ;
2813- secure = false ;
28142806
28152807 OnDisconnected ( uri ! . Host , uri . Port , GetSecureSocketOptions ( uri ) , requested ) ;
28162808 }
0 commit comments