Skip to content

feat: add RFC 5322 compliant email address parser ($400 bounty)#17

Open
zhangjiayang6835-cyber wants to merge 1 commit into
UnsafeLabs:mainfrom
zhangjiayang6835-cyber:feat/email-address-parser
Open

feat: add RFC 5322 compliant email address parser ($400 bounty)#17
zhangjiayang6835-cyber wants to merge 1 commit into
UnsafeLabs:mainfrom
zhangjiayang6835-cyber:feat/email-address-parser

Conversation

@zhangjiayang6835-cyber
Copy link
Copy Markdown

Summary

Implements a fully RFC 5322 compliant email address parser in Python, covering sections 3.2 through 3.4 with obsolete syntax support from §4.4.

Files

  • parser.py: Complete parser with AddressParser class and RFC5322Address data class
  • test_parser.py: 46 unit tests covering all grammar rules

Parser Capabilities

  • addr-spec: user@domain, user+tag@domain, a.long.local.part@sub.domain.co.uk
  • name-addr: John Doe <john@example.com>, "Smith, John" <john@example.com>
  • ✅ Quoted strings: "john doe"@example.com with escaped quotes/backslashes
  • ✅ Domain literals: user@[192.168.1.1], user@[IPv6:2001:db8::1]
  • ✅ Comments (nested supported): John (CEO) <john@example.com>
  • ✅ Folding whitespace: multi-line with CRLF folding
  • ✅ Groups: Developers: alice@a.com, bob@b.com;
  • ✅ Address lists: a@x.com, b@y.com
  • ✅ Obsolete syntax: obs-local-part, obs-domain, obs-angle-addr
  • ✅ Input validation: rejects consecutive dots, leading/trailing dots, double @

Testing

$ python3 -m unittest test_parser -v
Ran 46 tests in 0.003s
OK

Test Coverage

Category Tests Description
Basic addr-spec 7 Simple, dots, +tag, atext chars
Name-addr 5 Display names, angles
Quoted-string 4 Spaces, escapes, backslash
Domain-literals 3 IPv4, IPv6, text
Multiple addresses 3 Lists
Groups 3 Basic, empty, with comments
Comments 3 After addr, in name, nested
Edge cases 5 Case, single char, minimal
Invalid inputs 6 Empty, no @, double @, dots
Obsolete syntax 2 obs-local, obs-domain
Real-world 3 Standard, multi-word, complex

Closes #1

Implement a complete email address parser conforming to RFC 5322
sections 3.2–3.4 with obsolete syntax from §4.4.

Features:
- Full ABNF grammar: addr-spec, mailbox, name-addr, group, angle-addr
- Comment and folding whitespace (CFWS/FWS) handling
- Quoted-string local parts with quoted-pair escape sequences
- Domain literals (IPv4, IPv6, text)
- Display names (plain and quoted)
- Address lists and group syntax
- Obsolete syntax fallbacks (§4.4)
- Nested comments support
- 46 comprehensive unit tests covering all grammar rules

Closes UnsafeLabs#1
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.

[bounty $400] Implement ABNF-compliant email address parser with full §3.2–§4.4 coverage

1 participant