Skip to content

Commit 0c2487e

Browse files
committed
Updated documentation
1 parent 521eaed commit 0c2487e

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

CLAUDE.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ You can use The Swift Package Manager to install SwiftEmailValidator by adding i
2222
]
2323
)
2424

25+
## Performance Considerations
26+
27+
Due to the high number of entries in the Public Suffix list (>9k), the first email validation may add 100ms to 900ms depending on the device. To avoid this delay affecting user experience, you can pre-load the rules on a background thread soon after launching the app:
28+
29+
import SwiftPublicSuffixList
30+
31+
DispatchQueue.global(qos: .utility).async {
32+
_ = PublicSuffixRulesRegistry.rules
33+
}
34+
2535
## Public Suffix List
2636

2737
By default, domains are validated against the [Public Suffix List](https://publicsuffix.org) using the [SwiftPublicSuffixList](https://github.com/ekscrypto/SwiftPublicSuffixList) library.
2838

2939
### Notes:
30-
* Due to the high number of entries in the Public Suffix list (>9k), the first validation may add 100ms to 900ms depending on the device you are using. If this is unacceptable you can
31-
pre-load on a background thread PublicSuffixRulesRegistry.rules prior to using EmailSyntaxValidator.
3240
* The [Public Suffix List](https://publicsuffix.org) is updated regularly. If your application is published regularly you may be fine by simply pulling the latest version of the SwiftPublicSuffixList library. However it is recommended to have
3341
your application retrieve the latest copy of the public suffix list on a somewhat regular basis. Details on how to accomplish this are available in the [SwiftPublicSuffixList](https://github.com/ekscrypto/SwiftPublicSuffixList) library page. You can then use the domainValidator parameter to specify the closure to use for the domain validation. See "Using Custom SwiftPublicSuffixList Rules" below.
3442
* You can bypass the Public Suffix List altogether and use your own custom Regex if desired. See "Bypassing SwiftPublicSuffixList" below.

0 commit comments

Comments
 (0)