@@ -270,54 +270,36 @@ def _connect(self):
270270
271271 def _set_protocol_version (self ):
272272
273- if self ._should_use_rev1_mode_for_dual_support ():
274- self ._activate_rev1_mode ()
273+ if 'IMAP4REV2' in self .capabilities and 'IMAP4REV1' in self .capabilities :
274+ self .PROTOCOL_VERSION = 'IMAP4REV1'
275+ self ._mode_ascii ()
275276 return
276277
277278 for version in AllowedVersions :
278279 if not version in self .capabilities :
279280 continue
280281 if version == 'IMAP4REV2' :
281- self ._activate_rev2_mode ()
282+ self .PROTOCOL_VERSION = 'IMAP4REV2'
283+ self ._mode_utf8 ()
282284 else :
283285 self .PROTOCOL_VERSION = version
284286 return
285287
286288 raise self .error ('server not IMAP4 compliant' )
287289
288- def _supports_rev2 (self ):
289- return 'IMAP4REV2' in self .capabilities
290-
291- def _supports_dual_rev1_rev2 (self ):
292- return self ._supports_rev2 () and 'IMAP4REV1' in self .capabilities
293-
294- def _is_using_rev2 (self ):
295- return self .PROTOCOL_VERSION == 'IMAP4REV2'
296-
297290 def _is_capability_available (self , capability ):
298291 capability = capability .upper ()
299- if self ._is_using_rev2 () and capability in IMAP4REV2_BUILTIN_COMMANDS :
292+ if self .PROTOCOL_VERSION == 'IMAP4REV2' and capability in IMAP4REV2_BUILTIN_COMMANDS :
300293 return True
301294 return capability in self .capabilities
302295
303- def _should_use_rev1_mode_for_dual_support (self ):
304- return self ._supports_dual_rev1_rev2 ()
305-
306- def _activate_rev1_mode (self ):
307- self .PROTOCOL_VERSION = 'IMAP4REV1'
308- self ._mode_ascii ()
309-
310- def _activate_rev2_mode (self ):
311- self .PROTOCOL_VERSION = 'IMAP4REV2'
312- self ._mode_utf8 ()
313-
314296 def _handle_enable_success (self , capability ):
315297 capability = capability .upper ()
316298 if 'UTF8=ACCEPT' in capability :
317299 self ._mode_utf8 ()
318300 if 'IMAP4REV2' in capability :
319- self ._activate_rev2_mode ()
320-
301+ self .PROTOCOL_VERSION = 'IMAP4REV2'
302+ self . _mode_utf8 ()
321303
322304 def __getattr__ (self , attr ):
323305 # Allow UPPERCASE variants of IMAP4 command methods.
@@ -888,7 +870,7 @@ def search(self, charset, *criteria):
888870 """
889871 name = 'SEARCH'
890872 if charset :
891- if self .utf8_enabled and not self ._is_using_rev2 () :
873+ if self .utf8_enabled and not self .PROTOCOL_VERSION == 'IMAP4REV2' :
892874 raise IMAP4 .error ("Non-None charset not valid in UTF8 mode" )
893875 typ , dat = self ._simple_command (name , 'CHARSET' , charset , * criteria )
894876 else :
0 commit comments