Fetch an Email Body in Mailcore2 Osx with Swift

How to get message body and last email in mailcore2?

   var session = MCOIMAPSession() // Make Global
session.hostname = "imap.gmail.com"
session.port = 993
session.username = "example@gmail.com"
session.password = "**********"
session.connectionType = MCOConnectionType.TLS
let requestKind: MCOIMAPMessagesRequestKind = [.headers, .flags]

var uidSet = MCOIndexSet(range: MCORangeMake(1, UINT64_MAX))

var fetchOp: MCOIMAPFetchMessagesOperation? = session.fetchMessagesByUIDOperation(withFolder: "INBOX", requestKind: MCOIMAPMessagesRequestKind.headers, uids: uidSet)

fetchOp?.start{( err, msgs, vanished) -> Void in

//print(msgs)
let msgs = msgs as? [MCOIMAPMessage]

for msgs in msgs!{

// THE uid for this email. The uid is unique for one email
let uiid = msgs.uid

useImapFetchContent(uidToFetch: uiid)

}
}

func useImapFetchContent(uidToFetch uid: UInt32)
{

let operation = session.fetchParsedMessageOperation(withFolder: "INBOX", uid: UInt32(uid))

operation?.start{( error, messageParser)-> Void in
if error == nil {
let returnValue = messageParser!.plainTextBodyRenderingAndStripWhitespace(false)
}
let subject = messageParser?.header.subject
print(subject)
let from = messageParser?.header.from
print(from)
let to = messageParser?.header.to
print(to)
let msgPlainBody = messageParser?.plainTextBodyRendering()
print("BODY")
print(msgPlainBody)
}
}

How to store extra header value with MailCore2?

editWith the help of dinhviethoa in the MailCore2 forum on GitHub (https://github.com/MailCore/mailcore2/issues/680), the question could be answered:

  • It is not possible to edit the header of an existing email.
  • However, it is possible to remove the existing message from the server and append a new message (with extra headers).

Adding MailCore2 via Carthage with Swift Support to Xcode

Need for Carthage to checkout the latest commit. Changing the Cartfile to:

github "MailCore/mailcore2" "master"

Did magic



Related Topics



Leave a reply



Submit