如何在mailcore2中获取邮件正文 [英] how to fetch an email body in mailcore2
问题描述
我尝试从 mailcore 迁移到 mailcore2 。以前在mailcore中,获取一个body结构就像 [msg fetchBodyStructure]
一样简单,其中msg是一个 CTCoreMessage 对象。
I've trying to migrate from mailcore to mailcore2. Previously in mailcore, fetching a body structure was as simple as [msg fetchBodyStructure]
where msg is a CTCoreMessage object.
使用mailcore2,事情似乎更复杂。在 MCOIMAPSession的获取消息体的文档,我们有:
With mailcore2, things seem to be more complex. In MCOIMAPSession's documentation for fetching a message body, we have:
MCOIMAPFetchContentOperation * op =
[session fetchMessageAttachmentByUIDOperationWithFolder:@"INBOX"
uid:[message uid]
partID:"1.2"
encoding:[part encoding]];
[op start:^(NSError * error, NSData * partData) {
}];
我绝对不知道这个 1.2
应该是指的。作者将用户引用到 RFC 822 , RFC 2822 和 RFC 5322 但是他们都没有一个直截了当的答案。
I have absolutely no idea what this 1.2
is supposed to refer to. The authors refer the users to RFC 822, RFC 2822, and RFC 5322 but none of them has a straightforward answer to the above.
有人可以给我一个简单的代码示例来获取整个邮件正文吗?
Can someone please show me a simple code sample of fetching an entire message body?
推荐答案
我不知道为什么人们会使事情变得复杂:
这是你如何使用MailCore2获取电子邮件正文:
I'm not sure why people complicate things: this is how you fetch email body with MailCore2:
MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
[session setHostname:@"imap.gmail.com"];
[session setPort:993];
[session setUsername:[UICKeyChainStore stringForKey:@"username"]];
[session setPassword:[UICKeyChainStore stringForKey:@"password"]];
[session setConnectionType:MCOConnectionTypeTLS];
MCOIMAPFetchContentOperation *operation = [session fetchMessageByUIDOperationWithFolder:@"INBOX" uid:message.uid];
[operation start:^(NSError *error, NSData *data) {
MCOMessageParser *messageParser = [[MCOMessageParser alloc] initWithData:data];
NSString *msgHTMLBody = [messageParser htmlBodyRendering];
[webView loadHTMLString:msgHTMLBody baseURL:nil];
}];
这篇关于如何在mailcore2中获取邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!