Skip to content

Conversation

@dhairyajangir
Copy link

Fixes

Ensures message timestamps mirror the actual send/receive time rather than the cache file’s modification time
(Fixes #912)


What’s Changed

ImapMessageFetcher.php

  • Resolves the canonical message timestamp by:

    1. Parsing the RFC 822 Date header`
    2. Falling back to IMAP INTERNALDATE if the header is missing or invalid
    3. Using the current time only as a last-resort fallback
  • The final resolved timestamp is cached and passed to IMAPMessage

  • This ensures dateInt (and all UI components depending on it) reflects the true email date, even after:

    • Mailbox restores
    • Cache rebuilds

ImapMessageFetcherTest.php

  • Adds PHPUnit test coverage for the new resolution logic

  • Confirms:

    • Preference for the RFC 822 Date header
    • Fallback to IMAP INTERNALDATE
    • Handling of malformed or missing headers
    • Final fallback behavior when no date can be determined

Testing

phpunit --filter ImapMessageFetcherTest

Signed-off-by: dhairyasquad73 <dhairya.jangir.s73@kalvium.community>
@dhairyajangir
Copy link
Author

@ChristophWurst could you please check this one!

@dhairyajangir
Copy link
Author

dhairyajangir commented Oct 31, 2025

@kesselb could you please review this one

@kesselb
Copy link
Contributor

kesselb commented Oct 31, 2025

Thanks for your pr 🙏

Relying on the date header instead of, or in addition to, the IMAP date is something I've also noticed in Thunderbird, and I think that's a reasonable approach.

@kesselb
Copy link
Contributor

kesselb commented Oct 31, 2025

Failing test:

1) OCA\Mail\Tests\Unit\IMAP\ImapMessageFetcherTest::testResolveMessageDateFallsBackToInternalOnInvalidHeader
PHP Deprecated:  SebastianBergmann\GlobalState\Snapshot::__construct(): Implicitly marking parameter $excludeList as nullable is deprecated, the explicit nullable type must be used instead in /home/runner/actions-runner/_work/mail/mail/nextcloud/apps/mail/vendor-bin/phpunit/vendor/sebastian/global-state/src/Snapshot.php on line 104
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'2025-10-20T10:00:00+00:00'
+'1969-12-31T23:59:59+00:00'

@dhairyajangir
Copy link
Author

Failing test:

1) OCA\Mail\Tests\Unit\IMAP\ImapMessageFetcherTest::testResolveMessageDateFallsBackToInternalOnInvalidHeader
PHP Deprecated:  SebastianBergmann\GlobalState\Snapshot::__construct(): Implicitly marking parameter $excludeList as nullable is deprecated, the explicit nullable type must be used instead in /home/runner/actions-runner/_work/mail/mail/nextcloud/apps/mail/vendor-bin/phpunit/vendor/sebastian/global-state/src/Snapshot.php on line 104
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'2025-10-20T10:00:00+00:00'
+'1969-12-31T23:59:59+00:00'

i'll fix this!

dhairyajangir and others added 2 commits October 31, 2025 21:55
Co-authored-by: Daniel <mail@danielkesselberg.de>
Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
Co-authored-by: Daniel <mail@danielkesselberg.de>
Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
@dhairyajangir
Copy link
Author

dhairyajangir commented Oct 31, 2025

Failing test:

1) OCA\Mail\Tests\Unit\IMAP\ImapMessageFetcherTest::testResolveMessageDateFallsBackToInternalOnInvalidHeader
PHP Deprecated:  SebastianBergmann\GlobalState\Snapshot::__construct(): Implicitly marking parameter $excludeList as nullable is deprecated, the explicit nullable type must be used instead in /home/runner/actions-runner/_work/mail/mail/nextcloud/apps/mail/vendor-bin/phpunit/vendor/sebastian/global-state/src/Snapshot.php on line 104
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'2025-10-20T10:00:00+00:00'
+'1969-12-31T23:59:59+00:00'

@kesselb To fix this, I will modify resolveMessageDate in ImapMessageFetcher.php to check if the parsed date is valid (i.e., has a positive timestamp) before returning it. If the date is invalid, it will fall back to the internal date, as intended by the test.

@dhairyajangir dhairyajangir requested a review from kesselb October 31, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mails datetime is based on the file last change time instead of arrive date

2 participants