@@ -65,7 +65,6 @@ class Pop3Engine
6565#endif
6666 readonly List < Pop3Command > queue ;
6767 long clientConnectedTimestamp ;
68- Pop3Stream ? stream ;
6968 bool secure ;
7069
7170 /// <summary>
@@ -126,7 +125,7 @@ public Pop3Capabilities Capabilities {
126125 /// </remarks>
127126 /// <value>The pop3 stream.</value>
128127 public Pop3Stream ? Stream {
129- get { return stream ; }
128+ get ; private set ;
130129 }
131130
132131 /// <summary>
@@ -149,7 +148,7 @@ public Pop3EngineState State {
149148 /// <value><see langword="true" /> if the engine is connected; otherwise, <see langword="false" />.</value>
150149 [ MemberNotNullWhen ( true , new [ ] { nameof ( Stream ) , nameof ( Uri ) } ) ]
151150 public bool IsConnected {
152- get { return stream != null && stream . IsConnected ; }
151+ get { return Stream != null && Stream . IsConnected ; }
153152 }
154153
155154 /// <summary>
@@ -209,16 +208,17 @@ public int LoginDelay {
209208 get ; private set ;
210209 }
211210
211+ [ MemberNotNull ( nameof ( Stream ) ) ]
212212 void CheckConnected ( )
213213 {
214- if ( stream == null )
214+ if ( Stream == null )
215215 throw new InvalidOperationException ( ) ;
216216 }
217217
218- [ MemberNotNull ( nameof ( stream ) ) ]
218+ [ MemberNotNull ( nameof ( Stream ) ) ]
219219 void Initialize ( Pop3Stream pop3 )
220220 {
221- stream ? . Dispose ( ) ;
221+ Stream ? . Dispose ( ) ;
222222
223223 clientConnectedTimestamp = Stopwatch . GetTimestamp ( ) ;
224224 Capabilities = Pop3Capabilities . User ;
@@ -227,7 +227,7 @@ void Initialize (Pop3Stream pop3)
227227 ApopToken = null ;
228228
229229 secure = pop3 . Stream is SslStream ;
230- stream = pop3 ;
230+ Stream = pop3 ;
231231 }
232232
233233 void ParseGreeting ( string greeting )
@@ -251,8 +251,8 @@ void ParseGreeting (string greeting)
251251 }
252252
253253 if ( token != "+OK" ) {
254- stream ! . Dispose ( ) ;
255- stream = null ;
254+ Stream ! . Dispose ( ) ;
255+ Stream = null ;
256256
257257 throw new Pop3ProtocolException ( string . Format ( "Unexpected greeting from server: {0}" , greeting ) ) ;
258258 }
@@ -341,9 +341,9 @@ public void Disconnect (Exception? ex)
341341 {
342342 RecordClientDisconnected ( ex ) ;
343343
344- if ( stream != null ) {
345- stream . Dispose ( ) ;
346- stream = null ;
344+ if ( Stream != null ) {
345+ Stream . Dispose ( ) ;
346+ Stream = null ;
347347 }
348348
349349 secure = false ;
@@ -376,7 +376,7 @@ public string ReadLine (CancellationToken cancellationToken)
376376 bool complete ;
377377
378378 do {
379- complete = stream ! . ReadLine ( builder , cancellationToken ) ;
379+ complete = Stream . ReadLine ( builder , cancellationToken ) ;
380380 } while ( ! complete ) ;
381381
382382 // FIXME: All callers expect CRLF to be trimmed, but many also want all trailing whitespace trimmed.
@@ -408,7 +408,7 @@ public async Task<string> ReadLineAsync (CancellationToken cancellationToken)
408408 bool complete ;
409409
410410 do {
411- complete = await stream ! . ReadLineAsync ( builder , cancellationToken ) . ConfigureAwait ( false ) ;
411+ complete = await Stream . ReadLineAsync ( builder , cancellationToken ) . ConfigureAwait ( false ) ;
412412 } while ( ! complete ) ;
413413
414414 // FIXME: All callers expect CRLF to be trimmed, but many also want all trailing whitespace trimmed.
@@ -520,6 +520,7 @@ async Task ReadResponseAsync (Pop3Command pc, CancellationToken cancellationToke
520520 }
521521 }
522522
523+ [ MemberNotNull ( nameof ( Stream ) ) ]
523524 void CheckCanRun ( CancellationToken cancellationToken )
524525 {
525526 CheckConnected ( ) ;
@@ -548,10 +549,10 @@ public void Run (bool throwOnError, CancellationToken cancellationToken)
548549
549550 pc . Status = Pop3CommandStatus . Active ;
550551
551- stream ! . QueueCommand ( pc . Encoding , pc . Command , cancellationToken ) ;
552+ Stream . QueueCommand ( pc . Encoding , pc . Command , cancellationToken ) ;
552553 }
553554
554- stream ! . Flush ( cancellationToken ) ;
555+ Stream . Flush ( cancellationToken ) ;
555556
556557 for ( int i = 0 ; i < queue . Count ; i ++ )
557558 ReadResponse ( queue [ i ] , cancellationToken ) ;
@@ -581,10 +582,10 @@ public async Task RunAsync (bool throwOnError, CancellationToken cancellationTok
581582
582583 pc . Status = Pop3CommandStatus . Active ;
583584
584- await stream ! . QueueCommandAsync ( pc . Encoding , pc . Command , cancellationToken ) . ConfigureAwait ( false ) ;
585+ await Stream . QueueCommandAsync ( pc . Encoding , pc . Command , cancellationToken ) . ConfigureAwait ( false ) ;
585586 }
586587
587- await stream ! . FlushAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
588+ await Stream . FlushAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
588589
589590 for ( int i = 0 ; i < queue . Count ; i ++ )
590591 await ReadResponseAsync ( queue [ i ] , cancellationToken ) . ConfigureAwait ( false ) ;
0 commit comments