launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04983
[Merge] lp:~mbp/launchpad/mail-script into lp:launchpad
Martin Pool has proposed merging lp:~mbp/launchpad/mail-script into lp:launchpad with lp:~mbp/launchpad/643223-dkim-aliases as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~mbp/launchpad/mail-script/+merge/75488
This builds on the process-one-mail.py interactive testing script introduced in lp:~mbp/launchpad/643223-dkim-aliases
* take input from a named file so that pdb can still work
* show mail sent in response
The latter seems super useful for interactive testing of mail, compared to futzing with zcml and mailboxes.
The way it is hooked into sendmail is basically the simplest thing that would possibly work. If there is something more in keeping with Launchpad's general approach and not too much longer, please let me know.
--
https://code.launchpad.net/~mbp/launchpad/mail-script/+merge/75488
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~mbp/launchpad/mail-script into lp:launchpad.
=== modified file 'doc/email.txt'
--- doc/email.txt 2011-08-16 19:30:17 +0000
+++ doc/email.txt 2011-09-15 07:12:27 +0000
@@ -1,9 +1,22 @@
Launchpad and Email
===================
+Quicker interactive testing
+---------------------------
+
+There is a script ``process-one-mail.py`` which reads a single mail
+message from a file (or stdin), processes it as if it had been received by
+Lanuchpad, and then prints out any mail generated in response. For
+quasi-interactive testing of email processing this may be your best bet.
+
Quickstart
----------
+Otherwise, you can configure Launchpad with an incoming mailbox and an
+outgoing mailer, in a way somewhat similar to what is used in production.
+This lets you catch mail sent other than in response to an incoming
+message.
+
Create the file override-includes/+mail-configure.zcml with contents
similar to the following::
=== modified file 'lib/lp/services/mail/sendmail.py'
--- lib/lp/services/mail/sendmail.py 2011-04-07 04:58:20 +0000
+++ lib/lp/services/mail/sendmail.py 2011-09-15 07:12:27 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""The One True Way to send mail from the Launchpad application.
@@ -42,6 +42,7 @@
)
import hashlib
from smtplib import SMTP
+import sys
from lazr.restful.utils import get_current_browser_request
from zope.app import zapi
@@ -427,6 +428,9 @@
# when running in the testing environment, store emails
TestMailer().send(
config.canonical.bounce_address, to_addrs, raw_message)
+ elif getattr(config, 'sendmail_to_stdout', None):
+ # For debugging, from process-one-mail, just print it.
+ sys.stdout.write(raw_message)
else:
if config.zopeless.send_email:
# Note that we simply throw away dud recipients. This is fine,
=== modified file 'scripts/process-one-mail.py'
--- scripts/process-one-mail.py 2011-09-15 07:12:26 +0000
+++ scripts/process-one-mail.py 2011-09-15 07:12:27 +0000
@@ -23,9 +23,11 @@
from lp.services.mail.signedmessage import signed_message_from_string
class ProcessMail(LaunchpadScript):
- usage = """%prog [options]
-
- Process one incoming email, read from stdin.
+ usage = """%prog [options] [MAIL_FILE]
+
+ Process one incoming email, read from the specified file or from stdin.
+
+ Any mail generated in response is printed to stdout.
""" + __doc__
@@ -33,12 +35,18 @@
self.txn.begin()
# NB: This somewhat duplicates handleMail, but there it's mixed in
# with handling a mailbox, which we're avoiding here.
- self.logger.debug("reading message from stdin")
- raw_mail = sys.stdin.read()
+ if len(self.args) >= 1:
+ from_file = file(self.args[0], 'rb')
+ else:
+ from_file = sys.stdin
+ self.logger.debug("reading message from %r" % (from_file,))
+ raw_mail = from_file.read()
self.logger.debug("got %d bytes" % len(raw_mail))
file_alias = save_mail_to_librarian(raw_mail)
self.logger.debug("saved to librarian as %r" % (file_alias,))
parsed_mail = signed_message_from_string(raw_mail)
+ # Kinda kludgey way to cause sendmail to just print it.
+ config.sendmail_to_stdout = True
handle_one_mail(
self.logger, parsed_mail,
file_alias, file_alias.http_url,