Script and README
This commit is contained in:
parent
886e19ac7c
commit
c07a3220cc
2 changed files with 23 additions and 0 deletions
|
@ -1,2 +1,10 @@
|
||||||
py-gmail-unread
|
py-gmail-unread
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
I wanted to inject the number of unread messages I have into my ZSH prompt and
|
||||||
|
obviously I needed a way to get the unread count. This script should be set up
|
||||||
|
in cron to run periodically as it's a bit too slow for inline calls. Depends on
|
||||||
|
the EMAIL environment variable as well as your password being loaded up into
|
||||||
|
the OSX keychain under the name "email" using your password as the account. The
|
||||||
|
script saves the unread count out to /tmp/GMAIL_UNREAD and then you can do
|
||||||
|
whatever the fuck you want do to with it, as long as it's not illegal.
|
||||||
|
|
15
gmail-unread.py
Executable file
15
gmail-unread.py
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import imaplib
|
||||||
|
import os
|
||||||
|
|
||||||
|
email = os.environ['EMAIL']
|
||||||
|
password = os.popen('security find-generic-password -w -s email -a "' + email + '"').read().replace('\n', '')
|
||||||
|
|
||||||
|
imap = imaplib.IMAP4_SSL('imap.gmail.com', '993')
|
||||||
|
imap.login(email, password)
|
||||||
|
imap.select()
|
||||||
|
|
||||||
|
fp = open('/tmp/GMAIL_UNREAD', 'w')
|
||||||
|
print(len(imap.search(None,'UnSeen')[1][0].split()), file=fp)
|
Loading…
Add table
Add a link
Reference in a new issue