Skip to content

Commit

Permalink
According to martinrusev#68 the
Browse files Browse the repository at this point in the history
software was altered, in order to use the systems SSL-Context as
default.

It allows to toggle the use of the SSL-Default Context. It does not
allow to use a custom context.

 Considerations:
 * If No SSL-Validation should be done, the ImboxClass should be adapted, in
   order to achieve configuration of the ssl-context. This commit does not
   contain this alteration.

 Other Changes:
 * Reformatted long lines
  • Loading branch information
Dustin Demuth committed Jun 2, 2016
1 parent 9dd4913 commit 2a0117b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions imbox/imap.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
from imaplib import IMAP4, IMAP4_SSL

import logging
import ssl as pythonssllib

logger = logging.getLogger(__name__)


class ImapTransport(object):

def __init__(self, hostname, port=None, ssl=False):
def __init__(self, hostname, port=None, ssl=True, usesslcontext=True):
self.hostname = hostname
self.port = port

if ssl:
self.transport = IMAP4_SSL
if usesslcontext = True:
context = pythonssllib.create_default_context()
else:
context = None

if not self.port:
self.port = 993
self.server = self.IMAP4_SSL(self.hostname, self.port,
ssl_context=context)
else:
self.transport = IMAP4
if not self.port:
self.port = 143

self.server = self.transport(self.hostname, self.port)
logger.debug("Created IMAP4 transport for {host}:{port}".format(host=self.hostname, port=self.port))
self.server = self.IMAP4(self.hostname, self.port)
logger.debug("Created IMAP4 transport for {host}:{port}"
.format(host=self.hostname, port=self.port))

def list_folders(self):
logger.debug("List all folders in mailbox")
Expand All @@ -28,5 +37,6 @@ def list_folders(self):
def connect(self, username, password):
self.server.login(username, password)
self.server.select()
logger.debug("Logged into server {} and selected mailbox 'INBOX'".format(self.hostname))
logger.debug("Logged into server {} and selected mailbox 'INBOX'"
.format(self.hostname))
return self.server

0 comments on commit 2a0117b

Please sign in to comment.