diff options
| author | Tslil Clingman <hiato1@gmail.com> | 2015-06-24 15:08:32 +0200 |
|---|---|---|
| committer | Tslil Clingman <hiato1@gmail.com> | 2015-06-24 15:08:32 +0200 |
| commit | db8146fe4f86a2d0f76a9e7b4ac392985dafcdc1 (patch) | |
| tree | 65dde57c2044ef673353cf601e359533a4a69a93 | |
| parent | 0100e5ad7197101038dc6c792b1f2c804a43806f (diff) | |
A more unixy approach
| -rwxr-xr-x | count_email.py | 29 | ||||
| -rwxr-xr-x | newmail | 21 |
2 files changed, 21 insertions, 29 deletions
diff --git a/count_email.py b/count_email.py deleted file mode 100755 index 6b51971..0000000 --- a/count_email.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/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)) @@ -0,0 +1,21 @@ +#!/usr/bin/env sh + +servers="gmail posteo" + +result= +regexp='s#^machine \(.*\) login \(.*\) password \(.*\) port \([0-9]*\)$#-u \2:\3 imaps://\1:\4/INBOX#' +data=$(gpg --quiet --decrypt $HOME/.authinfo.gpg | grep 993) +for server in $servers; do + line=$(echo "$data" | grep $server | head -n 1) + num=$(curl -s --ssl-reqd $(echo $line | sed "$regexp") -X 'SEARCH UNSEEN' | grep SEARCH | wc -w) + if [ "$num" != "2" ]; then + count=$(($num - 2)) + if [ -z "$result" ]; then + result="$server: $count" + else + result="$result, $server: $count" + fi + fi +done; + +echo $result |
