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.
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) {
}];
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?
I'm not sure why people complicate things: this is how you fetch email body with MailCore2:
You want RFC 3501, part 6.4.5 - Fetch Command, specifically
BODY[<section>]
. The number refers to segments of the MIME structure of the message.For example, if your messages mime structure looks like this, a common format:
The parts and subparts are numbered recursively like this:
For a more complicated format, eg, with an attachment:
If you want the entirety of the message, the part number is normally left blank. Or you can use
TEXT
if you want the entirety of the message, but without the headers.