Reputation: 831
For some emails i want to send extra data with headers. Like I want to know that an email is encrypted or not. For this purpose i am setting extra header like below.
Setting extra header
let mailBuilder: MCOMessageBuilder! = MCOMessageBuilder()
mailBuilder.header.subject = "Subject"
mailBuilder.header.setExtraHeaderValue("yes", forName: "Encrypted")
// set rest of data. From,TO,CC,Body etc and send email.. // Email sending is working properly.
Retrieving extra header
func fetchRequestKind () -> MCOIMAPMessagesRequestKind {
let kind = MCOIMAPMessagesRequestKind()
let headers = kind.union(MCOIMAPMessagesRequestKind.headers)
let structure = headers.union(MCOIMAPMessagesRequestKind.structure)
let request = structure.union(MCOIMAPMessagesRequestKind.flags)
let requestHeader = request.union(MCOIMAPMessagesRequestKind.extraHeaders)
return requestHeader
}
let request = self.fetchRequestKind()
let messagesNumbers = MCOIndexSet.init() // range get set here
let fetch : MCOIMAPFetchMessagesOperation = self.imapSession.fetchMessagesByNumberOperation(withFolder: "Inbox", requestKind:request, numbers: messagesNumbers)
fetch.start({ (error, fetchedMessages, vanishedMessages) in
if(error != nil)
{
failure(error.debugDescription)
} else {
if let mails = fetchedMessages as? [MCOIMAPMessage] {
print("\(mails[0].header.subject) &&& \(mails[0].header.allExtraHeadersNames())")
}
})
But i am not getting extra headers this way.. What i am doing wrong here.? Any help would be appreciated.
Upvotes: 0
Views: 173
Reputation: 36
You have to specify the extra header you want in the fetch operation before you start it. In your case:
fetch.extraHeaders = ["Encrypted"]
Then you can retrieve the value with:
mails[0].header.extraHeaderValue(forName: "Encrypted")
Reference: https://github.com/MailCore/mailcore2/issues/1288
Upvotes: 1