]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Added SSL support
authorMenno Smits <menno@freshfoo.com>
Thu, 26 Mar 2009 18:59:13 +0000 (18:59 +0000)
committerMenno Smits <menno@freshfoo.com>
Thu, 26 Mar 2009 18:59:13 +0000 (18:59 +0000)
TODO
imapclient/imapclient.py
livetest.py

diff --git a/TODO b/TODO
index c2370ad7bb968623feeda88d509b9563af785e39..ed52d98aefa036752b9b0aff6244cd19dbda8fa6 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,13 +1,13 @@
+- transparent "&" escaping
 - automatic changelog generation
 - support for more IMAP functions: sort, examine etc
+    - someone sent a patch for this?
 - write a comparision of imaplib vs imapclient.py
        (presentation is a good start)
 - abstract out UID handling if possible
 - higher level fetch methods for common attributes, flattened
 - handling read-only access
-- transparent "&" escaping
 - more unit tests using mocking
-- SSL support
 - allow per-call uid overrides
 - more docs
 - better namespace support
index b16d646654bc282ea2eb75e177e39357e6aaa42e..c314a390aadde3030ebc2e9240897af702e5c72b 100644 (file)
@@ -67,14 +67,25 @@ class IMAPClient:
     re_status = re.compile(r'^\s*"(?P<folder>[^"]+)"\s+'
                            r'\((?P<status_items>.*)\)$')
 
-    def __init__(self, host, port=143, use_uid=True):
+    def __init__(self, host, port=None, use_uid=True, ssl=False):
         '''Initialise object instance and connect to the remote IMAP server.
 
         @param host: The IMAP server address/hostname to connect to.
-        @param port: The port number to use (default is 143).
+        @param port: The port number to use (default is 143, 993 for SSL).
         @param use_uid: Should message UIDs be used (default is True).
+        @param ssl: Make an SSL connection (default is False)
         '''
-        self._imap = imaplib.IMAP4(host, port)
+        if ssl:
+            ImapClass = imaplib.IMAP4_SSL
+            default_port = 993
+        else:
+            ImapClass = imaplib.IMAP4
+            default_port = 143
+
+        if port is None:
+            port = default_port
+
+        self._imap = ImapClass(host, port)
         self.use_uid = use_uid
 
     def login(self, username, password):
index 88905468f9b1ef67561dc6e79dac6033daf239ef..8a524fdb4a2791d7cfde74c4b7443e67386df69e 100644 (file)
@@ -235,16 +235,18 @@ def clear_folder(server, folder):
 def command_line():
     p = OptionParser()
     p.add_option('-H', '--host', dest='host', action='store',
-            help='IMAP host connect to')
+                 help='IMAP host connect to')
     p.add_option('-P', '--port', dest='port', action='store',
-            default=143, help='IMAP port to use (default is 143)')
+                 default=143, help='IMAP port to use (default is 143)')
+    p.add_option('-s', '--ssl', dest='ssl', action='store_true', default=False,
+                 help='Use SSL connection')
     p.add_option('-u', '--username', dest='username', action='store',
-            help='Username to login with')
+                 help='Username to login with')
     p.add_option('-p', '--password', dest='password', action='store',
-            help='Password to login with')
+                 help='Password to login with')
     p.add_option('', '--clobber', dest='clobber', action='store_true',
-            default=False, help='These tests are destructive. Use this '
-            'option to bypass the confirmation prompt.')
+                 default=False, help='These tests are destructive. Use this '
+                 'option to bypass the confirmation prompt.')
 
     options, args = p.parse_args()
 
@@ -257,6 +259,7 @@ def command_line():
 
     return options
 
+
 def user_confirm():
     print """\
 WARNING: These tests are destructive.
@@ -276,9 +279,9 @@ def main():
     # Test with use_uid on and off
     for use_uid in (True, False):
         print '-'*60
-        print "Testing with use_uid=%r..." % use_uid
+        print "Testing with use_uid=%r, ssl=%r..." % (use_uid, options.ssl)
         print '-'*60
-        server = imapclient.IMAPClient(options.host, use_uid=use_uid)
+        server = imapclient.IMAPClient(options.host, use_uid=use_uid, ssl=options.ssl)
         server.login(options.username, options.password)
         runtests(server)
         print 'SUCCESS'