对于某些电子邮件,我想发送带标题的额外数据。就像我想知道电子邮件是否加密一样。为此,我正在设置额外的标题,如下所示。
设置额外标题
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.
检索额外标题
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())")
}
})
但我没有这样获得额外的标题.. 我在这里做错了什么。任何帮助将不胜感激。
答案 0 :(得分:0)
启动前,您必须在获取操作中指定所需的额外头。就您而言:
fetch.extraHeaders = ["Encrypted"]
然后您可以使用以下方法检索值:
mails[0].header.extraHeaderValue(forName: "Encrypted")