From 402a594877d5c426810f722ca4fb9d096711148d Mon Sep 17 00:00:00 2001 From: SpotlightKid Date: Fri, 22 Aug 2014 18:34:25 +0200 Subject: [PATCH] Pass additional kwargs from `IMAPClient` init method to `_create_IMAP4` method and from there to `imaplib.IMAP4` or imaplib.IMAP4_SSL` constructor to allow usage of SSL context and/or key and certificate file. --- imapclient/imapclient.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 1000f83..5aef0f6 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -101,7 +101,8 @@ class IMAPClient(object): AbortError = imaplib.IMAP4.abort ReadOnlyError = imaplib.IMAP4.readonly - def __init__(self, host, port=None, use_uid=True, ssl=False, stream=False): + def __init__(self, host, port=None, use_uid=True, ssl=False, stream=False, + **kwargs): if stream: if port is not None: raise ValueError("can't set 'port' when 'stream' True") @@ -120,16 +121,16 @@ class IMAPClient(object): self.normalise_times = True self._cached_capabilities = None - self._imap = self._create_IMAP4() + self._imap = self._create_IMAP4(**kwargs) self._imap._mesg = self._log # patch in custom debug log method self._idle_tag = None - def _create_IMAP4(self): + def _create_IMAP4(self, **kwargs): # Create the IMAP instance in a separate method to make unit tests easier if self.stream: return imaplib.IMAP4_stream(self.host) ImapClass = self.ssl and imaplib.IMAP4_SSL or imaplib.IMAP4 - return ImapClass(self.host, self.port) + return ImapClass(self.host, self.port, **kwargs) def login(self, username, password): """Login using *username* and *password*, returning the @@ -284,7 +285,7 @@ class IMAPClient(object): ([u'\\HasNoChildren', u'\\Starred'], '/', u'[Gmail]/Starred'), ([u'\\HasNoChildren', u'\\Trash'], '/', u'[Gmail]/Trash')] - This is a *deprecated* Gmail-specific IMAP extension (See + This is a *deprecated* Gmail-specific IMAP extension (See https://developers.google.com/gmail/imap_extensions#xlist_is_deprecated for more information). It is the responsibility of the caller to either check for ``XLIST`` -- 2.43.0