1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/usr/bin/env python2.4
# Copyright 2004 Canonical Ltd. All rights reserved.
"""Fetches mail from the mail box and feeds them to the handlers."""
import _pythonpath
import logging, sys
from optparse import OptionParser
from zope.component.exceptions import ComponentLookupError
from canonical.lp import initZopeless
from canonical.launchpad.scripts import (
execute_zcml_for_scripts, logger_options, logger)
from canonical.launchpad.scripts.lockfile import LockFile
from canonical.launchpad.mail.incoming import handleMail
from canonical.launchpad.interfaces import IMailBox
usage = """%prog [options]
""" + __doc__
def main(args):
options_parser = OptionParser(usage=usage)
logger_options(options_parser)
options, args = options_parser.parse_args(args)
log = logger(options, 'process-mail')
lockfile = LockFile('/var/lock/launchpad-process-mail.lock', logger=log)
lockfile.acquire()
try:
trans = initZopeless()
execute_zcml_for_scripts(use_web_security=True)
try:
handleMail(trans)
return 0
except ComponentLookupError, lookup_error:
if lookup_error.args[0] == IMailBox:
log.error(
"No mail box is configured. "
"Please see mailbox.txt for info on how to configure one.")
return 1
raise
finally:
lockfile.release()
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
|