From bc67fa3204f0554cd9a0e733a0eb0d1ea59335b0 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Fri, 18 Dec 2020 08:31:59 +0300 Subject: [PATCH] python: use configured_mail_{port,security} when creating IMAPClient Previously only TLS on port 993 was allowed. --- python/src/deltachat/_build.py | 1 + python/src/deltachat/direct_imap.py | 32 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/python/src/deltachat/_build.py b/python/src/deltachat/_build.py index c0c34ee14..687be4ac3 100644 --- a/python/src/deltachat/_build.py +++ b/python/src/deltachat/_build.py @@ -145,6 +145,7 @@ def extract_defines(flags): | DC_STR | DC_CONTACT_ID | DC_GCL + | DC_SOCKET | DC_CHAT | DC_PROVIDER | DC_KEY_GEN diff --git a/python/src/deltachat/direct_imap.py b/python/src/deltachat/direct_imap.py index ca67fd835..dcc01097a 100644 --- a/python/src/deltachat/direct_imap.py +++ b/python/src/deltachat/direct_imap.py @@ -10,6 +10,7 @@ import pathlib from imapclient import IMAPClient from imapclient.exceptions import IMAPClientError import deltachat +from deltachat import const SEEN = b'\\Seen' @@ -50,18 +51,31 @@ class DirectImap: self.connect() def connect(self): - ssl_context = ssl.create_default_context() - - # don't check if certificate hostname doesn't match target hostname - ssl_context.check_hostname = False - - # don't check if the certificate is trusted by a certificate authority - ssl_context.verify_mode = ssl.CERT_NONE - host = self.account.get_config("configured_mail_server") + port = int(self.account.get_config("configured_mail_port")) + security = int(self.account.get_config("configured_mail_security")) + user = self.account.get_config("addr") pw = self.account.get_config("mail_pw") - self.conn = IMAPClient(host, ssl_context=ssl_context) + + if security == const.DC_SOCKET_PLAIN: + ssl_context = None + else: + ssl_context = ssl.create_default_context() + + # don't check if certificate hostname doesn't match target hostname + ssl_context.check_hostname = False + + # don't check if the certificate is trusted by a certificate authority + ssl_context.verify_mode = ssl.CERT_NONE + + if security == const.DC_SOCKET_STARTTLS: + self.conn = IMAPClient(host, port, ssl=False) + self.conn.starttls(ssl_context) + elif security == const.DC_SOCKET_PLAIN: + self.conn = IMAPClient(host, port, ssl=False) + elif security == const.DC_SOCKET_SSL: + self.conn = IMAPClient(host, port, ssl_context=ssl_context) self.conn.login(user, pw) self.select_folder("INBOX")