我仍在尝试通过复制邮件并将标题添加到新邮件中来为邮件添加自定义标头(另请参阅我未回答的问题mailcore2: Adding a custom header to IMAP message doesn't work (newly written to the IMAP server))。
对于带附件的邮件,此功能已经有效。原始邮件的附件将复制到新邮件,包括(普通)文本邮件,也是附件。大! : - )
现在我尝试对没有任何附件的邮件执行相同的操作。当我查看原始邮件的来源时,标题是:
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
现在我尝试使用以下代码(Swift 3)将邮件正文复制为附件:
let abstractMainPart: MCOAbstractPart = messageParser.mainPart()
if abstractMainPart.partType == MCOPartType.single {
let attachment: MCOAttachment = abstractMainPart as! MCOAttachment
messageBuilder.addAttachment(attachment)
}
然后我用
发送消息let appendOp = self.imapSession.appendMessageOperation(withFolder: withFolder, messageData: messageBuilder.data(), flags: MCOMessageFlag(rawValue: 0), customFlags: ["$label1"])
appendOp?.start{ (err, createdUid) in
log.debug("error from server \(err)")
log.debug("created uid: \(createdUid)")
}
问题是,在新邮件中,文本被base64编码的文本替换。标题说:
Content-Type: text/plain; charset=ISO-8859-1
[...many header lines...]
Content-Type: text/plain
Content-Transfer-Encoding: base64
如何阻止从普通的ISO-8859-1文本转换为base64编码的文本?
或者替代方法:如何在没有任何展平的情况下获取纯文本字符串,从原始邮件或原始附件中删除空格,HTML呈现等???