bugGNU Mailutils - Bugs: bug #61239, Timezone offset in date header...

 
 

bug #61239: Timezone offset in date header weirdness when sendmail mail

Submitter:  None
Submitted:  Tue 28 Sep 2021 07:43:03 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  gray
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 10 Oct 2024 10:08:34 AM UTC, comment #6: 
Sergey Poznyakoff <gray>
Group administrator
Mon 07 Oct 2024 11:59:01 PM UTC, comment #5: 

Ignore that last post - as I suspected, I didn't understand what it was doing and why ...

Having slept on it, here's an update that works and has been tested with different times and time zones, including testing for month and year boundaries, DST changes et c.

*** libmailutils/datetime/utcoff.c.orig        2024-01-07 01:55:12.000000000 +1300
--- libmailutils/datetime/utcoff.c        2024-10-08 12:47:53.290458478 +1300
***************
*** 19,26 ****
  #endif
  #include <time.h>

! #define SECS_PER_DAY 86400
! #define TMSEC(t) (((t)->tm_hour * 60 + (t)->tm_min) * 60 + (t)->tm_sec)

  /* Returns the offset of our timezone from UTC, in seconds. */
  int
--- 19,25 ----
  #endif
  #include <time.h>

! #define TMSEC(t) ((t)->tm_mday * 86400 + (t)->tm_hour * 3600 + (t)->tm_min * 60 + (t)->tm_sec)

  /* Returns the offset of our timezone from UTC, in seconds. */
  int
***************
*** 29,38 ****
    time_t t = time (NULL);
    struct tm ltm = *localtime (&t);
    struct tm gtm = *gmtime (&t);
!   int d = TMSEC (&ltm) - TMSEC (&gtm);
!   if (d < 0 && -d > SECS_PER_DAY/2)
!     d += SECS_PER_DAY;
!   else if (d > SECS_PER_DAY/2)
!     d -= SECS_PER_DAY;
!   return d;
  }
--- 28,36 ----
    time_t t = time (NULL);
    struct tm ltm = *localtime (&t);
    struct tm gtm = *gmtime (&t);
!   if(gtm.tm_mday == 1 && ltm.tm_mday > 2)
!     ltm.tm_mday = 0;
!   else if(ltm.tm_mday == 1 && gtm.tm_mday > 2)
!     gtm.tm_mday = 0;
!   return TMSEC (&ltm) - TMSEC (&gtm);
  }

Basically, this eliminates the +/- 12 hour range check completely by using the day of the month to account for day changes; we then detect month boundaries and adjust accordingly (converting the last day of the month to 0 if necessary).

Anonymous
Mon 07 Oct 2024 07:47:30 AM UTC, comment #4: 

I'm not entirely sure what the range check in libmailutils/datetime/utcoff.c is even trying to achieve - it's like it doesn't trust what gmtime() and locatime() are returning. Nevertheless, I have applied the following patch to my copy of the latest source:

*** libmailutils/datetime/utcoff.c.bak        2024-01-07 01:55:12.000000000 +1300
--- libmailutils/datetime/utcoff.c        2024-10-07 20:04:18.174110751 +1300
***************
*** 20,25 ****
--- 20,26 ----
  #include <time.h>

  #define SECS_PER_DAY 86400
+ #define MAXTZOFF 50400 /* 14 hours */
  #define TMSEC(t) (((t)->tm_hour * 60 + (t)->tm_min) * 60 + (t)->tm_sec)

  /* Returns the offset of our timezone from UTC, in seconds. */
***************
*** 32,38 ****
    int d = TMSEC (&ltm) - TMSEC (&gtm);
    if (d < 0 && -d > SECS_PER_DAY/2)
      d += SECS_PER_DAY;
!   else if (d > SECS_PER_DAY/2)
      d -= SECS_PER_DAY;
    return d;
  }
--- 33,39 ----
    int d = TMSEC (&ltm) - TMSEC (&gtm);
    if (d < 0 && -d > SECS_PER_DAY/2)
      d += SECS_PER_DAY;
!   else if (d > MAXTZOFF)
      d -= SECS_PER_DAY;
    return d;
  }


In short, I've allowed for offets of up to +14 hours, since +14 is the time zone for Kiribati, and I believe the highest likely timezone offset. Samoa and NZ daylight time are +13; Chatham Island standard time is 12:45 and daylight time +13:45 (yes, really). Again, I'm not sure what this code is trying to protect against so this may break something ... but it appears to solve my immediate problem.

Anonymous
Mon 07 Oct 2024 06:23:02 AM UTC, comment #3: 

I'm using mailutils 3.14 and still experiencing a problem. Timezone is set to Pacific/Auckland, and since it's daylight saving, the timezone is UTC+13:00. Messages sent through /usr/bin/mail are showing the correct time in the Date: line, but the time zone shows as -1100, rather than +1300, which makes the date 24 hours out ... and triggering "date in the future" spam detection.

Basically, I'm seeing the symptoms observed in comment #2.

Anonymous
Thu 08 Feb 2024 06:41:34 AM UTC, comment #2: 

I think there might still be an issue here - in particular with time zones above UTC+12. I'm currently in NZDT (UTC+13) and I've noticed that all the emails that are sent with the 'mail' command have the time zone in the 'Date' header set to -1100. I think the issue is with the 'else if (d > SECS_PER_DAY/2)' line since this will always be true for time zone offsets above UTC+12 and so it subtracts SECS_PER_DAY making my UTC+13 become UTC-11.

Anonymous
Thu 30 Sep 2021 04:23:42 AM UTC, comment #1: 
Sergey Poznyakoff <gray>
Group administrator
Tue 28 Sep 2021 07:43:03 PM UTC, original submission:  

The introduction of message_add_date in GNU Mailutils 3.13, may lead to weirdness in the timezone offset in Date headers added when sending messages (eg "Date: Sat, 7 Aug 2021 23:00:01 +4400"). I believe the problem arises in mu_utc_offset() in libmailutils/datetime/utcoff.c when the day (or month or year) of the GMT date differs from that of the localtime date.

For example, consider a message being sent at 2005 EDT / 0005 UTC. In mu_utc_offset, TMSEC(&ltm) equals 72300 and TMSEC(&gtm) equals  300. Initially, d is assigned 72000. But since ltm.tm_mday does not equal gtm.tm_mday, the function adds a day's worth of seconds to it and returns 158400. And in turn, mu_c_streamftime() generates the timezone offset in the date header by converting that to hours (44 = 158400/(60*60)) and minutes (0 = (158400/60)%60).

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by gray (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-09-30 gray StatusNone Fixed
        Assigned toNone gray

    Back to the top

    Powered by Savane 3.14-8e77.
    Corresponding source code