Question

How to retrieve the .xml extension attachments from mail by using MailCore for iphone?

I used MailCore to download the attachments from my mail to my sample iPhone app. I getting Inbox subjects from my mail that subjects I sort to get particular mail subject and mail attachments.

The problem is I got particular mail subject but not attachments. I used below code to get attachments from mail but it's not working.

NSArray *Array=[msg attachments];
CTBareAttachment *ctbaratt=[Array objectAtIndex:0];
CTCoreAttachment *ctcoreatt=[ctbaratt fetchFullAttachment];

but I'm getting :

Array count is zero

Please share your ideas.

Was it helpful?

Solution

This could be for a few reasons:

1)It is possible that you're not downloading enough information about the CTCoreMessage. When making a request to download the CTCoreMessages you must specify what information you want by specifying the correct fetch attributes.

For example:

[core_folder messagesFromSequenceNumber:from to:to withFetchAttributes: CTFetchAttrEnvelope | CTFetchAttrBodyStructure]

should populate the information about the attachments.

When fetching a message from IMAP, the command will specify exactly what information it wants.

you can see what is being fetched by enabling MailCore Logging as follows:

MailcoreEnableLogging();
[core_folder messagesFromSequenceNumber:from to:to withFetchAttributes: CTFetchAttrEnvelope | CTFetchAttrBodyStructure];
MailcoreDisableLogging();

You will see commands of the format

<command number> <UID> <Command> (<requested structure>)

I imagine you will see something like this:

1 UID FETCH (ENVELOPE)

You should ensure that inside the () either BODY or BODY[2] or RFC822 as these will contain information about attachments.

When you see what is actually being fetched you can read the RFC, if you are dealing with mailcore and IMAP then it is well worth the investment in time.

2)Failing that, perhaps your CTCoreAccount and/or CTCoreFolder are not connected, thus preventing the CTCoreMessage from having a valid mailimapsession and being unable to download the attachment information. If an attribute inside a CTCoreMessage is not available then libetpan should download it on request. The fact that is it not suggests that your account or folder may be not valid or connected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top