Add RFC 5322 compliant Message-ID header to email notifications #1557
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements automatic generation of RFC 5322 compliant Message-ID headers for all email notifications sent by diun.
Currently, diun email notifications do not include a Message-ID header, which can cause issues with:
Changes
New function
generateMessageID()ininternal/notif/mail/client.go:<timestamp.randomhex@domain>LocalNameconfig if set, otherwise falls back toHostIntegration in
Send()method:mailMessage.SetHeader("Message-ID", messageID)Comprehensive unit tests in
internal/notif/mail/client_test.go:TestGenerateMessageID: Validates format with LocalName and Host fallbackTestGenerateMessageID_Uniqueness: Verifies uniqueness across 1000 iterationsTestGenerateMessageID_Format: Validates RFC 5322 format complianceBenefits
✅ Improves email threading and tracking in mail clients
✅ Enhances spam filter compatibility
✅ Ensures RFC 5322 compliance for all outgoing notifications
✅ Each message gets a globally unique identifier
Testing
All tests pass successfully:
Tested with:
docker buildx bake testImplementation Details
The Message-ID generation follows RFC 5322 best practices:
<local-part@domain>Example generated Message-ID: