mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
python: use configured_mail_{port,security} when creating IMAPClient
Previously only TLS on port 993 was allowed.
This commit is contained in:
committed by
link2xt
parent
29991f1caf
commit
bc67fa3204
@@ -145,6 +145,7 @@ def extract_defines(flags):
|
|||||||
| DC_STR
|
| DC_STR
|
||||||
| DC_CONTACT_ID
|
| DC_CONTACT_ID
|
||||||
| DC_GCL
|
| DC_GCL
|
||||||
|
| DC_SOCKET
|
||||||
| DC_CHAT
|
| DC_CHAT
|
||||||
| DC_PROVIDER
|
| DC_PROVIDER
|
||||||
| DC_KEY_GEN
|
| DC_KEY_GEN
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import pathlib
|
|||||||
from imapclient import IMAPClient
|
from imapclient import IMAPClient
|
||||||
from imapclient.exceptions import IMAPClientError
|
from imapclient.exceptions import IMAPClientError
|
||||||
import deltachat
|
import deltachat
|
||||||
|
from deltachat import const
|
||||||
|
|
||||||
|
|
||||||
SEEN = b'\\Seen'
|
SEEN = b'\\Seen'
|
||||||
@@ -50,18 +51,31 @@ class DirectImap:
|
|||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
def connect(self):
|
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")
|
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")
|
user = self.account.get_config("addr")
|
||||||
pw = self.account.get_config("mail_pw")
|
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.conn.login(user, pw)
|
||||||
|
|
||||||
self.select_folder("INBOX")
|
self.select_folder("INBOX")
|
||||||
|
|||||||
Reference in New Issue
Block a user