Thanks. It took some doing (and a little hair loss), but it was worth it!
I was considering using a cron job, but I prefer to have my dzen2 script run it so it can integrate into the status bar with less resources. This also means that I don't need an extra notification flag.
I bumped into isync (uses mbsync to grab mail), so I've decided to use it instead. It's much faster than offlineimap, being based off of C++ and not python. Also, offlineimap is not going to be given new features and may eventually be discontinued as the dev mentioned on github.
Here is the new—and much improved—setup, incase anyone might benefit and for my own reference later:
~/.mbsync:
Code: Select all
# Change 'mymailname' to whatever you would like to name it
# You could get away with just changing the first 3 variables (i.e., Host, User, Pass) for a simple setup.
IMAPAccount mymailname
# Address to connect to
Host mail.myemail.com
User myemailuser@myemail.com
Pass mypass
# To store the password in an encrypted file use PassCmd instead of Pass
# PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d ~/.mailpass.gpg"
#
# Use SSL
SSLType IMAPS
# The following line should work. If get certificate errors, uncomment the two following lines and read the "Troubleshooting" section.
CertificateFile /etc/ssl/certs/ca-certificates.crt
#CertificateFile ~/.cert/imap.gmail.com.pem
#CertificateFile ~/.cert/Equifax_Secure_CA.pem
IMAPStore mymailname-remote
Account mymailname
MaildirStore mymailname-local
Subfolders Verbatim
# The trailing "/" is important
Path ~/.mail/mymailname/
Inbox ~/.mail/mymailname/Inbox
Channel mymailname
Master :mymailname-remote:
Slave :mymailname-local:
# Exclude everything under the internal [Gmail] folder, except the interesting folders
#Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail"
# Or include everything
Patterns *
# Automatically create missing mailboxes, both locally and on the server
Create Both
# Save the synchronization state files in the relevant directory
SyncState *
To check the mail (could be run by a cron job):
checkmail.sh:
Code: Select all
#!/bin/sh
mbsync -q mymailname
# Count all the new files in the 'new' directory
newMail=$(find ~/.mail/mymailname/Inbox/new/ -type f | wc -l)
echo "Inbox:"$newMail
if [ $newMail -gt 0 ]; then
# Add an 's' if more than 1 email
if [ $newMail -gt 1 ]; then addTheS="s"; fi
notify-send -t 0 "<span color='#ffffff' font='26px' face='mono'><b>Your inbox now has "$newMail" email$addTheS!</b></span>"
beep
# Uncomment if you'd like to clear the cache so that this notification doesn't keep running
#rm -f ~/.mail/mymailname/Inbox/new/*
fi
Point mutt to that mailbox so that you can instantly load the cached email:
readmail.sh:
Code: Select all
#!/bin/sh
urxvt -e mutt -f ~/.mail/mymailname/Inbox/
As you view the new email, mutt will automatically take the viewed emails off the list, lowering the email count; there is no need to reset the count manually.