Django

Code

Changeset 9197

Show
Ignore:
Timestamp:
10/07/08 07:20:01 (3 months ago)
Author:
mtredinnick
Message:

Fixed #9233 -- Allow date and message-id headers to be passed in manually in
email messages. Previously we were creating duplicate headers, which was bad.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/mail.py

    r8483 r9197  
    248248        msg['From'] = self.from_email 
    249249        msg['To'] = ', '.join(self.to) 
    250         msg['Date'] = formatdate() 
    251         msg['Message-ID'] = make_msgid() 
     250 
     251        # Email header names are case-insensitive (RFC 2045), so we have to 
     252        # accommodate that when doing comparisons. 
     253        header_names = [key.lower() for key in self.extra_headers] 
     254        if 'date' not in header_names: 
     255            msg['Date'] = formatdate() 
     256        if 'message-id' not in header_names: 
     257            msg['Message-ID'] = make_msgid() 
    252258        for name, value in self.extra_headers.items(): 
    253259            msg[name] = value 
  • django/trunk/tests/regressiontests/mail/tests.py

    r8508 r9197  
    5353'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Long subject lines that get wrapped should use a space continuation\n character to get expected behaviour in Outlook and Thunderbird\nFrom: from@example.com\nTo: to@example.com\nDate: ...\nMessage-ID: <...>\n\nContent' 
    5454 
     55# Specifying dates or message-ids in the extra headers overrides the defaul 
     56# values (#9233). 
     57 
     58>>> headers = {"date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"} 
     59>>> email = EmailMessage('subject', 'content', 'from@example.com', ['to@example.com'], headers=headers) 
     60>>> email.message().as_string() 
     61'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\ndate: Fri, 09 Nov 2001 01:08:47 -0000\nMessage-ID: foo\n\ncontent' 
     62 
    5563"""