Postal icon indicating copy to clipboard operation
Postal copied to clipboard

how to parse mail after fetch command

Open NipunBilala opened this issue 8 years ago • 2 comments

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.

NipunBilala avatar Nov 09 '17 10:11 NipunBilala

message.body?.allParts.forEach { part in
    if part.mimeType.description == "text/html" {
        part.data?.decodedData // HTML Data
    }
}

carping avatar Dec 17 '17 15:12 carping

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:

  1. login - ok
  2. 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!")
            }
        })
  1. 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?

aweissbr avatar Jul 10 '18 12:07 aweissbr