diff --git a/gmail_unread.py b/gmail_unread.py index 3936b6a..a96d6b6 100755 --- a/gmail_unread.py +++ b/gmail_unread.py @@ -4,15 +4,13 @@ import imaplib -#default imap port is 993, change otherwise -M=imaplib.IMAP4_SSL("imap.gmail.com", 993) -from credentials import gmail_login,gmail_password -M.login(gmail_login,gmail_password) - -status, counts = M.status("Inbox","(MESSAGES UNSEEN)") - -unread = counts[0].split()[4][:-1] - -print(int(unread)) - -M.logout() +try: + from credentials import gmail_login,gmail_password + M=imaplib.IMAP4_SSL("imap.gmail.com", 993) + M.login(gmail_login,gmail_password) + status, counts = M.status("Inbox","(MESSAGES UNSEEN)") + unread = counts[0].split()[4][:-1] + M.logout() + print(int(unread)) +except: + print("?") diff --git a/mymail_unread.py b/mymail_unread.py index dda0d43..0f625a9 100755 --- a/mymail_unread.py +++ b/mymail_unread.py @@ -16,17 +16,18 @@ def IMAP_starttls(self, keyfile=None, certfile=None,cert_reqs=ssl.CERT_NONE,ca_c imaplib.IMAP4.__dict__['starttls']=IMAP_starttls imaplib.Commands['STARTTLS']=('NONAUTH',) -# read credentials -from credentials import mymail_server,mymail_port,mymail_login,mymail_password +try: + # read credentials + from credentials import mymail_server,mymail_port,mymail_login,mymail_password -M=imaplib.IMAP4(mymail_server, mymail_port) -M.starttls() -M.login(mymail_login,mymail_password) + M=imaplib.IMAP4(mymail_server, mymail_port) + M.starttls() + M.login(mymail_login,mymail_password) -status, counts = M.status("Inbox","(MESSAGES UNSEEN)") + status, counts = M.status("Inbox","(MESSAGES UNSEEN)") -unread = counts[0].split()[4][:-1] - -print(int(unread)) - -M.logout() + unread = counts[0].split()[4][:-1] + M.logout() + print(int(unread)) +except: + print("?")