Skip to content

Fix SMTPUTF8 test to actually test non-ASCII email addresses#40

Open
matrixise wants to merge 2 commits intomainfrom
fix-smtputf8-test
Open

Fix SMTPUTF8 test to actually test non-ASCII email addresses#40
matrixise wants to merge 2 commits intomainfrom
fix-smtputf8-test

Conversation

@matrixise
Copy link
Copy Markdown
Owner

@matrixise matrixise commented Jan 7, 2026

Summary

Fixes the test_smtputf8_support test to actually test SMTPUTF8 (RFC 6531) functionality by using non-ASCII characters in email addresses, not just in message bodies.

Background

As pointed out in issue #5, the previous test claimed to test SMTPUTF8 support but only used ASCII email addresses (user@example.com, recipient@example.com) and UTF-8 characters in the message body. This doesn't test what SMTPUTF8 is designed for.

SMTPUTF8 (RFC 6531) allows non-ASCII characters in email addresses themselves, such as:

  • prénom@société.fr (French accented characters)
  • usuario@例え.jp (Japanese characters)

Changes

  • Use actual non-ASCII email addresses: expéditeur@société.fr and destinataire@例え.jp
  • Use EmailMessage: Switched from manual message construction to EmailMessage which uses modern email policy and properly handles SMTPUTF8
  • Automatic SMTPUTF8: Use send_message() which automatically enables SMTPUTF8 when non-ASCII addresses are detected
  • Verify envelope addresses: Check the X-MailFrom and X-RcptTo headers added by dsmtpd, which contain the actual SMTP envelope addresses
  • Proper header decoding: Add MIME header decoding to correctly verify UTF-8 content

Test Results

All tests pass:

tests/test_server_integration.py::test_smtputf8_support PASSED

The test now properly verifies that:

  1. SMTPUTF8 is announced in EHLO response
  2. Non-ASCII email addresses are accepted
  3. UTF-8 addresses are correctly preserved in envelope headers
  4. UTF-8 content is preserved in message body

Related

Addresses feedback on issue #5

The previous test claimed to test SMTPUTF8 (RFC 6531) support but only
used ASCII email addresses and UTF-8 in the message body. This doesn't
test what SMTPUTF8 is designed for: supporting non-ASCII characters in
email addresses themselves.

Changes:
- Use non-ASCII email addresses: expéditeur@société.fr and destinataire@例え.jp
- Switch from manual message construction to EmailMessage with modern policy
- Use send_message() which automatically enables SMTPUTF8 when needed
- Verify UTF-8 addresses are preserved in X-MailFrom and X-RcptTo headers
- Add proper MIME header decoding for verification

This addresses the valid concern raised in issue #5 about properly
testing SMTPUTF8 functionality.
@matrixise matrixise mentioned this pull request Jan 7, 2026
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.

1 participant