From d6e6cfd3c9aa4f920f9d0f2e3dba3f6ddc2dcfb3 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Wed, 4 Jun 2014 17:13:06 -0400 Subject: [PATCH] mail test: catch typical connecting errors and display nicer output --- tests/test_mail.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_mail.py b/tests/test_mail.py index 6c287ba..8975eb8 100755 --- a/tests/test_mail.py +++ b/tests/test_mail.py @@ -12,8 +12,18 @@ host, emailaddress, pw = sys.argv[1:4] # Attempt to login with IMAP. Our setup uses email addresses # as IMAP/SMTP usernames. -M = imaplib.IMAP4_SSL(host) -M.login(emailaddress, pw) +try: + M = imaplib.IMAP4_SSL(host) + M.login(emailaddress, pw) +except OSError as e: + print("Connection error:", e) + sys.exit(1) +except imaplib.IMAP4.error as e: + # any sort of login error + e = ", ".join(a.decode("utf8") for a in e.args) + print("IMAP error:", e) + sys.exit(1) + M.select() print("IMAP login is OK.")