1919CRLF = '\r \n '
2020Debug = 0
2121IMAP4_PORT = 143
22+ AllowedVersions = ('IMAP4REV1' , 'IMAP4' ) # Most recent first
2223
2324# Commands
2425
@@ -133,12 +134,19 @@ def __init__(self, host = '', port = IMAP4_PORT):
133134 if not self .untagged_responses .has_key (cap ):
134135 raise self .error ('no CAPABILITY response from server' )
135136 self .capabilities = tuple (string .split (self .untagged_responses [cap ][- 1 ]))
136- if not 'IMAP4REV1' in self .capabilities :
137- raise self .error ('server not IMAP4REV1 compliant' )
138137
139138 if __debug__ and self .debug >= 3 :
140139 print '\t CAPABILITIES: %s' % `self.capabilities`
141140
141+ self .PROTOCOL_VERSION = None
142+ for version in AllowedVersions :
143+ if not version in self .capabilities :
144+ continue
145+ self .PROTOCOL_VERSION = version
146+ break
147+ if not self .PROTOCOL_VERSION :
148+ raise self .error ('server not IMAP4 compliant' )
149+
142150
143151 def __getattr__ (self , attr ):
144152 """Allow UPPERCASE variants of all following IMAP4 commands."""
@@ -267,7 +275,7 @@ def login(self, user, password):
267275
268276 (typ, [data]) = <instance>.list(user, password)
269277 """
270- if not 'AUTH= LOGIN' in self .capabilities :
278+ if not 'AUTH- LOGIN' in self .capabilities :
271279 raise self .error ("server doesn't allow LOGIN authorisation" )
272280 typ , dat = self ._simple_command ('LOGIN' , user , password )
273281 if typ != 'OK' :
@@ -406,7 +414,8 @@ def subscribe(self, mailbox):
406414
407415
408416 def uid (self , command , args ):
409- """Execute "command args" with messages identified by UID, rather than message number.
417+ """Execute "command args" with messages identified by UID,
418+ rather than message number.
410419
411420 (typ, [data]) = <instance>.uid(command, args)
412421
@@ -432,7 +441,8 @@ def unsubscribe(self, mailbox):
432441
433442
434443 def xatom (self , name , arg1 = None , arg2 = None ):
435- """Allow simple extension commands notified by server in CAPABILITY response.
444+ """Allow simple extension commands
445+ notified by server in CAPABILITY response.
436446
437447 (typ, [data]) = <instance>.xatom(name, arg1=None, arg2=None)
438448 """
@@ -773,18 +783,22 @@ def run(cmd, args):
773783 return dat
774784
775785 Debug = 4
776- M = IMAP4 ()
786+ M = IMAP4 ("newcnri" )
787+ print 'PROTOCOL_VERSION = %s' % M .PROTOCOL_VERSION
777788
778789 for cmd ,args in test_seq1 :
779790 run (cmd , args )
780791
781- for ml in M . list ('/tmp/' , 'yy%' )[ 1 ] :
792+ for ml in run ( ' list' , ('/tmp/' , 'yy%' )) :
782793 path = string .split (ml )[- 1 ]
783- print '%s %s' % M . delete (path )
794+ run ( 'delete' , (path ,) )
784795
785796 for cmd ,args in test_seq2 :
786797 dat = run (cmd , args )
787798
788- if (cmd ,args ) == ('uid' , ('SEARCH' , 'ALL' )):
789- uid = string .split (dat [0 ])[- 1 ]
790- run ('uid' , ('FETCH' , '%s (FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822)' % uid ))
799+ if (cmd ,args ) != ('uid' , ('SEARCH' , 'ALL' )):
800+ continue
801+
802+ uid = string .split (dat [0 ])[- 1 ]
803+ run ('uid' , ('FETCH' ,
804+ '%s (FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822)' % uid ))
0 commit comments