|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build & Test Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Build the package |
| 9 | +swift build |
| 10 | + |
| 11 | +# Run all tests |
| 12 | +swift test |
| 13 | + |
| 14 | +# Run tests with code coverage |
| 15 | +swift test --enable-code-coverage |
| 16 | +``` |
| 17 | + |
| 18 | +## Architecture Overview |
| 19 | + |
| 20 | +SwiftEmailValidator is an RFC-compliant email syntax validator supporting international email addresses. It validates email format without requiring network access. |
| 21 | + |
| 22 | +### Core Components |
| 23 | + |
| 24 | +**EmailSyntaxValidator** (`Sources/SwiftEmailValidator/EmailSyntaxValidator.swift`) |
| 25 | +- Main entry point with static methods: `correctlyFormatted()` and `mailbox()` |
| 26 | +- Returns `Mailbox` struct containing parsed `localPart` (dotAtom or quotedString) and `host` (domain or addressLiteral) |
| 27 | +- Supports three compatibility modes: `.ascii` (RFC822), `.asciiWithUnicodeExtension` (RFC2047), `.unicode` (RFC6531) |
| 28 | +- Domain validation delegated to SwiftPublicSuffixList by default, customizable via `domainValidator` closure |
| 29 | + |
| 30 | +**RFC2047Coder** (`Sources/SwiftEmailValidator/RFC2047Coder.swift`) |
| 31 | +- Encodes/decodes Unicode email addresses for ASCII-only systems |
| 32 | +- Supports Base64 ('b') and Quoted-Printable ('q') encodings |
| 33 | +- Handles utf-8, utf-16, utf-32, iso-8859-1, iso-8859-2 charsets |
| 34 | + |
| 35 | +**IPAddressSyntaxValidator** (`Sources/SwiftEmailValidator/IPAddressSyntaxValidator.swift`) |
| 36 | +- Validates IPv4 and IPv6 address literals in email hosts |
| 37 | +- Used when `allowAddressLiteral: true` is passed to validation methods |
| 38 | + |
| 39 | +### Validation Flow |
| 40 | + |
| 41 | +1. Optionally decode RFC2047 encoded input |
| 42 | +2. Extract and validate local part (before @) - either dot-atom or quoted-string format |
| 43 | +3. Extract host (after @) - either domain or address literal |
| 44 | +4. Validate domain against Public Suffix List (or custom validator) |
| 45 | +5. Return structured `Mailbox` or `nil` |
| 46 | + |
| 47 | +### Dependencies |
| 48 | + |
| 49 | +- **SwiftPublicSuffixList**: Domain validation against the Public Suffix List. First use incurs 100-900ms initialization delay. |
| 50 | + |
| 51 | +### Key Design Decisions |
| 52 | + |
| 53 | +- All public API methods are static - no instance creation needed |
| 54 | +- Returns `nil` for invalid input rather than throwing |
| 55 | +- Domain validation is pluggable via closure parameter |
| 56 | +- Character validation uses pre-built `CharacterSet` instances for efficiency |
0 commit comments