3
# This is a class which watches a maildir for new messages. It uses the
4
# linux dirwatcher API (if available) to look for new files. The
5
# .messageReceived method is invoked with the filename of the new message,
6
# relative to the top of the maildir (so it will look like "new/blahblah").
8
# This form uses the Gtk event loop to handle polling and signal safety
10
if __name__ == '__main__':
15
from maildir import Maildir
17
class MaildirGtk(Maildir):
18
def __init__(self, basedir):
19
Maildir.__init__(self, basedir)
21
def startTimeout(self):
22
self.timeout = gtk.timeout_add(self.pollinterval*1000, self.doTimeout)
25
return gtk.TRUE # keep going
26
def stopTimeout(self):
28
gtk.timeout_remove(self.timeout)
30
def dnotify_callback(self):
32
self.idler = gtk.idle_add(self.idlePoll)
34
gtk.idle_remove(self.idler)
40
class MaildirTest(MaildirGtk):
41
def messageReceived(self, filename):
42
print "changed:", filename
43
m = MaildirTest("ddir")
44
print "watching ddir/new/"
47
# to allow the python-side signal handler to run, we must surface from
48
# gtk (which blocks on the C-side) every once in a while.
50
gtk.mainiteration() # this will block until there is something to do
54
if __name__ == '__main__':