Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to parse mail after fetch command #76

Open
NipunBilala opened this issue Nov 9, 2017 · 2 comments
Open

how to parse mail after fetch command #76

NipunBilala opened this issue Nov 9, 2017 · 2 comments

Comments

@NipunBilala
Copy link

NipunBilala commented Nov 9, 2017

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.

@carping
Copy link

carping commented Dec 17, 2017

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

@aweissbr
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants