summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-ximap-dl14
1 files changed, 9 insertions, 5 deletions
diff --git a/imap-dl b/imap-dl
index a1c2329..f1259da 100755
--- a/imap-dl
+++ b/imap-dl
@@ -80,6 +80,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,
+ 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}')
+
def scan_msgs(configfile:str, verbose:bool) -> None:
conf = configparser.ConfigParser()
conf.read_file(open(configfile, 'r'))
@@ -125,11 +133,7 @@ def scan_msgs(configfile:str, verbose:bool) -> None:
port=int(conf.get('retriever', 'port', fallback=993)),
ssl_context=ctx) as imap:
username:str = conf.get('retriever', 'username')
- 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}')
+ auth_builtin(username, imap, conf, server)
if verbose: # only enable debugging after login to avoid leaking credentials in the log
imap.debug = 4
logging.info("capabilities reported: %s", ', '.join(imap.capabilities))