##// END OF EJS Templates
mail response garden
marcink -
r1905:fbddaf2f beta
parent child Browse files
Show More
@@ -41,17 +41,20 from email.charset import Charset
41 from email.utils import parseaddr
41 from email.utils import parseaddr
42 from email.mime.base import MIMEBase
42 from email.mime.base import MIMEBase
43
43
44 ADDRESS_HEADERS_WHITELIST = ['From', 'To', 'Delivered-To', 'Cc', 'Bcc']
44 ADDRESS_HEADERS_WHITELIST = ['From', 'To', 'Delivered-To', 'Cc']
45 DEFAULT_ENCODING = "utf-8"
45 DEFAULT_ENCODING = "utf-8"
46 VALUE_IS_EMAIL_ADDRESS = lambda v: '@' in v
46 VALUE_IS_EMAIL_ADDRESS = lambda v: '@' in v
47
47
48
48 def normalize_header(header):
49 def normalize_header(header):
49 return string.capwords(header.lower(), '-')
50 return string.capwords(header.lower(), '-')
50
51
52
51 class EncodingError(Exception):
53 class EncodingError(Exception):
52 """Thrown when there is an encoding error."""
54 """Thrown when there is an encoding error."""
53 pass
55 pass
54
56
57
55 class MailBase(object):
58 class MailBase(object):
56 """MailBase is used as the basis of lamson.mail and contains the basics of
59 """MailBase is used as the basis of lamson.mail and contains the basics of
57 encoding an email. You actually can do all your email processing with this
60 encoding an email. You actually can do all your email processing with this
@@ -105,7 +108,6 class MailBase(object):
105 {'filename': filename})
108 {'filename': filename})
106 self.parts.append(part)
109 self.parts.append(part)
107
110
108
109 def attach_text(self, data, ctype):
111 def attach_text(self, data, ctype):
110 """
112 """
111 This attaches a simpler text encoded part, which doesn't have a
113 This attaches a simpler text encoded part, which doesn't have a
@@ -124,6 +126,7 class MailBase(object):
124 for x in p.walk():
126 for x in p.walk():
125 yield x
127 yield x
126
128
129
127 class MailResponse(object):
130 class MailResponse(object):
128 """
131 """
129 You are given MailResponse objects from the lamson.view methods, and
132 You are given MailResponse objects from the lamson.view methods, and
@@ -194,6 +197,7 class MailResponse(object):
194 'content_type': content_type,
197 'content_type': content_type,
195 'data': data,
198 'data': data,
196 'disposition': disposition,})
199 'disposition': disposition,})
200
197 def attach_part(self, part):
201 def attach_part(self, part):
198 """
202 """
199 Attaches a raw MailBase part from a MailRequest (or anywhere)
203 Attaches a raw MailBase part from a MailRequest (or anywhere)
@@ -227,7 +231,6 class MailResponse(object):
227 del self.base.parts[:]
231 del self.base.parts[:]
228 self.multipart = False
232 self.multipart = False
229
233
230
231 def update(self, message):
234 def update(self, message):
232 """
235 """
233 Used to easily set a bunch of heading from another dict
236 Used to easily set a bunch of heading from another dict
@@ -312,6 +315,7 class MailResponse(object):
312 def keys(self):
315 def keys(self):
313 return self.base.keys()
316 return self.base.keys()
314
317
318
315 def to_message(mail, separator="; "):
319 def to_message(mail, separator="; "):
316 """
320 """
317 Given a MailBase message, this will construct a MIMEPart
321 Given a MailBase message, this will construct a MIMEPart
@@ -334,7 +338,7 def to_message(mail, separator="; "):
334
338
335 try:
339 try:
336 out = MIMEPart(ctype, **params)
340 out = MIMEPart(ctype, **params)
337 except TypeError, exc: # pragma: no cover
341 except TypeError, exc: # pragma: no cover
338 raise EncodingError("Content-Type malformed, not allowed: %r; "
342 raise EncodingError("Content-Type malformed, not allowed: %r; "
339 "%r (Python ERROR: %s" %
343 "%r (Python ERROR: %s" %
340 (ctype, params, exc.message))
344 (ctype, params, exc.message))
@@ -382,7 +386,6 class MIMEPart(MIMEBase):
382
386
383 self.set_payload(encoded, charset=charset)
387 self.set_payload(encoded, charset=charset)
384
388
385
386 def extract_payload(self, mail):
389 def extract_payload(self, mail):
387 if mail.body == None: return # only None, '' is still ok
390 if mail.body == None: return # only None, '' is still ok
388
391
General Comments 0
You need to be logged in to leave comments. Login now