how to parse mail after fetch command
I am able to fetch the mail with header,body. But after fetching the mail how to parse the data? Following is my code
postal.fetchLast("INBOX", last: 1, flags: [ .headers,.size,.fullHeaders,.body ], onMessage: { message in
print("new email uid: \(message.uid)")
print("new email body: \(message.body)")
}
How to parse this data received??
I mean basically how can i parse the mail to display in a viewer.
message.body?.allParts.forEach { part in
if part.mimeType.description == "text/html" {
part.data?.decodedData // HTML Data
}
}
Hello and thank you for great framework and your time invested in. I used MailCore2 framework for a while for fetching and recognition of messages for given keywords. Works until today fine, but i would not say i'm happy with, because of Objective-C wrapper behind, working actually with Swift today.
To my problem:
How can i get mail pdf attachments with fetchAttachments fetch request?
What i do:
- login - ok
- fetching headers - ok, with logger i already see all pdf attachments
let extraHeaders = Set.init(["Received", "DKIM-Signature"])
self.postal.fetchMessages("INBOX", uids: indexset as IndexSet, flags: [.fullHeaders, .body, .structure], extraHeaders: extraHeaders, onMessage: { (message) in
self.messages.append(message)
}, onComplete: { error in
if let error = error {
print("Fail to receive message headers with error = \(error.localizedDescription)")
} else {
print("Request header successed!")
}
})
- fetch attachments for some mails:
recognizedMessages.forEach { (message) in
message.body?.allParts.forEach({ (part) in
self.postal.fetchAttachments("INBOX", uid: message.uid, partId: part.id, onAttachment: { (mailData) in
if !mailData.rawData.isEmpty {
let decodedData = mailData.decodedData
let attachmentStr = String(data: decodedData, encoding: String.Encoding.utf8)
}
}, onComplete: { error in
if let error = error {
print("Fail to receive message attachment with error = \(error.localizedDescription)")
} else {
print("Fetch attachment successed!")
}
})
}
I get ONLY attachments text/plain + text/html as one responce
What i'm missing in my Code?