Created
July 14, 2022 23:52
-
-
Save sebw/ac7b67bb6faea5be227e7360c0afb908 to your computer and use it in GitHub Desktop.
Count imap unread emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
small script to check for unread count on imap inbox | |
""" | |
import imaplib | |
IMAPSERVER = 'imap.fastmail.com' | |
USER = 'user@domain' | |
PASSWORD = 'xxxxxxxx' | |
try: | |
mail = imaplib.IMAP4_SSL(IMAPSERVER) | |
mail.login(USER, PASSWORD) | |
mail.select("INBOX", True) # connect to inbox. | |
return_code, mail_ids = mail.search(None, 'UnSeen') | |
converted = str(mail_ids[0], "UTF-8") | |
if converted == "": | |
count = 0 | |
else: | |
count = len(converted.split(" ")) | |
except: | |
count = 0 | |
if count == 0: | |
print("<span color='#a3be8c'>📪 " + str(count) + "</span>") | |
else: | |
print("<span color='#bf616a'>📬 " + str(count) + "</span>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment