Ticket #7722: cc-r13609.diff

File cc-r13609.diff, 4.8 KB (added by dougvanhorn, 14 years ago)

Patch updated against r13609, includes modest regression and doc changes.

  • django/core/mail/message.py

     
    105105    encoding = None     # None => use settings default
    106106
    107107    def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
    108                  connection=None, attachments=None, headers=None):
     108                 connection=None, attachments=None, headers=None, cc=None):
    109109        """
    110110        Initialize a single email message (which can be sent to multiple
    111111        recipients).
     
    119119            self.to = list(to)
    120120        else:
    121121            self.to = []
     122        if cc:
     123            assert not isinstance(cc, basestring), '"cc" argument must be a list or tuple'
     124            self.cc = list(cc)
     125        else:
     126            self.cc = []
    122127        if bcc:
    123128            assert not isinstance(bcc, basestring), '"bcc" argument must be a list or tuple'
    124129            self.bcc = list(bcc)
     
    145150        msg['Subject'] = self.subject
    146151        msg['From'] = self.extra_headers.get('From', self.from_email)
    147152        msg['To'] = ', '.join(self.to)
     153        if self.cc:
     154            msg['Cc'] = ', '.join(self.cc)
    148155
    149156        # Email header names are case-insensitive (RFC 2045), so we have to
    150157        # accommodate that when doing comparisons.
     
    162169    def recipients(self):
    163170        """
    164171        Returns a list of all recipients of the email (includes direct
    165         addressees as well as Bcc entries).
     172        addressees as well as Cc and Bcc entries).
    166173        """
    167         return self.to + self.bcc
     174        return self.to + self.cc + self.bcc
    168175
    169176    def send(self, fail_silently=False):
    170177        """Sends the email message."""
     
    252259    alternative_subtype = 'alternative'
    253260
    254261    def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
    255             connection=None, attachments=None, headers=None, alternatives=None):
     262            connection=None, attachments=None, headers=None, alternatives=None,
     263            cc=None):
    256264        """
    257265        Initialize a single email message (which can be sent to multiple
    258266        recipients).
     
    261269        bytestrings). The SafeMIMEText class will handle any necessary encoding
    262270        conversions.
    263271        """
    264         super(EmailMultiAlternatives, self).__init__(subject, body, from_email, to, bcc, connection, attachments, headers)
     272        super(EmailMultiAlternatives, self).__init__(subject, body, from_email, to, bcc, connection, attachments, headers, cc)
    265273        self.alternatives=alternatives or []
    266274
    267275    def attach_alternative(self, content, mimetype):
  • tests/regressiontests/mail/tests.py

     
    417417>>> settings.ADMINS = old_admins
    418418>>> settings.MANAGERS = old_managers
    419419
     420# Add Cc to the email argument list (#7722)
     421
     422>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com'])
     423>>> message = email.message()
     424>>> message['Cc']
     425'cc@example.com'
     426>>> email.recipients()
     427['to@example.com', 'cc@example.com']
     428
     429>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com'], cc=['cc@example.com', 'cc.other@example.com'])
     430>>> message = email.message()
     431>>> message['Cc']
     432'cc@example.com, cc.other@example.com'
     433>>> email.recipients()
     434['to@example.com', 'other@example.com', 'cc@example.com', 'cc.other@example.com']
     435
     436>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com'], cc=['cc@example.com', 'cc.other@example.com'], bcc=['bcc@example.com'])
     437>>> message = email.message()
     438>>> email.recipients()
     439['to@example.com', 'other@example.com', 'cc@example.com', 'cc.other@example.com', 'bcc@example.com']
     440
     441>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com'])
     442>>> message = email.message()
     443>>> message.as_string()
     444'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: from@example.com\nTo: to@example.com\nCc: cc@example.com\nDate: ...\nMessage-ID: <...>\n\nContent'
     445
    420446"""
  • docs/topics/email.txt

     
    261261      caller to ensure header names and values are in the correct format for
    262262      an e-mail message.
    263263
     264    # ``cc``: A list or tuple of addresses used in the "Cc" receiver field when
     265      sending the e-mail.
     266
    264267For example::
    265268
    266269    email = EmailMessage('Hello', 'Body goes here', 'from@example.com',
Back to Top