diff options
| author | Tslil Clingman <hiato1@gmail.com> | 2015-06-22 20:42:41 +0200 |
|---|---|---|
| committer | Tslil Clingman <hiato1@gmail.com> | 2015-06-22 20:42:41 +0200 |
| commit | 0100e5ad7197101038dc6c792b1f2c804a43806f (patch) | |
| tree | 57dfd143e2b6bd45c6f4fc5868a5f13fc95a1e51 | |
| parent | 00a3aac5046e860d46c70ef8bb3d68d12e4e5ec0 (diff) | |
Maybe this will be useful?
| -rwxr-xr-x | count_email.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/count_email.py b/count_email.py new file mode 100755 index 0000000..6b51971 --- /dev/null +++ b/count_email.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +# A small script to pull unread email counts from servers in .authinfo + +from imaplib import IMAP4_SSL +from subprocess import check_output + +# Server +servers=["posteo","gmail"] +result = [] +# Decrypt the file, split the lines +data = check_output(["gpg","--decrypt",".authinfo.gpg"]).decode('utf-8').split('\n') +# Collect results +for server in servers: + # Get password and username + line = [l for l in data if ("imap" in l and server in l)][0].split() + host,user,password = line[1], line[3], line[5] + # Login + imap = IMAP4_SSL(host) + imap.login(user,password) + imap.select("INBOX", 1) + # Count emails + _, res = imap.search(None, "UNSEEN") + count = len(res[0].split()) + imap.logout() + # Store count if there's something + if count>0: result.append(user+": "+str(count)) +# What did we find +print(", ".join(result)) |
