[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|
|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|
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.
Change History (3)
Changed 9 years ago by mrmachine <real dot human at mrmachine dot net>
comment:1 Changed 9 years ago by SmileyChris
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Ready for checkin