1

使用 Mailcore 2,我可以访问 Yahoo 几乎所有文件夹的消息,但是当我尝试使用 gmail 时,它只能访问 Inbox 文件夹消息。请任何人知道出了什么问题。

这是我的代码

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..
         }];
4

1 回答 1

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);
}];
于 2013-10-10T18:08:30.220 回答