Skip to content

Commit

Permalink
Added support for python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ikvk committed Oct 4, 2023
1 parent f735d8e commit acae531
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ Big thanks to people who helped develop this library:
`JacquelinCharbonnel <https://github.com/JacquelinCharbonnel>`_,
`stumpylog <https://github.com/stumpylog>`_,
`dimitrisstr <https://github.com/dimitrisstr>`_,
`abionics <https://github.com/abionics>`_
`abionics <https://github.com/abionics>`_,
`link2xt <https://github.com/link2xt>`_

Help the project
----------------
Expand Down
4 changes: 4 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.3.0
=====
* Added support for python 3.12 - Since 3.12 keyfile and certfile arguments are deprecated for imaplib.IMAP4_SSL, ssl_context and timeout must be keyword arguments

1.2.0
=====
* Fixed MailBoxFolderManager.status bug for folders with brackets
Expand Down
2 changes: 1 addition & 1 deletion imap_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
from .utils import EmailAddress
from .errors import *

__version__ = '1.2.0'
__version__ = '1.3.0'
16 changes: 12 additions & 4 deletions imap_tools/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ def __init__(self, host='', port=143, timeout=None):
def _get_mailbox_client(self) -> imaplib.IMAP4:
if PYTHON_VERSION_MINOR < 9:
return imaplib.IMAP4(self._host, self._port)
elif PYTHON_VERSION_MINOR < 12:
return imaplib.IMAP4(self._host, self._port, self._timeout)
else:
return imaplib.IMAP4(self._host, self._port, self._timeout) # noqa
return imaplib.IMAP4(self._host, self._port, timeout=self._timeout)


class MailBox(BaseMailBox):
Expand All @@ -285,6 +287,8 @@ def __init__(self, host='', port=993, timeout=None, keyfile=None, certfile=None,
:param keyfile: PEM formatted file that contains your private key (deprecated)
:param certfile: PEM formatted certificate chain file (deprecated)
:param ssl_context: SSLContext object that contains your certificate chain and private key
Since Python 3.9 timeout argument added
Since Python 3.12 keyfile and certfile arguments are deprecated, ssl_context and timeout must be keyword args
"""
check_timeout_arg_support(timeout)
self._host = host
Expand All @@ -298,9 +302,11 @@ def __init__(self, host='', port=993, timeout=None, keyfile=None, certfile=None,
def _get_mailbox_client(self) -> imaplib.IMAP4:
if PYTHON_VERSION_MINOR < 9:
return imaplib.IMAP4_SSL(self._host, self._port, self._keyfile, self._certfile, self._ssl_context)
elif PYTHON_VERSION_MINOR < 12:
return imaplib.IMAP4_SSL(
self._host, self._port, self._keyfile, self._certfile, self._ssl_context, self._timeout)
else:
return imaplib.IMAP4_SSL(self._host, self._port, self._keyfile, self._certfile, self._ssl_context,
self._timeout)
return imaplib.IMAP4_SSL(self._host, self._port, ssl_context=self._ssl_context, timeout=self._timeout)


class MailBoxTls(BaseMailBox):
Expand All @@ -323,8 +329,10 @@ def __init__(self, host='', port=993, timeout=None, ssl_context=None):
def _get_mailbox_client(self) -> imaplib.IMAP4:
if PYTHON_VERSION_MINOR < 9:
client = imaplib.IMAP4(self._host, self._port)
elif PYTHON_VERSION_MINOR < 12:
client = imaplib.IMAP4(self._host, self._port, self._timeout)
else:
client = imaplib.IMAP4(self._host, self._port, self._timeout) # noqa
client = imaplib.IMAP4(self._host, self._port, timeout=self._timeout)
result = client.starttls(self._ssl_context)
check_command_status(result, MailboxStarttlsError)
return client
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist=
py3.3,py3.4,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11
py3.3,py3.4,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12

[testenv]
commands=
Expand Down

0 comments on commit acae531

Please sign in to comment.