Email address parser.
This framework is a component of Hedwig,
which is a cross platform Swift SMTP email client framework.
When sending an email, you need to specify the receipt address. The address
field could be one of these forms below:
[email protected]
Wei Wang <[email protected]>
[email protected], [email protected]
My Group: [email protected], [email protected];
and even more and mixed…
If you need a complete solution of sending mails through SMTP by Swift, see
Hedwig instead.
Add the url of this repo to your Package.swift
:
import PackageDescription
let package = Package(
name: "YourAwesomeSoftware",
dependencies: [
.Package(url: "https://github.com/onevcat/AddressParser.git",
majorVersion: 1)
]
)
Then run swift build
whenever you get prepared.
You could know more information on how to use Swift Package Manager in Apple’s
official page.
Use AddressParser.parse
to parse an email string field to an array of Address
.
An Address
struct contains the name of that address and an entry to indicate
whether this is a mail address or a group.
import AddressParser
let _ = AddressParser.parse("[email protected]")
// [Address(name: "", entry: .mail("[email protected]"))]
let _ = AddressParser.parse("Wei Wang <[email protected]>")
// [Address(name: "Wei Wang", entry: .mail("[email protected]"))]
let _ = AddressParser.parse("[email protected], [email protected]")
// [
// Address(name: "", entry: .mail("[email protected]"))
// Address(name: "", entry: .mail("[email protected]"))
// ]
let _ = AddressParser.parse("My Group: [email protected], [email protected];")
// [
// Address(name: "MyGroup", entry: .group([
// Address(name: "", entry: .mail("[email protected]")),
// Address(name: "", entry: .mail("[email protected]")),
// ]))
// ]
MIT. See the LICENSE file.