Changeset - 349a0ca30a75
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 14 years ago 2012-01-07 22:55:24
marcin@python-works.com
Changed default recipients separator for mails to ', '
4 files changed with 28 insertions and 12 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/rcmail/exceptions.py
Show inline comments
 

	
 

	
 
class InvalidMessage(RuntimeError):
 
    """
 
@@ -5,6 +6,7 @@ class InvalidMessage(RuntimeError):
 
    as recipients or sender address.
 
    """
 

	
 

	
 
class BadHeaders(RuntimeError):
 
    """
 
    Raised if message contains newlines in headers.
rhodecode/lib/rcmail/message.py
Show inline comments
 
@@ -45,6 +45,8 @@ class Message(object):
 
    :param bcc: BCC list
 
    :param extra_headers: dict of extra email headers
 
    :param attachments: list of Attachment instances
 
    :param recipients_separator: alternative separator for any of
 
        'From', 'To', 'Delivered-To', 'Cc', 'Bcc' fields
 
    """
 

	
 
    def __init__(self,
 
@@ -56,8 +58,8 @@ class Message(object):
 
                 cc=None,
 
                 bcc=None,
 
                 extra_headers=None,
 
                 attachments=None):
 

	
 
                 attachments=None,
 
                 recipients_separator="; "):
 

	
 
        self.subject = subject or ''
 
        self.sender = sender
 
@@ -70,6 +72,8 @@ class Message(object):
 
        self.bcc = bcc or []
 
        self.extra_headers = extra_headers or {}
 

	
 
        self.recipients_separator = recipients_separator
 

	
 
    @property
 
    def send_to(self):
 
        return set(self.recipients) | set(self.bcc or ()) | set(self.cc or ())
 
@@ -92,7 +96,8 @@ class Message(object):
 
                                To=self.recipients,
 
                                From=self.sender,
 
                                Body=self.body,
 
                                Html=self.html)
 
                                Html=self.html,
 
                                separator=self.recipients_separator)
 

	
 
        if self.bcc:
 
            response.base['Bcc'] = self.bcc
rhodecode/lib/rcmail/response.py
Show inline comments
 
@@ -141,12 +141,14 @@ class MailResponse(object):
 
    MailResponse.to_message.  This lets you change it and work with it, then
 
    send it out when it's ready.
 
    """
 
    def __init__(self, To=None, From=None, Subject=None, Body=None, Html=None):
 
    def __init__(self, To=None, From=None, Subject=None, Body=None, Html=None, 
 
                 separator="; "):
 
        self.Body = Body
 
        self.Html = Html
 
        self.base = MailBase([('To', To), ('From', From), ('Subject', Subject)])
 
        self.multipart = self.Body and self.Html
 
        self.attachments = []
 
        self.separator = separator
 

	
 
    def __contains__(self, key):
 
        return self.base.__contains__(key)
 
@@ -298,7 +300,7 @@ class MailResponse(object):
 
            self.base.body = self.Html
 
            self.base.content_encoding['Content-Type'] = ('text/html', {})
 

	
 
        return to_message(self.base)
 
        return to_message(self.base, separator=self.separator)
 

	
 
    def all_parts(self):
 
        """
 
@@ -310,7 +312,7 @@ class MailResponse(object):
 
    def keys(self):
 
        return self.base.keys()
 

	
 
def to_message(mail):
 
def to_message(mail, separator="; "):
 
    """
 
    Given a MailBase message, this will construct a MIMEPart
 
    that is canonicalized for use with the Python email API.
 
@@ -339,10 +341,16 @@ def to_message(mail):
 

	
 
    for k in mail.keys():
 
        if k in ADDRESS_HEADERS_WHITELIST:
 
            out[k.encode('ascii')] = header_to_mime_encoding(mail[k])
 
            out[k.encode('ascii')] = header_to_mime_encoding(
 
                                         mail[k],
 
                                         not_email=False,
 
                                         separator=separator
 
                                     )
 
        else:
 
            out[k.encode('ascii')] = header_to_mime_encoding(mail[k],
 
                                                             not_email=True)
 
            out[k.encode('ascii')] = header_to_mime_encoding(
 
                                         mail[k],
 
                                         not_email=True
 
                                    )
 

	
 
    out.extract_payload(mail)
 

	
 
@@ -403,12 +411,12 @@ class MIMEPart(MIMEBase):
 
            self.is_multipart())
 

	
 

	
 
def header_to_mime_encoding(value, not_email=False):
 
def header_to_mime_encoding(value, not_email=False, separator=", "):
 
    if not value: return ""
 

	
 
    encoder = Charset(DEFAULT_ENCODING)
 
    if type(value) == list:
 
        return "; ".join(properly_encode_header(
 
        return separator.join(properly_encode_header(
 
            v, encoder, not_email) for v in value)
 
    else:
 
        return properly_encode_header(value, encoder, not_email)
rhodecode/lib/rcmail/smtp_mailer.py
Show inline comments
 
@@ -59,7 +59,8 @@ class SmtpMailer(object):
 

	
 
        if isinstance(recipients, basestring):
 
            recipients = [recipients]
 
        msg = Message(subject, recipients, body, html, self.mail_from)
 
        msg = Message(subject, recipients, body, html, self.mail_from,
 
                      recipients_separator=", ")
 
        raw_msg = msg.to_message()
 

	
 
        if self.ssl:
0 comments (0 inline, 0 general)