I3/mutt/offlineimap with decent mail notifications

Today I’ll show you my last trick to get decent email notifications on my I3 environment, without using anything else than offlineimap and mutt. Ok, there’s something else, a couple of scripts but nothing scary.

Before going further, I’d like to ensure you’re using i3blocks. If not, then please configure it then come back and read on.

Until today I was using the classical offlineimap configuration which polled my IMAP server every several minutes directed from a crontab. However, that method has several drawbacks:
– lack of instant mail delivery
– offlineimap would occasionally get stuck upon wifi issues.

Then save this script as ~/bin/mail-idle.py. Modify lines 25..27 to suit your configuration. Beware that you should use the same values as in your ~/.offlineimaprc file, if not the scripts will not correctly invoke offlineimap.chmod +x ~/bin/mail-idle.py

Get the i3blocks blocklet command from here and save it to ~/.config/i3blocks/mail_status.sh. Then adjust it on line 2 to get it inspect your local mailboxes. Also, adjust line 6 if the directory containing your mails is not ~/Mail.chmod +x ~/.config/i3blocks/mail_status.sh

As you may have noticed, the blocklet will be updated by the other parts of the system using this command:pkill -SIGRTMIN+12 i3blocks

Hang-on, we’re almost done! 😉

Get the tool activated upon I3 session start by adding this to ~/.config/i3/config:exec --no-startup-id ~/bin/mail-check.sh &

Stop your current mail retrieval scripts and then restart your I3 session. You should now start having notifications upon new mail arrival. That is, when some of the IMAP folders supervised by mail-idle.py get mail, then you should see a dunst (or whatever you use) notification, and the i3blocket should become red, displaying the offlineimap account name containing new mails, with their count.