使用MailCore2检索最新的电子邮件

时间:2015-01-20 21:18:04

标签: ios mailcore2

我正在加载我的最新电子邮件,而且我保存了最新的UID,因为稍后如果用户重新加载电子邮件列表我想要从该UID获取所有电子邮件到现在......为此,我正在使用

UInt64 start = lUid;
UInt64 end = UINT64_MAX;

MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(start, end)];

MCOIMAPFetchMessagesOperation *fetchOperation = [imapSession fetchMessagesOperationWithFolder:@"INBOX"
                                                                                  requestKind:requestKind
                                                                                         uids:uids];

此操作始终返回结果,但我收到了最新的电子邮件...所以我试图制作

UInt64 start = lUid + 1;

但它完全一样。

修改

我正在查看记录器,最后一个UID是34038所以当我拨打电话时,启动参数是34039 ...所以为什么我收到ID为34038的电子邮件?

2015-01-20 18:33:06.852 App[25022:730644] mailcore - IMAP: 8 UID FETCH 34039:* (UID ENVELOPE BODY.PEEK[HEADER.FIELDS (References)])

任何人都知道发生了什么事?

编辑2: 所以这是我的代码

UInt64 start = lUid + 1;
UInt64 end = UINT64_MAX;

MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(start, end)];

MCOIMAPFetchMessagesOperation *fetchOperation = [imapSession fetchMessagesOperationWithFolder:@"INBOX"
                                                                                  requestKind:requestKind
                                                                                         uids:uids];

void(^fetchHandler)(NSError *, NSArray *, MCOIndexSet *) = ^(NSError *error, NSArray *fetchedMessages, MCOIndexSet *vanishedMessages) {

    if( error ) {
        completionHandler(UIBackgroundFetchResultFailed);

        NSLog(@"Error downloading message headers:%@", error);
    }

    NSMutableArray *currentMessages = [NSMutableArray arrayWithArray:fetchedMessages];

    if( [currentMessages count] > 0 ) {

        MCOIMAPMessage *lastMessage = [fetchedMessages lastObject];
        NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:@(lastMessage.uid) forKey:@"lastUID"];
        [defaults synchronize];

        completionHandler(UIBackgroundFetchResultNewData);

    }
    else {
        completionHandler(UIBackgroundFetchResultNoData);
    }

};

[fetchOperation start:fetchHandler];

这是执行该调用时的记录器

2015-01-21 18:02:46.723 App[5021:473470] mailcore - IMAP: * OK Gimap     ready for requests from 181.167.207.42 b69mb75112208qhb
2015-01-21 18:02:46.725 App[5021:473470] mailcore - IMAP: 1 CAPABILITY
2015-01-21 18:02:46.955 App[5021:473470] mailcore - IMAP: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN
1 OK Thats all she wrote! b69mb75112208qhb
2015-01-21 18:02:46.955 App[5021:473470] mailcore - IMAP: 2     AUTHENTICATE XOAUTH2     dXNlcj1zYW50b21lZ29uemFsb0BnbWFpbC5jb20BYXV0aD1CZWFyZXIgeWEyOS5BZ0VQNnBQNFRJN1ZEMHlwempRNm01bTMwS2J0b0F6VzN6REdBbXc2dmh0VEF1TUJISVVaN3BobEtwY0M4dDlQRVFHcVhETHRlMU5VaFEBAQ==
2015-01-21 18:02:47.267 App[5021:473470] mailcore - IMAP: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT
2 OK santomegonzalo@gmail.com authenticated (Success)
2015-01-21 18:02:47.267 App[5021:473470] mailcore - IMAP: 3 COMPRESS DEFLATE
2015-01-21 18:02:47.518 App[5021:473470] mailcore - IMAP: 3 OK Success
2015-01-21 18:02:47.518 App[5021:473470] mailcore - IMAP: 4 ENABLE CONDSTORE
2015-01-21 18:02:47.767 App[5021:473470] mailcore - IMAP: * ENABLED CONDSTORE
4 OK Success
2015-01-21 18:02:47.767 App[5021:473470] mailcore - IMAP: 5 NAMESPACE
2015-01-21 18:02:48.016 App[5021:473470] mailcore - IMAP: * NAMESPACE (("" "/")) NIL NIL
5 OK Success
2015-01-21 18:02:48.017 App[5021:473470] mailcore - IMAP: 6 ID NIL
2015-01-21 18:02:48.267 App[5021:473470] mailcore - IMAP: * ID ("name"     "GImap" "vendor" "Google, Inc." "support-url"     "http://support.google.com/mail" "version" "gmail_imap_150113.07_p0"     "remote-host" "181.167.207.42")
6 OK Success
2015-01-21 18:02:48.268 App[5021:473470] mailcore - IMAP: 7 SELECT INBOX
2015-01-21 18:02:48.770 App[5021:473470] mailcore - IMAP: * FLAGS     (\Answered \Flagged \Draft \Deleted \Seen $MailFlagBit1 $MailFlagBit0     $Phishing $Forwarded $MailFlagBit2 JunkRecorded $NotJunk NotJunk     $NotPhishing $Junk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen     $MailFlagBit1 $MailFlagBit0 $Phishing $Forwarded $MailFlagBit2 JunkRecorded $NotJunk NotJunk $NotPhishing $Junk \*)] Flags permitted.
* OK [UIDVALIDITY 617846230] UIDs valid.
* 20472 EXISTS
* 0 RECENT
* OK [UIDNEXT 34091] Predicted next UID.
* OK [HIGHESTMODSEQ 4668463]
7 OK [READ-WRITE] INBO
2015-01-21 18:02:48.771 App[5021:473470] mailcore - IMAP: X selected.     (Success)
2015-01-21 18:02:48.771 App[5021:473470] mailcore - IMAP: 8 UID FETCH     34092:* (UID ENVELOPE BODY.PEEK[HEADER.FIELDS (References)])
2015-01-21 18:02:49.405 App[5021:473470] mailcore - IMAP: * 20472 FETCH     (UID 34090 MODSEQ (4668387) ENVELOPE ("Wed, 21 Jan 2015 20:31:46 -0000"     "Subject" (("User" NIL "pullrequests-reply" "company.org")) (("User" NIL     "toreply" "company.org")) (("User" NIL "toreply" "company.org")) ((NIL NIL     "santomegonzalo" "gmail.com")) NIL NIL "<toreply@company.com>" "    <toreply@company.com>") BODY[HEADER.FIELDS (References)] {52}
References: <toreply@company.com

)
8 OK Success

0 个答案:

没有答案