13668.1.21
by Curtis Hovey
Updated copyrights. |
1 |
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
|
8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py files. |
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
3 |
||
7845.2.4
by Tim Penhey
Minor updates following review. |
4 |
"""Useful helper functions used for testing."""
|
7845.2.2
by Tim Penhey
Add a helper function to the harness. |
5 |
|
6 |
__metaclass__ = type |
|
7 |
||
8 |
from email.Utils import formatdate |
|
9 |
import os |
|
10 |
||
11 |
from zope.component import getUtility |
|
12 |
||
13668.1.5
by Curtis Hovey
Moved canonical.launchpad.interfaces.mailbox to lp.services.mail |
13 |
from lp.services.mail.mailbox import IMailBox |
13668.1.2
by Curtis Hovey
import from lp.services.mail.sendmail |
14 |
from lp.services.mail.sendmail import ( |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
15 |
get_msgid, |
16 |
MailController, |
|
17 |
)
|
|
7845.2.2
by Tim Penhey
Add a helper function to the harness. |
18 |
|
19 |
||
20 |
def create_mail_for_directoryMailBox(from_addr, to_addrs, subject, body, |
|
21 |
headers=None): |
|
22 |
"""Create a email in the DirectoryMailBox."""
|
|
23 |
mc = MailController(from_addr, to_addrs, subject, body, headers) |
|
24 |
message = mc.makeMessage() |
|
25 |
if 'message-id' not in message: |
|
26 |
message['Message-Id'] = get_msgid() |
|
27 |
if 'date' not in message: |
|
28 |
message['Date'] = formatdate() |
|
29 |
# Since this is faking incoming email, set the X-Original-To.
|
|
30 |
message['X-Original-To'] = to_addrs |
|
31 |
mailbox = getUtility(IMailBox) |
|
32 |
msg_file = open( |
|
33 |
os.path.join(mailbox.mail_dir, message['Message-Id']), 'w') |
|
34 |
msg_file.write(message.as_string()) |
|
35 |
msg_file.close() |