Changeset - fbddaf2f9728
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 14 years ago 2012-01-15 19:22:57
marcin@python-works.com
mail response garden
1 file changed with 8 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/rcmail/response.py
Show inline comments
 
@@ -41,17 +41,20 @@ from email.charset import Charset
 
from email.utils import parseaddr
 
from email.mime.base import MIMEBase
 

	
 
ADDRESS_HEADERS_WHITELIST = ['From', 'To', 'Delivered-To', 'Cc', 'Bcc']
 
ADDRESS_HEADERS_WHITELIST = ['From', 'To', 'Delivered-To', 'Cc']
 
DEFAULT_ENCODING = "utf-8"
 
VALUE_IS_EMAIL_ADDRESS = lambda v: '@' in v
 

	
 

	
 
def normalize_header(header):
 
    return string.capwords(header.lower(), '-')
 

	
 

	
 
class EncodingError(Exception):
 
    """Thrown when there is an encoding error."""
 
    pass
 

	
 

	
 
class MailBase(object):
 
    """MailBase is used as the basis of lamson.mail and contains the basics of
 
    encoding an email.  You actually can do all your email processing with this
 
@@ -105,7 +108,6 @@ class MailBase(object):
 
                                                        {'filename': filename})
 
        self.parts.append(part)
 

	
 

	
 
    def attach_text(self, data, ctype):
 
        """
 
        This attaches a simpler text encoded part, which doesn't have a
 
@@ -124,6 +126,7 @@ class MailBase(object):
 
            for x in p.walk():
 
                yield x
 

	
 

	
 
class MailResponse(object):
 
    """
 
    You are given MailResponse objects from the lamson.view methods, and
 
@@ -194,6 +197,7 @@ class MailResponse(object):
 
                                 'content_type': content_type,
 
                                 'data': data,
 
                                 'disposition': disposition,})
 
        
 
    def attach_part(self, part):
 
        """
 
        Attaches a raw MailBase part from a MailRequest (or anywhere)
 
@@ -227,7 +231,6 @@ class MailResponse(object):
 
        del self.base.parts[:]
 
        self.multipart = False
 

	
 

	
 
    def update(self, message):
 
        """
 
        Used to easily set a bunch of heading from another dict
 
@@ -312,6 +315,7 @@ class MailResponse(object):
 
    def keys(self):
 
        return self.base.keys()
 

	
 

	
 
def to_message(mail, separator="; "):
 
    """
 
    Given a MailBase message, this will construct a MIMEPart
 
@@ -334,7 +338,7 @@ def to_message(mail, separator="; "):
 

	
 
    try:
 
        out = MIMEPart(ctype, **params)
 
    except TypeError, exc: # pragma: no cover
 
    except TypeError, exc:  # pragma: no cover
 
        raise EncodingError("Content-Type malformed, not allowed: %r; "
 
                            "%r (Python ERROR: %s" %
 
                            (ctype, params, exc.message))
 
@@ -382,7 +386,6 @@ class MIMEPart(MIMEBase):
 

	
 
        self.set_payload(encoded, charset=charset)
 

	
 

	
 
    def extract_payload(self, mail):
 
        if mail.body == None: return  # only None, '' is still ok
 

	
0 comments (0 inline, 0 general)