File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ extension Target.Dependency {
1212}
1313
1414extension Target . Dependency {
15+ static var rfc2822 : Self { . product( name: " RFC_2822 " , package : " swift-rfc-2822 " ) }
1516 static var rfc5321 : Self { . product( name: " RFC_5321 " , package : " swift-rfc-5321 " ) }
1617 static var rfc5322 : Self { . product( name: " RFC_5322 " , package : " swift-rfc-5322 " ) }
1718 static var rfc6531 : Self { . product( name: " RFC_6531 " , package : " swift-rfc-6531 " ) }
@@ -25,6 +26,7 @@ let package = Package(
2526 . library( name: . emailAddress, targets: [ . emailAddress] )
2627 ] ,
2728 dependencies: [
29+ . package ( url: " https://github.com/swift-web-standards/swift-rfc-2822 " , from: " 0.0.1 " ) ,
2830 . package ( url: " https://github.com/swift-web-standards/swift-rfc-5321 " , from: " 0.0.1 " ) ,
2931 . package ( url: " https://github.com/swift-web-standards/swift-rfc-5322 " , from: " 0.0.1 " ) ,
3032 . package ( url: " https://github.com/swift-web-standards/swift-rfc-6531 " , from: " 0.0.1 " ) ,
@@ -35,6 +37,7 @@ let package = Package(
3537 name: . emailAddress,
3638 dependencies: [
3739 . domain,
40+ . rfc2822,
3841 . rfc5321,
3942 . rfc5322,
4043 . rfc6531
Original file line number Diff line number Diff line change 1+ import Foundation
2+ import RFC_2822
3+ import RFC_5322
4+
5+ // MARK: - EmailAddress ↔ RFC_2822.AddrSpec Conversions
6+
7+ extension EmailAddress {
8+ /// Initialize EmailAddress from RFC 2822 AddrSpec
9+ public init ( _ addrSpec: RFC_2822 . AddrSpec ) throws {
10+ // RFC 2822 is obsoleted by RFC 5322, so we can treat the AddrSpec as RFC 5322 compatible
11+ try self . init (
12+ localPart: addrSpec. localPart,
13+ domain: addrSpec. domain
14+ )
15+ }
16+ }
17+
18+ extension RFC_2822 . AddrSpec {
19+ /// Initialize AddrSpec from EmailAddress
20+ public init ( _ emailAddress: EmailAddress ) throws {
21+ // Try to use RFC 5322 representation if available (most compatible)
22+ if let rfc5322 = emailAddress. rfc5322 {
23+ try self . init (
24+ localPart: rfc5322. localPart. stringValue,
25+ domain: rfc5322. domain. name
26+ )
27+ } else {
28+ // Fall back to RFC 6531 (most permissive)
29+ try self . init (
30+ localPart: emailAddress. rfc6531. localPart. stringValue,
31+ domain: emailAddress. rfc6531. domain. name
32+ )
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments