I’m having trouble accessing Gmail folders using MailCore2. The INBOX folder works perfectly but when I try to fetch messages from other folders I get this error: “The requested folder does not exist. Folder selection failed”. This same code works fine with other email providers but Gmail seems to be different. Here’s my code for getting the folder list:
_emailSession = [EmailHelper getIMAPConnection];
[[_emailSession getAllFoldersOperation] start:^(NSError *err, NSArray *allFolders) {
[[SharedFolders instance].directories removeAllObjects];
for (MCOIMAPFolder *directory in allFolders) {
NSArray *parts = [directory.path componentsSeparatedByString:[NSString stringWithFormat:@"%c", directory.delimiter]];
NSString *dirName = [parts lastObject];
const char *charString = [dirName cStringUsingEncoding:[NSString defaultCStringEncoding]];
dirName = [NSString stringWithCString:charString encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF7_IMAP)];
[directories addObject:dirName];
NSLog(@"Found folder: %@", dirName);
}
}];
I can see all folders including Gmail-specific ones like “Sent Mail”, “All Mail”, “Trash” etc. But when I try to fetch messages from these folders:
MCOIMAPSession *connection = [EmailHelper getIMAPConnection];
if (!connection) return;
MCOIMAPMessagesRequestKind kind = MCOIMAPMessagesRequestKindHeaders;
MCOIndexSet *messageIds = [MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)];
MCOIMAPFetchMessagesOperation *operation = [connection fetchMessagesOperationWithFolder:selectedFolder requestKind:kind uids:messageIds];
[operation start:^(NSError *err, NSArray *messages, MCOIndexSet *removedMessages) {
if(err) {
NSLog(@"Failed to get messages: %@", err);
if (callback) callback(NO);
}
Only INBOX works but other folders throw the “folder does not exist” error. What am I missing for Gmail folders?