~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to scripts/process-one-mail.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-21 14:28:02 UTC
  • mfrom: (14006 devel)
  • mto: This revision was merged to the branch mainline in revision 14010.
  • Revision ID: jelmer@canonical.com-20110921142802-7ggkc204igsy532w
MergeĀ lp:launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from lp.services.mail.signedmessage import signed_message_from_string    
24
24
 
25
25
class ProcessMail(LaunchpadScript):
26
 
    usage = """%prog [options]
27
 
 
28
 
    Process one incoming email, read from stdin.
 
26
    usage = """%prog [options] [MAIL_FILE]
 
27
 
 
28
    Process one incoming email, read from the specified file or from stdin.
 
29
 
 
30
    Any mail generated in response is printed to stdout.
29
31
 
30
32
    """ + __doc__
31
33
 
33
35
        self.txn.begin()
34
36
        # NB: This somewhat duplicates handleMail, but there it's mixed in
35
37
        # with handling a mailbox, which we're avoiding here.
36
 
        self.logger.debug("reading message from stdin")
37
 
        raw_mail = sys.stdin.read()
 
38
        if len(self.args) >= 1:
 
39
            from_file = file(self.args[0], 'rb')
 
40
        else:
 
41
            from_file = sys.stdin
 
42
        self.logger.debug("reading message from %r" % (from_file,))
 
43
        raw_mail = from_file.read()
38
44
        self.logger.debug("got %d bytes" % len(raw_mail))
39
45
        file_alias = save_mail_to_librarian(raw_mail)
40
46
        self.logger.debug("saved to librarian as %r" % (file_alias,))
41
47
        parsed_mail = signed_message_from_string(raw_mail)
 
48
        # Kinda kludgey way to cause sendmail to just print it.
 
49
        config.sendmail_to_stdout = True
42
50
        handle_one_mail(
43
51
            self.logger, parsed_mail,
44
52
            file_alias, file_alias.http_url,