169
169
return scope_name == self.script_scope
172
class MailHeaderScope(BaseScope):
173
"""Matches a regex against the un-wrapped form of arbitrary mail headers.
175
For example mail_header:received:bad-example\\.com will match any mail
176
that passed through that host.
178
The header name is matched case-insensitively, and if the header is
179
repeated this scope looks for a match in any occurrence.
181
The value is matched as a Python regex, without
182
anchoring to the start of the string, and with Python's default regexp
183
options. For a case-insensitive match, you should include (?i) at the
186
Headers are not unfolded before matching, so wrapped lines may appear as
190
pattern = r'mail_header:(?P<header_name>[^:]*):(?P<value_regex>.*)'
192
def __init__(self, email_message):
193
self.email_message = email_message
195
def lookup(self, scope_name):
196
match = self.compiled_pattern.match(scope_name)
198
return False # Shouldn't happen?
199
header_name = match.group('header_name')
200
regex_str = match.group('value_regex')
201
regex = re.compile(regex_str)
202
for header_value in self.email_message.get_all(header_name, []):
203
if regex.search(header_value):
209
172
# These are the handlers for all of the allowable scopes, listed here so that
210
173
# we can for example show all of them in an admin page. Any new scope will
211
174
# need a scope handler and that scope handler has to be added to this list.
212
175
# See BaseScope for hints as to what a scope handler should look like.
176
HANDLERS = set([DefaultScope, PageScope, TeamScope, ServerScope, ScriptScope])
223
179
class MultiScopeHandler():
280
231
super(ScopesForScript, self).__init__([
282
233
ScriptScope(script_name)])
285
class ScopesForMail(MultiScopeHandler):
286
"""Identify feature scopes for handling user email."""
288
def __init__(self, mail_object):
289
"""Construct set of scopes for incoming mail.
291
:param mail_object: An ISignedMessage giving the parsed
292
form of the incoming message. (Note that it's *not*
293
necessarily signed, just potentially signed.)
295
super(ScopesForMail, self).__init__([
297
MailHeaderScope(mail_object),