Search code examples
mailcore2

Mailcore: plainTextBodyRenderingOperationWithMessage returns nil


I'm using plainTextBodyRenderingOperationWithMessage to get summaries for my messages. I run it when the user logs in and then I run it again when the user scrolls to a certain point. The second time I run it it works perfectly. The first time I run it it only gets some message summaries. The htmlString returned for over half the messages is nil and I receive an error:

Error Domain=MCOErrorDomain Code=19 "An error occured while fetching messages in the requested folder." UserInfo=0x168a1260 {NSLocalizedDescription=An error occured while fetching messages in the requested folder

I turned on connection logger but I don't get anything useful - it just prints the html for the messages it can get.

The strange part is that I'm getting these errors only the first time I make the call and the code for both is identical.

Below is my code.

MCOIMAPMessageRenderingOperation * op = [session plainTextBodyRenderingOperationWithMessage:message folder:self.folderpath];

[op start:^(NSString * htmlString, NSError * error) {
    NSLog(@"Error getting summary: %@", error);
}];

I have also tried htmlBodyRenderingOperationWithMessage with the same result.


Solution

  • I should have paid more heed to the error message. 'An error occurred while fetching messages in the requested folder'. The path I was passing as the folder parameter was NULL. It's still a little strange that, despite it being NULL the method managed to get some data successfully, however once I fixed that it worked correctly.