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 version is implemented as a Twisted Python "Service". It uses the
9
# twisted Reactor to handle polling and signal safety.
11
from twisted.internet.app import ApplicationService
12
from twisted.internet import reactor
13
from maildir import Maildir
15
class MaildirTwisted(ApplicationService, Maildir):
16
def __init__(self, serviceName, serviceParent, basedir):
17
ApplicationService.__init__(self, serviceName)
18
Maildir.__init__(self, basedir)
19
def startService(self):
20
self.serviceRunning = 1
23
def stopService(self):
26
def startTimeout(self):
27
self.timeout = reactor.callLater(self.pollinterval, self.poll)
28
def stopTimeout(self):
32
def dnotify_callback(self):
34
reactor.callFromThread(self.poll)
38
class MaildirTest(MaildirTwisted):
39
def messageReceived(self, filename):
40
print "changed:", filename
41
from twisted.internet.app import Application
42
#from maildir import MaildirTest
43
# note that MaildirTest is really __main__.MaildirTest, which makes
44
# maildir-test-shutdown.tap unusable
45
app = Application("maildir-test")
46
# add the service to the app
47
m = MaildirTest("maildir", app, basedir="ddir")
48
print "watching ddir/new/"
52
if __name__ == '__main__':