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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
from zope.component.zcml import (
handler,
utility,
)
from zope.interface import Interface
from zope.schema import (
ASCII,
Bool,
)
from zope.sendmail.interfaces import IMailer
from zope.sendmail.zcml import IMailerDirective
from lp.services.mail.mailbox import (
DirectoryMailBox,
IMailBox,
POP3MailBox,
TestMailBox,
)
from lp.services.mail.mbox import MboxMailer
from lp.services.mail.stub import (
StubMailer,
TestMailer,
)
class ITestMailBoxDirective(Interface):
"""Configure a mail box which operates on test_emails."""
def testMailBoxHandler(_context):
utility(_context, IMailBox, component=TestMailBox())
class IPOP3MailBoxDirective(Interface):
"""Configure a mail box which interfaces to a POP3 server."""
host = ASCII(
title=u"Host",
description=u"Host name of the POP3 server.",
required=True,
)
user = ASCII(
title=u"User",
description=u"User name to connect to the POP3 server with.",
required=True,
)
password = ASCII(
title=u"Password",
description=u"Password to connect to the POP3 server with.",
required=True,
)
ssl = Bool(
title=u"SSL",
description=u"Use SSL.",
required=False,
default=False)
def pop3MailBoxHandler(_context, host, user, password, ssl=False):
utility(
_context, IMailBox, component=POP3MailBox(host, user, password, ssl))
class IDirectoryMailBoxDirective(Interface):
"""Configure a mail box which interfaces to a directory of raw files."""
directory = ASCII(
title=u"Directory",
description=u"The directory containing the raw mail files.",
required=True,
)
def directorymailBoxHandler(_context, directory):
"""Create the DirectoryMailBox and register the utility."""
utility(_context, IMailBox, component=DirectoryMailBox(directory))
class IStubMailerDirective(IMailerDirective):
from_addr = ASCII(
title=u"From Address",
description=u"All outgoing emails will use this email address",
required=True,
)
to_addr = ASCII(
title=u"To Address",
description=(
u"All outgoing emails will be redirected to this email "
u"address"),
required=True,
)
mailer = ASCII(
title=u"Mailer to use",
description=u"""\
Which registered mailer to use, such as configured with
the smtpMailer or sendmailMailer directives""",
required=False,
default='smtp',
)
rewrite = Bool(
title=u"Rewrite headers",
description=u"""\
If true, headers are rewritten in addition to the
destination address in the envelope. May me required
to bypass spam filters.""",
required=False,
default=False,
)
def stubMailerHandler(_context, name, from_addr, to_addr,
mailer='smtp', rewrite=False):
_context.action(
discriminator=('utility', IMailer, name),
callable=handler,
args=('registerUtility',
StubMailer(from_addr, [to_addr], mailer, rewrite),
IMailer, name)
)
class ITestMailerDirective(IMailerDirective):
pass
def testMailerHandler(_context, name):
_context.action(
discriminator=('utility', IMailer, name),
callable=handler,
args=('registerUtility', TestMailer(), IMailer, name)
)
class IMboxMailerDirective(IMailerDirective):
filename = ASCII(
title=u'File name',
description=u'Unix mbox file to store outgoing emails in',
required=True,
)
overwrite = Bool(
title=u'Overwrite',
description=u'Whether to overwrite the existing mbox file or not',
required=False,
default=False,
)
mailer = ASCII(
title=u"Chained mailer to which messages are forwarded",
description=u"""\
Optional mailer to forward messages to, such as those configured
with smtpMailer, sendmailMailer, or testMailer directives. When
not given, the message is not forwarded but only stored in the
mbox file.""",
required=False,
default=None,
)
def mboxMailerHandler(_context, name, filename, overwrite, mailer=None):
_context.action(
discriminator=('utility', IMailer, name),
callable=handler,
args=('registerUtility',
MboxMailer(filename, overwrite, mailer),
IMailer, name)
)
|