(Swift) Unpack HTML Email to Files
Unpacks an HTML email into an HTML file and related files (images and style sheets). The links within the HTML are updated to point to the files unpacked and saved to disk.
func chilkatTest() {
var success: Bool = false
let email = CkoEmail()!
success = email.loadEml(mimePath: "qa_data/eml/happyHour.eml")
if success != true {
print("\(email.lastErrorText!)")
return
}
// Is this an HTML email?
if email.hasHtmlBody() == true {
// Unpack the HTML to files. The image and css URLs
// in the HTML are modified to point to the files extracted to disk.
var unpackDir: String? = "qa_output/emails"
var partsSubdir: String? = "images"
var htmlFilename: String? = "happyHour.html"
success = email.unpackHtml(unpackDir: unpackDir, htmlFilename: htmlFilename, partsSubdir: partsSubdir)
if success != true {
print("\(email.lastErrorText!)")
return
}
print("Success.")
}
}
|