summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobbie Harwood <rharwood@redhat.com>2020-05-04 14:54:11 -0400
committerSean Whitton <spwhitton@spwhitton.name>2020-05-05 07:57:20 -0700
commitd6c60f05fc0b2dd2959a46d866ec2b35dc3c0f7f (patch)
tree376b139663a9f710229e7b155d27799608806304
parent2f1ccd039ec0b1c4f33d682afc51d6dc6993eb63 (diff)
downloadmailscripts-d6c60f05fc0b2dd2959a46d866ec2b35dc3c0f7f.tar.gz
imap-dl: update for imaplib type changes
Of particular note here, imaplib.IMAP4_SSL is now an instance of imaplib.IMAP4. Additionally, semantics around imap.login appear to not match our previous assumption: the function can never not return 'OK', but can raise exceptions. Signed-off-by: Robbie Harwood <rharwood@redhat.com>
-rwxr-xr-ximap-dl18
1 files changed, 9 insertions, 9 deletions
diff --git a/imap-dl b/imap-dl
index a644549..fac7487 100755
--- a/imap-dl
+++ b/imap-dl
@@ -87,13 +87,14 @@ summary_splitter = Splitter('summary', _summary_re)
_fetch_re = rb'^(?P<id>[0-9]+) \(UID (?P<uid>[0-9]+) (FLAGS \([\\A-Za-z ]*\) )?BODY\[\] \{(?P<size>[0-9]+)\}$'
fetch_splitter = Splitter('fetch', _fetch_re)
-def auth_builtin(username:str, imap:imaplib.IMAP4_SSL,
+def auth_builtin(username:str, imap:imaplib.IMAP4,
conf:configparser.ConfigParser, server:str) -> None:
logging.info('Logging in as %s', username)
resp:Tuple[str, List[Union[bytes,Tuple[bytes,bytes]]]]
- resp = imap.login(username, conf.get('retriever', 'password'))
- if resp[0] != 'OK':
- raise Exception(f'login failed with {resp} as user {username} on {server}')
+ try:
+ imap.login(username, conf.get('retriever', 'password'))
+ except Exception as e:
+ raise Exception(f'login failed with {e} as user {username} on {server}')
if gssapi:
# imaplib auth methods need to be in the form of callables, and they all
@@ -131,7 +132,7 @@ if gssapi:
response = self.gss_vc.wrap(bytes(reply), response.encrypted)
return response.message if response.message else b"" # type: ignore
-def auth_gssapi(username:str, imap:imaplib.IMAP4_SSL,
+def auth_gssapi(username:str, imap:imaplib.IMAP4,
conf:configparser.ConfigParser, server:str) -> None:
if not gssapi:
raise Exception('Kerberos requested, but python3-gssapi not found')
@@ -184,7 +185,7 @@ def scan_msgs(configfile:str, verbose:bool) -> None:
ctx.set_ciphers(ssl_ciphers)
server:str = conf.get('retriever', 'server')
- with imaplib.IMAP4_SSL(host=server, #type: ignore
+ with imaplib.IMAP4_SSL(host=server,
port=int(conf.get('retriever', 'port', fallback=993)),
ssl_context=ctx) as imap:
username:str = conf.get('retriever', 'username')
@@ -212,7 +213,7 @@ def scan_msgs(configfile:str, verbose:bool) -> None:
raise Exception(f'selection failed: {resp}')
if len(resp[1]) != 1:
raise Exception(f'expected exactly one EXISTS response from select, got {resp[1]}')
- data:Union[bytes,Tuple[bytes,bytes]] = resp[1][0]
+ data:Optional[bytes] = resp[1][0]
if not isinstance(data, bytes):
raise Exception(f'expected bytes in response to SELECT, got {data}')
n:int = int(data)
@@ -222,10 +223,9 @@ def scan_msgs(configfile:str, verbose:bool) -> None:
pull_msgs(imap, n, mdst, on_size_mismatch, delete)
logging.getLogger().setLevel(oldloglevel)
-def pull_msgs(imap:imaplib.IMAP4_SSL, n:int, mdst:mailbox.Maildir,
+def pull_msgs(imap:imaplib.IMAP4, n:int, mdst:mailbox.Maildir,
on_size_mismatch:OnSizeMismatch, delete:bool) -> None:
sizes_mismatched:List[int] = []
- resp:Tuple[str, List[Union[bytes,Tuple[bytes,bytes]]]]
resp = imap.fetch('1:%d'%(n), '(UID RFC822.SIZE)')
if resp[0] != 'OK':
raise Exception(f'initial FETCH 1:{n} not OK ({resp})')