8000 Fix: fall back to INTERNALDATE when Date header is missing or invalid by alanpbaldwin · Pull Request #28 · dominicgisler/imap-spam-cleaner · GitHub
[go: up one dir, main page]

Skip to content

Fix: fall back to INTERNALDATE when Date header is missing or invalid - #28

Merged
dominicgisler merged 4 commits into
dominicgisler:masterfrom
alanpbaldwin:fix/missing-date-header-fallback
Mar 30, 2026
Merged

dominicgisler merged 4 commits into
dominicgisler:masterfrom
alanpbaldwin:fix/missing-date-header-fallback

Conversation

@alanpbaldwin
Copy link
Copy Markdown
Contributor

Summary

  • Emails with a missing Date header are silently skipped because Header.Date() returns a zero time, which always falls outside the maxage range check
  • Emails with an invalid/unparseable Date header are also skipped because Header.Date() returns an error and the code does continue
  • Both cases allow obvious spam (which frequently omits or malforms the Date header) to evade scanning entirely

This PR falls back to the IMAP INTERNALDATE when the Date header is missing or unparseable, ensuring these emails are still scanned.

Fixes #26

Emails without a Date header get a zero time from go-message's
Header.Date(), which silently passes the error check (returns nil
error) but then always fails the maxage range check. These messages
are skipped every scan cycle and never sent to the spam provider.

This is actively exploited by spam in the wild — phishing emails
spoofing well-known brands commonly omit Date (and Message-ID)
headers, making them invisible to the scanner.

The fix requests INTERNALDATE in the IMAP fetch options and falls
back to it when the parsed Date is zero. INTERNALDATE is the
server-received timestamp and is always present per RFC 3501.

Fixes dominicgisler#26
Builds for amd64 and arm64, publishes to ghcr.io.
The previous fix handled missing Date headers (zero time) but not
invalid ones. Spam commonly uses malformed dates like "24:45:17 0500"
which cause a parse error — these were still being skipped.

Now both cases (missing and invalid Date) fall back to INTERNALDATE
instead of skipping the message.
@dominicgisler
Copy link
Copy Markdown
Owner

Thanks for the PR. Please remove the additional workflow, then I'll gladly merge it back.

The build-fork.yml workflow was only needed for building the patched
Docker image on the fork. Not appropriate for the upstream repo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dominicgisler
dominicgisler merged commit 885a96d into dominicgisler:master Mar 30, 2026
1 check passed
@alanpbaldwin
alanpbaldwin deleted the fix/missing-date-header-fallback branch October 9, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emails with missing Date header are silently skipped, never scanned

2 participants

0