From 23b689f479df578f69a89a0ca5d97b45dbc4ba30 Mon Sep 17 00:00:00 2001 From: Bryan Lai Date: Thu, 23 May 2024 01:13:43 +0800 Subject: [PATCH] Fix deprecated ssl.wrap_socket This fix was originally provided by Lalufu in #fedora-devel, and posted on the issue tracker by @knurd. --- Mailnag/common/imaplib2.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Mailnag/common/imaplib2.py b/Mailnag/common/imaplib2.py index 0cbcff3..e97ccab 100644 --- a/Mailnag/common/imaplib2.py +++ b/Mailnag/common/imaplib2.py @@ -309,6 +309,7 @@ def __init__(self, host=None, port=None, debug=None, debug_file=None, identifier self.compressor = None # COMPRESS/DEFLATE if not None self.decompressor = None self._tls_established = False + self._ssl_context = None # Create unique tag for this session, # and compile tagged response matcher. @@ -492,7 +493,13 @@ def ssl_wrap_socket(self): ssl_version = TLS_MAP[self.tls_level][self.ssl_version] - self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ca_certs=self.ca_certs, cert_reqs=cert_reqs, ssl_version=ssl_version, ciphers='ALL') + self._ssl_context = ssl.SSLContext(ssl_version) + self._ssl_context.verify_mode = cert_reqs + if self.ca_certs: + self._ssl_context.load_verify_locations(self.ca_certs) + if self.keyfile and self.certfile: + self._ssl_context.load_cert_chain(self.certfile, self.keyfile) + self.sock = self._ssl_context.wrap_socket(self.sock, server_hostname=self.host) ssl_exc = ssl.SSLError self.read_fd = self.sock.fileno() except ImportError: