How to get email body in mailcore2

I am trying to switch from mailcore to mailcore2 . Earlier in mailcore, fetching the body structure was as simple as [msg fetchBodyStructure] , where msg is the CTCoreMessage object.

With mailcore2, things look more complicated. In the MCOIMAPSession documentation for receiving the message body, we have:

 MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentByUIDOperationWithFolder:@"INBOX" uid:[message uid] partID:"1.2" encoding:[part encoding]]; [op start:^(NSError * error, NSData * partData) { }]; 

I absolutely do not know what this 1.2 should relate to. The authors cite users of RFC 822 , RFC 2822 , and RFC 5322 , but not one of them has a direct answer to the above.

Can someone please show me a simple code example to get the whole message body?

+4
source share
2 answers

I'm not sure why people complicate things: this is how you get the 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]; }]; 
+14
source

You want RFC 3501, part 6.4.5, to be a Fetch command, in particular BODY[<section>] . The number refers to the segments of the MIME structure of the message.

For example, if your message mime structure looks like this, the general format is:

 multipart/alternative |- text/plain \- text/html 

Details and substrings are numbered recursively:

 multipart/alternative (top-level) |- text/plain (Part 1) \- text/html (Part 2) 

For a more complex format, for example, with the application:

 multipart/mixed (top-level) |- multipart/alternative (Part 1) | |- text/plain (Part 1.1) | \- text/html (Part 1.2) \- image/jpeg (Part 2) 

If you require a complete message, the part number is usually left blank. Or you can use TEXT if you want to get the full message, but without headers.

0
source

Source: https://habr.com/ru/post/1495118/


All Articles