Skip Menu |

This queue is for tickets about the MIME-Lite CPAN distribution.

Report information
The Basics
Id: 274
Status: resolved
Priority: 0/
Queue: MIME-Lite

People
Owner: Nobody in particular
Requestors: kurta [...] spk.agilent.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Date field update per RFC 2822 section 3.3
This patch updates the date field format to comply with RFC 2822 section 3.3: using local time not UTC and using a signed four digit offset to designate the timezone. It relies on the Time::Local module which is distributed with PERL so it should be OK to assume its presence and functionality. Cheers, Kurt
*** Lite.pm.orig Mon Feb 11 06:35:00 2002 --- Lite.pm Mon Feb 11 07:04:59 2002 *************** *** 1052,1060 **** my $ds_wanted = $params{Datestamp}; my $ds_defaulted = ($is_top and !exists($params{Datestamp})); if (($ds_wanted or $ds_defaulted) and !exists($params{Date})) { my ($u_wdy, $u_mon, $u_mdy, $u_time, $u_y4) = ! split /\s+/, gmtime().""; ### should be non-locale-dependent ! my $date = "$u_wdy, $u_mdy $u_mon $u_y4 $u_time UT"; $self->add("date", $date); } --- 1052,1069 ---- my $ds_wanted = $params{Datestamp}; my $ds_defaulted = ($is_top and !exists($params{Datestamp})); if (($ds_wanted or $ds_defaulted) and !exists($params{Date})) { + # Updated to use local time and numeric offset per RFC 2822 + # Calculate offset from UTC + use Time::Local; # ships w/ PERL so should be OK to assume presence + my $t0 = timegm (0,0,0,2,0,70); # one day from epoch + my $t1 = timelocal (0,0,0,2,0,70); + my $offset = $t0 - $t1; + my $offset_hrs = int ($offset / 3600); + my $offset_min = int ($offset / 60) - $offset_hrs * 60; + my $offset_str = sprintf "%+.2d%02d", $offset_hrs, $offset_min; my ($u_wdy, $u_mon, $u_mdy, $u_time, $u_y4) = ! split /\s+/, localtime().""; ### should be non-locale-dependent ! my $date = "$u_wdy, $u_mdy $u_mon $u_y4 $u_time $offset_str"; $self->add("date", $date); }
From: vek [...] pharmapartners.nl
[guest - Mon Feb 11 10:09:47 2002]: Show quoted text
> This patch updates the date field format to comply with RFC 2822 > section 3.3: > using local time not UTC and using a signed four digit offset to > designate the > timezone. It relies on the Time::Local module which is distributed > with PERL so > it should be OK to assume its presence and functionality. > > Cheers, > Kurt
This patch has a flaw: the TZ offset is calculated as it was one day after the epoch. You realy need to calculate the TZ offset at the time of sending, as that would take into the account the summertime/daylight saving differences. Also some systems keep track of historical time zones so the timezone offset in 1970 may not be the same as it is today. Villy
From: Douglas K. Fischer
[guest - Mon Sep 29 11:22:20 2003]: Show quoted text
> [guest - Mon Feb 11 10:09:47 2002]: >
> > This patch updates the date field format to comply with RFC 2822 > > section 3.3: > > using local time not UTC and using a signed four digit offset to > > designate the > > timezone. It relies on the Time::Local module which is distributed > > with PERL so > > it should be OK to assume its presence and functionality. > > > > Cheers, > > Kurt
> > > This patch has a flaw: the TZ offset is calculated as it was one > day after the epoch. You realy need to calculate the TZ offset at > the time of sending, as that would take into the account the > summertime/daylight saving differences. Also some systems keep > track of historical time zones so the timezone offset in 1970 > may not be the same as it is today. > > > > Villy
Here's a cleaner patch for this: --- MIME-Lite-3.01.orig/lib/MIME/Lite.pm Thu Apr 24 19:12:13 2003 +++ MIME-Lite-3.01/lib/MIME/Lite.pm Tue Feb 8 15:41:56 2005 @@ -321,6 +321,7 @@ use Carp (); use FileHandle; +use Time::Local qw(timegm); use strict; use vars qw( @@ -1049,9 +1050,17 @@ my $ds_wanted = $params{Datestamp}; my $ds_defaulted = ($is_top and !exists($params{Datestamp})); if (($ds_wanted or $ds_defaulted) and !exists($params{Date})) { + # Per RFC 2822 Section 3.3 the timestamp must be for local time + # with a signed four-digit offset to represent time zone. + my $now = time(); + my $now_gmt = timegm(localtime($now)); + my $offset = $now_gmt - $now; + my $offset_hrs = int( $offset / 3600 ); + my $offset_min = int( $offset / 60 ) - ( $offset_hrs * 60 ); + my $offset_str = sprintf("%+.2d%02d", $offset_hrs, $offset_min); my ($u_wdy, $u_mon, $u_mdy, $u_time, $u_y4) = - split /\s+/, gmtime().""; ### should be non-locale-dependent - my $date = "$u_wdy, $u_mdy $u_mon $u_y4 $u_time UT"; + split /\s+/, localtime($now).""; ### should be non-locale-dependent + my $date = "$u_wdy, $u_mdy $u_mon $u_y4 $u_time $offset_str"; $self->add("date", $date); } -- Doug
Instead, we now use Email::Date. -- rjbs