Skip to content

Commit

Permalink
add mailToMetaData method for URL
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSteven committed Nov 8, 2023
1 parent 2c6d82b commit 2e81bd2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions MemoryChainKit/Sources/Extensions/Foudantion/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,27 @@ extension URL.Scheme {
}


public struct MailToMetaData {
public let to:String
public let headers:[String:String]
}
public extension URL {
func mailToMetaData() ->MailToMetaData? {
guard scheme == "mailto",let components = URLComponents(url: self, resolvingAgainstBaseURL: false) else {
return nil
}
let toMail = components.path
let queryItems = components.queryItems
var headers = [String:String]()
guard let queryItems = queryItems else {
if toMail.isEmpty {
return nil
}
return MailToMetaData(to: toMail, headers: headers)
}
queryItems.forEach{ queryItem in guard let value = queryItem.value else {return}
headers[queryItem.name] = value
}
return MailToMetaData(to: toMail, headers: headers)
}
}

0 comments on commit 2e81bd2

Please sign in to comment.