Unity indicator applet: maildir check
UPDATE: My code was found by another mutt user and modified, his changes are here, and I've changed it a bit more here. It now integrates with the unity messaging menu and shows notifications like it should!
As I mentioned in my last post, I've been transitioning to a local Maildir for my email. One downside to this is that the mail indicator included with Ubuntu's Unity desktop requires you to run Evolution to get mail updates. Now I know it also works with certain other MUAs (ie, Firebird), but I like Mutt, so I just wanted a simple indicator in Python to check my Maildir. So I did some googling and found some examples of indicator applets in Python, and coded up as simple applet. VoilĂ :

So all it does is poll my Maildir, and turn the icon red when I have messages; pretty simple. As you can see I currently have two little mail icons in my indicator; that's because I'm not integrating at all with the Ubuntu messages indicator. If I get a coding itch I'll investigate doing that. Other things I'd like to add are configurability for mailboxes as well as MUA of choice (the Config menu item is just a stub right now) and popup notifications for new messages. If I get those things done I might actually feel inclined to submit the code to someone, somewhere. For the moment, I'll leave the code here in case anyone wants example code of a really simple indicator applet. Feel free to do whatever you want with this code.
#!/usr/bin/env python
import sys, os, gtk, appindicator
CHECK_FREQUENCY = 60 # seconds
MAILDIRS = [ "/home/brad/Maildir/" ]
DEBUG_LEVEL = 0
class mailIndicator:
def __init__(self):
self.ind = appindicator.Indicator ("debian-doc-menu",
"indicator-messages",
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status (appindicator.STATUS_ACTIVE)
self.ind.set_attention_icon ("new-messages-red")
self.buildMenus()
self.ind.set_menu(self.menu)
def buildMenus(self):
self.menu = gtk.Menu()
self.mutt_item = gtk.MenuItem("Launch Mutt")
self.mutt_item.connect("activate", self.launch_mutt)
self.mutt_item.show()
self.menu.append(self.mutt_item)
self.maildir_item = gtk.MenuItem("Configure Maildir(s)")
self.maildir_item.connect("activate", self.maildir_clicked)
self.maildir_item.show()
self.menu.append(self.maildir_item)
self.quit_item = gtk.MenuItem("Quit")
self.quit_item.connect("activate", self.quit_clicked)
self.quit_item.show()
self.menu.append(self.quit_item)
def run(self):
self.check_mailbox()
gtk.timeout_add(CHECK_FREQUENCY * 1000, self.check_mailbox)
gtk.main()
def maildir_clicked(self, widget,data=None):
# stub
m = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, "STUB")
m.run()
m.destroy()
def quit_clicked(self, widget,data=None):
sys.exit(0)
def launch_mutt(self, widget,data=None):
os.system("gnome-terminal -e mutt &")
def check_mailbox(self):
DEBUG("Checking Maildirs")
newmail = False
for maildir in MAILDIRS:
newmail = (newmail or (len( os.listdir(maildir + "new") ) > 0))
if newmail == True:
self.ind.set_status (appindicator.STATUS_ATTENTION)
DEBUG("new mail detected.", 2)
else:
self.ind.set_status (appindicator.STATUS_ACTIVE)
DEBUG( "no new mail detected.", 2)
return True
def DEBUG(message, level = 1):
if DEBUG_LEVEL >= level:
print message
if __name__ == "__main__":
indicator = mailIndicator()
indicator.run()
July 28th, 2011 - 20:27
Brad, thanks for writing this. I’ve adapted your code to emit notifications, as well as use the messaging menu. The code for this is on gitorious: https://gitorious.org/chrisirwin-utils/maildir-indicator/blobs/master/maildir-indicator.py
One question: “Feel free to do whatever you want with this code” does not really indicate whether you’ve intended that to mean “public domain” or “wtfpl”, or whether it is okay to stick a free or permissive license on it. The license tag on my existing gitorious project was set to GPL3+. Just wanted to make sure this was an okay license with you.
Thanks again,
August 4th, 2011 - 12:06
Hey Chris,
Glad you found the code helpful!
My meaning is that the code doesn’t contain anything really original or creative; it pretty much reads like an API example, so I didn’t want to use a restrictive license. Feel free to redistribute it under any license you like; I guess the WTFPL would be a more formal way of saying the same thing. Personally I’d go with something less restrictive than GPL for such a small project, maybe BSDL, but I’m fine with that if it’s what you prefer.
August 8th, 2011 - 23:52
GPL was just my gut reaction, but you’re probably right. I’ll be formally appending the copyright to my repository shortly. Since we’re the only two contributors, and I think we’re both in agreement, I’ll tag it as WTFPL as that summed up your initial spirit. I also haven’t read up on the clauses on the BSD licenses.
WTFPL is pretty much how I feel about my bits as well.