Skip to content

Instantly share code, notes, and snippets.

@mrtazz
Created September 18, 2012 04:06
Show Gist options
  • Save mrtazz/3741193 to your computer and use it in GitHub Desktop.
Save mrtazz/3741193 to your computer and use it in GitHub Desktop.
quick script to check unread count of imap inbox
#!/usr/bin/env python
"""
small script to check for unread count on imap inbox
"""
import imaplib
IMAPSERVER = ''
USER = ''
PASSWORD = ''
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')
count = len(mail_ids[0].split(" "))
except:
count = 0
print count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment