Creates and provides a default SSL context to the IMAP library

This commit is contained in:
Trenton H 2023-07-27 15:07:59 -07:00
parent aad5e9e99f
commit b715e4d426

View File

@ -2,6 +2,7 @@ import datetime
import itertools import itertools
import logging import logging
import os import os
import ssl
import tempfile import tempfile
import traceback import traceback
from datetime import date from datetime import date
@ -394,13 +395,12 @@ def get_mailbox(server, port, security) -> MailBox:
""" """
Returns the correct MailBox instance for the given configuration. Returns the correct MailBox instance for the given configuration.
""" """
if security == MailAccount.ImapSecurity.NONE: if security == MailAccount.ImapSecurity.NONE:
mailbox = MailBoxUnencrypted(server, port) mailbox = MailBoxUnencrypted(server, port)
elif security == MailAccount.ImapSecurity.STARTTLS: elif security == MailAccount.ImapSecurity.STARTTLS:
mailbox = MailBoxTls(server, port) mailbox = MailBoxTls(server, port, ssl_context=ssl.create_default_context())
elif security == MailAccount.ImapSecurity.SSL: elif security == MailAccount.ImapSecurity.SSL:
mailbox = MailBox(server, port) mailbox = MailBox(server, port, ssl_context=ssl.create_default_context())
else: else:
raise NotImplementedError("Unknown IMAP security") # pragma: nocover raise NotImplementedError("Unknown IMAP security") # pragma: nocover
return mailbox return mailbox