~ubuntu-branches/ubuntu/edgy/mailcrypt/edgy

« back to all changes in this revision

Viewing changes to tests/remailer/maildirtwisted.py

  • Committer: Bazaar Package Importer
  • Author(s): Davide G. M. Salvetti
  • Date: 2005-10-10 17:49:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051010174917-9khdzkxutwykslzx
Tags: 3.5.8+CVS.2005.04.29.1-4
control (Standard-Versions): Upgraded to 3.6.2.
(Depends): Modified the dependency on "debconf" to "debconf |
debconf-2.0" in order to allow the transition to cdebconf.
(Closes: #332016)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
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").
 
7
 
 
8
# This version is implemented as a Twisted Python "Service". It uses the
 
9
# twisted Reactor to handle polling and signal safety.
 
10
 
 
11
from twisted.internet.app import ApplicationService
 
12
from twisted.internet import reactor
 
13
from maildir import Maildir
 
14
 
 
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
 
21
        self.start()
 
22
        return None
 
23
    def stopService(self):
 
24
        self.stop()
 
25
        return None
 
26
    def startTimeout(self):
 
27
        self.timeout = reactor.callLater(self.pollinterval, self.poll)
 
28
    def stopTimeout(self):
 
29
        if self.timeout:
 
30
            self.timeout.cancel()
 
31
            self.timeout = None
 
32
    def dnotify_callback(self):
 
33
        # make it safe
 
34
        reactor.callFromThread(self.poll)
 
35
 
 
36
 
 
37
def test1():
 
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/"
 
49
    app.run()
 
50
    print "done"
 
51
    
 
52
if __name__ == '__main__':
 
53
    test1()
 
54
    
 
55