Mailcore 2无法访问除收件箱文件夹之外的gmail邮件

时间:2013-08-12 10:00:36

标签: ios objective-c gmail-imap mailcore

使用Mailcore 2,我可以访问Yahoo几乎所有文件夹的邮件,但是当我尝试使用Gmail时,它只能访问收件箱文件夹邮件。请有人知道什么是错的。

这是我的代码

if ([dict count] > 0)
            {
            myAccountsession = [[MCOIMAPSession alloc] init];
            [myAccountsession setHostname:[dict objectForKey:@"incomingserver"]];
            [myAccountsession setPort:993];
            [myAccountsession setUsername:[dict objectForKey:@"email"]];
            [myAccountsession setPassword:[dict objectForKey:@"password"]];
            [myAccountsession setConnectionType:MCOConnectionTypeTLS];
            }
 MCOIMAPMessagesRequestKind requestKind = (MCOIMAPMessagesRequestKind)
        (MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure |
         MCOIMAPMessagesRequestKindInternalDate | MCOIMAPMessagesRequestKindHeaderSubject |
         MCOIMAPMessagesRequestKindFlags);
        NSString *folder = foldernamestring;
        NSLog(@"foldername to fetch mails %@",folder);
        MCOIMAPFolderInfoOperation *inboxFolderInfo = [myAccountsession folderInfoOperation:foldernamestring];

        [inboxFolderInfo start:^(NSError *error, MCOIMAPFolderInfo *info)
         {
        //access messages in folder..
         }];

1 个答案:

答案 0 :(得分:0)

您没有使用正确的操作来检索邮件列表。您正在使用的操作(MCOIMAPFolderInfoOperation)只检索指定文件夹的元数据信息。您应该使用MCOIMAPFetchMessagesOperation而不是此操作,此操作将为您提供特定文件夹的消息列表。可以在此处找到有关此操作的更多说明(http://libmailcore.com/mailcore2/api/Classes/MCOIMAPFetchMessagesOperation.html)。

如何使用此操作检索消息的示例如下:

MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
[session setHostname:@"imap.gmail.com"];
[session setPort:993];
[session setUsername:@"ADDRESS@gmail.com"];
[session setPassword:@"123456"];
[session setConnectionType:MCOConnectionTypeTLS];

MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
NSString *folder = @"INBOX";
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)];

MCOIMAPFetchMessagesOperation *fetchOperation = [session fetchMessagesByUIDOperationWithFolder:folder requestKind:requestKind uids:uids];

[fetchOperation start:^(NSError * error, NSArray * fetchedMessages, MCOIndexSet * vanishedMessages) {
    //We've finished downloading the messages!

    //Let's check if there was an error:
    if(error) {
        NSLog(@"Error downloading message headers:%@", error);
    }

    //And, let's print out the messages...
    NSLog(@"The post man delivereth:%@", fetchedMessages);
}];