Skip to content

Commit

Permalink
Merge pull request #71 from dhellmann/python-3.10-update
Browse files Browse the repository at this point in the history
Python 3.10 update
  • Loading branch information
mergify[bot] committed May 7, 2022
2 parents af05252 + dd2866f commit c862344
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
15 changes: 10 additions & 5 deletions imapautofiler/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging
import mailbox
import os
import ssl

import imapclient

Expand Down Expand Up @@ -153,21 +154,25 @@ def __init__(self, cfg):
super().__init__(cfg)

# Use default client behavior if ca_file not provided.
context = imapclient.create_default_context()
if 'ca_file' in cfg['server']:
context.cafile = cfg['server']['ca_file']
context = ssl.create_default_context(
cafile=cfg['server']['ca_file'],
)
else:
context = ssl.create_default_context()

if 'check_hostname' in cfg['server']:
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = tobool(cfg['server']['check_hostname'])

ssl = True
use_ssl = True
if 'ssl' in cfg['server']:
ssl = tobool(cfg['server']['ssl'])
use_ssl = tobool(cfg['server']['ssl'])

self._conn = imapclient.IMAPClient(
cfg['server']['hostname'],
use_uid=True,
ssl=ssl,
ssl=use_ssl,
port=cfg['server'].get('port'),
ssl_context=context,
)
Expand Down
17 changes: 8 additions & 9 deletions imapautofiler/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from imapautofiler.client import IMAPClient
from imapautofiler.config import get_config, tobool


CONFIG = """\
server:
hostname: example.com
Expand Down Expand Up @@ -84,18 +83,18 @@ def test_tobool(self):

class TestServerConfig(BaseConfigTest):
def test_imapclient_config(self):
context = mock.MagicMock()
with mock.patch('imapclient.create_default_context',
return_value=context):
context = mock.Mock()
context_maker = mock.Mock(return_value=context)
with mock.patch('ssl.create_default_context',
context_maker):
with mock.patch('imapclient.IMAPClient') as clientclass:
conn = IMAPClient(self.cfg)
IMAPClient(self.cfg)
clientclass.assert_called_once_with(
'example.com',
use_uid=True,
ssl=True,
port=1234,
ssl_context=context)
conn._conn.login.assert_called_once_with('my-user@example.com',
'super-secret')
self.assertEqual(context.cafile, 'path/to/ca_file.pem')
self.assertTrue(context.check_hostname)
context_maker.assert_called_once_with(
cafile='path/to/ca_file.pem',
)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyYAML>=3.11
imapclient>=1.0.1,<2.0.0
imapclient>=2.2.0
keyring>=10.0.0
jinja2>=2.11.2
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ classifier =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Communications :: Email

[files]
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
distribute = False
envlist = pep8,py37,py38,py39,docs,pkglint
envlist = pep8,py,docs,pkglint

[testenv]
deps = .[test]
Expand Down

0 comments on commit c862344

Please sign in to comment.