Swiftpack.co - onevcat/AddressParser as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by onevcat.
onevcat/AddressParser 2.0.0
Email address parser.
⭐️ 69
🕓 3 years ago
.package(url: "https://github.com/onevcat/AddressParser.git", from: "2.0.0")

AddressParser

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:

and even more and mixed...

If you need a complete solution of sending mails through SMTP by Swift, see Hedwig instead.

Installation

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.

Usage

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]")),
//     ]))
// ]

License

MIT. See the LICENSE file.

GitHub

link
Stars: 69
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Swift 5
3 years ago

Drop old versions of Swift and adapt to Swift 5. #3 from @vencewill

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics