@@ -139,7 +139,7 @@ fn validate_sequence_set(
139
139
pub struct Session < T : Read + Write > {
140
140
conn : Connection < T > ,
141
141
142
- // Capabilities are almost guaranteed to chance if encryption state or authentication state
142
+ // Capabilities are almost guaranteed to change if encryption state or authentication state
143
143
// changes, so caching them in `Connection` is inappropiate.
144
144
capability_cache : Option < Capabilities > ,
145
145
@@ -159,7 +159,7 @@ pub struct Session<T: Read + Write> {
159
159
pub struct Client < T : Read + Write > {
160
160
conn : Connection < T > ,
161
161
162
- // Capabilities are almost guaranteed to chance if encryption state or authentication state
162
+ // Capabilities are almost guaranteed to change if encryption state or authentication state
163
163
// changes, so caching them in `Connection` is inappropiate.
164
164
capability_cache : Option < Capabilities > ,
165
165
}
@@ -362,16 +362,16 @@ impl<T: Read + Write> Client<T> {
362
362
/// This method will always bypass the local capabilities cache and send a `CAPABILITY` command
363
363
/// to the server. The [`Self::capabilities()`] method can be used when returning a cached
364
364
/// response is acceptable.
365
- pub fn capabilities_refresh ( & mut self ) -> Result < & Capabilities > {
365
+ pub fn current_capabilities ( & mut self ) -> Result < & Capabilities > {
366
366
let ( mut tx, _rx) = mpsc:: channel ( ) ;
367
367
let caps = self . run_command_and_read_response ( "CAPABILITY" )
368
368
. and_then ( |lines| Capabilities :: parse ( lines, & mut tx) ) ?;
369
369
self . capability_cache = Some ( caps) ;
370
370
371
- self . capability_cache . as_ref ( )
371
+ Ok ( self . capability_cache . as_ref ( )
372
372
// This path will not be hit; if the cache is not populated the above calls will either
373
373
// populate it or return with an early error.
374
- . ok_or_else ( || panic ! ( "CAPABILITY call did not populate capability cache!" ) )
374
+ . expect ( "CAPABILITY call did not populate capability cache!" ) )
375
375
}
376
376
377
377
/// The [`CAPABILITY` command](https://tools.ietf.org/html/rfc3501#section-6.1.1) requests a
@@ -381,7 +381,7 @@ impl<T: Read + Write> Client<T> {
381
381
/// This function will not query the server if a set of capabilities was cached, but request
382
382
/// and cache capabilities from the server otherwise. The [`Self::capabilities_refresh`] method
383
383
/// can be used to refresh the cache by forcing a `CAPABILITY` command to be send.
384
- pub fn capabilities_ref ( & mut self ) -> Result < & Capabilities > {
384
+ pub fn capabilities ( & mut self ) -> Result < & Capabilities > {
385
385
let ( mut tx, _rx) = mpsc:: channel ( ) ;
386
386
if self . capability_cache . is_none ( ) {
387
387
let caps = self . run_command_and_read_response ( "CAPABILITY" )
@@ -390,10 +390,10 @@ impl<T: Read + Write> Client<T> {
390
390
self . capability_cache = Some ( caps) ;
391
391
}
392
392
393
- self . capability_cache . as_ref ( )
393
+ Ok ( self . capability_cache . as_ref ( )
394
394
// This path will not be hit; if the cache is not populated the above `if` will either
395
395
// populate it or return with an early error.
396
- . ok_or_else ( || panic ! ( "CAPABILITY call did not populate capability cache!" ) )
396
+ . expect ( "CAPABILITY call did not populate capability cache!" ) )
397
397
}
398
398
399
399
/// Log in to the IMAP server. Upon success a [`Session`](struct.Session.html) instance is
@@ -830,7 +830,7 @@ impl<T: Read + Write> Session<T> {
830
830
/// This method will always bypass the local capabilities cache and send a `CAPABILITY` command
831
831
/// to the server. The [`Self::capabilities()`] method can be used when returning a cached
832
832
/// response is acceptable.
833
- pub fn capabilities_refresh ( & mut self ) -> Result < & Capabilities > {
833
+ pub fn current_capabilities ( & mut self ) -> Result < & Capabilities > {
834
834
let caps = self . run_command_and_read_response ( "CAPABILITY" )
835
835
. and_then ( |lines| Capabilities :: parse ( lines, & mut self . unsolicited_responses_tx ) ) ?;
836
836
self . capability_cache = Some ( caps) ;
@@ -848,7 +848,7 @@ impl<T: Read + Write> Session<T> {
848
848
/// This function will not query the server if a set of capabilities was cached, but request
849
849
/// and cache capabilities from the server otherwise. The [`Self::capabilities_refresh`] method
850
850
/// can be used to refresh the cache by forcing a `CAPABILITY` command to be send.
851
- pub fn capabilities_ref ( & mut self ) -> Result < & Capabilities > {
851
+ pub fn capabilities ( & mut self ) -> Result < & Capabilities > {
852
852
if self . capability_cache . is_none ( ) {
853
853
let caps = self . run_command_and_read_response ( "CAPABILITY" )
854
854
. and_then ( |lines| Capabilities :: parse ( lines, & mut self . unsolicited_responses_tx ) ) ?;
@@ -862,15 +862,6 @@ impl<T: Read + Write> Session<T> {
862
862
. ok_or_else ( || panic ! ( "CAPABILITY call did not populate capability cache!" ) )
863
863
}
864
864
865
- /// The [`CAPABILITY` command](https://tools.ietf.org/html/rfc3501#section-6.1.1) requests a
866
- /// listing of capabilities that the server supports. The server will include "IMAP4rev1" as
867
- /// one of the listed capabilities. See [`Capabilities`] for further details.
868
- pub fn capabilities ( & mut self ) -> Result < Capabilities > {
869
- // TODO: This emulated the same behaviour as before, with each call issuing a command.
870
- // It may be sensible to allow hitting the cache here.
871
- self . capabilities_refresh ( ) . map ( |caps| caps. clone ( ) )
872
- }
873
-
874
865
/// The [`EXPUNGE` command](https://tools.ietf.org/html/rfc3501#section-6.4.3) permanently
875
866
/// removes all messages that have [`Flag::Deleted`] set from the currently selected mailbox.
876
867
/// The message sequence number of each message that is removed is returned.
@@ -2826,7 +2817,7 @@ a1 OK completed\r
2826
2817
] ;
2827
2818
let mock_stream = MockStream :: new ( response) ;
2828
2819
let mut session = mock_session ! ( mock_stream) ;
2829
- let capabilities = session. capabilities ( ) . unwrap ( ) ;
2820
+ let capabilities = session. capabilities ( ) . cloned ( ) . unwrap ( ) ;
2830
2821
assert ! (
2831
2822
session. stream. get_ref( ) . written_buf == b"a1 CAPABILITY\r \n " . to_vec( ) ,
2832
2823
"Invalid capability command"
0 commit comments