Skip to content

Timezone bug in either rcube_utils::anytodatetime() or zipdownload::_download_messages() #10147

@gurnec

Description

@gurnec

Prerequisites

  • I have searched for duplicate or closed issues
  • I can recreate the issue with all plugins disabled

Describe the issue

This is in regards to the zipdownload plugin's Export -> Mbox format. Each email in this format is prefaced by an arrival-time header:

From user@example.com Sat Apr 18 14:19:20 2026

The header doesn't include a timezone, but I believe the intent is for UTC?

In zipdownload, this line is formatted by:

$timezone = new \DateTimeZone('UTC');

$date = rcube_utils::anytodatetime($headers->internaldate, $timezone);
if ($date) {
$date = $date->format(self::MBOX_DATE_FORMAT);
}

Which calls into rcube_utils::anytodatetime:

if (!empty($date)) {
try {
$_date = preg_match('/^[0-9]+$/', $date) ? "@{$date}" : $date;
$dt = $timezone ? new \DateTime($_date, $timezone) : new \DateTime($_date);
} catch (\Exception $e) {
// ignore
}
}
// try our advanced strtotime() method
if (!$dt && ($timestamp = self::strtotime($date, $timezone))) {
try {
$dt = new \DateTime('@' . $timestamp);
if ($timezone) {
$dt->setTimezone($timezone);
}

Typically, line 1176 above succeeds in parsing a string from IMAP, however if that string contains a timezone, the DateTimeZone('UTC') parameter is ignored. This is returned and format()ed by zipdownload without any timezone string, however the DateTime object still stores the originally parsed timezone, and the resulting string is in that timezone.

Note also that if the initial conversion in anytodatetime() fails and strtotime succeeds instead, the result is converted to the requested timezone on line 1187.

Should line 1187 apply to both cases in anytodatetime()? Should zipdownload call setTimezone() instead?

What browser(s) are you seeing the problem on?

Chrome

What version of PHP are you using?

v8.3

What version of Roundcube are you using?

v1.7-rc6

JavaScript errors

No response

PHP errors

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions