Code

Opened 7 years ago

Closed 7 years ago

#3554 closed (fixed)

[patch] implement explicit timezone offset in date header for emails generated by django

Reported by: mrmachine <real dot human at mrmachine dot net> Owned by: adrian
Component: Core (Mail) Version: master
Severity: Keywords: mail timezone rfc822 rfc2822
Cc: real.human@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django.core.mail uses formatdate() from the rfc822 module which has been deprecated as of python 2.3 in favour of the email module (http://docs.python.org/lib/module-rfc822.html), which contains an equivelent Utils.formatdate() method.

the problem with rfc822.formatdate() is that it includes the timezone offset as a named string which some popular MUA's misread or ignore (such as apple's mail.app), causing emails generated by django to appear out of order as the date header is assumed to be local time when it is actually GMT.

>>> import rfc822       
>>> from email import Utils
>>> rfc822.formatdate()
'Fri, 23 Feb 2007 00:16:54 GMT'
>>> Utils.formatdate()
'Fri, 23 Feb 2007 00:17:01 -0000'

RFC822 was made obsolete by RFC2822 (http://www.faqs.org/rfcs/rfc2822.html) which states:

The zone specifies the offset from Coordinated Universal Time (UTC,
formerly referred to as "Greenwich Mean Time") that the date and
time-of-day represent.  The "+" or "-" indicates whether the
time-of-day is ahead of (i.e., east of) or behind (i.e., west of)
Universal Time.  The first two digits indicate the number of hours
difference from Universal Time, and the last two digits indicate the
number of minutes difference from Universal Time.  (Hence, +hhmm
means +(hh * 60 + mm) minutes, and -hhmm means -(hh * 60 + mm)
minutes).  The form "+0000" SHOULD be used to indicate a time zone at
Universal Time.  Though "-0000" also indicates Universal Time, it is
used to indicate that the time was generated on a system that may be
in a local time zone other than Universal Time and therefore
indicates that the date-time contains no information about the local
time zone.

email.Utils.formatdate() always returns the current Universal Time regardless of local server time with "-0000" as the timezone, which is correct according to the RFC above. attached is a patch which replaces rfc822.formatdate() with email.Utils.formatdate() in django.core.mail. it's a simple change which shouldn't break anything, but should improve compatibility with MUA's which don't understand or choose to ignore named timezones and expect an explicit offset instead.

Attachments (1)

explicit_timezone_offset.patch (774 bytes) - added by mrmachine <real dot human at mrmachine dot net> 7 years ago.
replace rfc822.formatdate() with email.Utils.formatdate() in django.core.mail

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by mrmachine <real dot human at mrmachine dot net>

replace rfc822.formatdate() with email.Utils.formatdate() in django.core.mail

comment:1 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

looks good.

comment:2 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(In [4570]) Fixed #3554: django.core.mail now generates dates with the email module instead of the outdated rfc822 module. Thanks, real.human@…

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.