我有一个iPad应用程序,允许用户使用Mailcore2访问他们的Gmail帐户.我想我已经理解了Gmail的线程ID,消息ID和UID之间的区别,直到我仔细查看当我执行消息获取操作时Mailcore2返回给我的内容.我希望有人可以澄清我的困惑.
以下是我认为我从Gmail文档中了解到的内容:
1)线程ID将作为同一对话的一部分的消息(具有它们自己的消息ID和UID)组合在一起
2)UID特定于消息,并且仅对包含它的文件夹唯一
3)消息ID特定于消息,并且在帐户的所有文件夹中是唯一的
我也做了以下假设:
1)线程具有线程ID并且是消息的集合.线程没有消息ID或UID.
2)消息具有消息ID,UID和线程ID(即使它是线程中的唯一消息)
3)通过UID获取消息获取具有落在所请求的UID范围内的UID的MESSAGES.
4)属于同一线程的消息将具有不同的UID和消息ID,但具有相同的线程ID.
好吧,假设上面的内容是正确的,我认为在UID的Mailcore2中典型的消息提取过程中,我会收到一组电子邮件,从这些电子邮件中我可以查看他们的线程ID,例如重构线程在客户端.但是,我似乎回到了线程而不是电子邮件.此外,我得到的每个线程不一定包含其所有"子"消息.
因此,例如,如果我的收件箱中有两个线程,每个线程包含五条消息,则Mailcore以MCOIMAPMessages的形式向我返回一组2个"电子邮件".每个"电子邮件"都有一个线程ID,一个消息ID和一个UID.所以我不确定如何在这两个线程上访问包含的电子邮件.我看到有一个引用数组......但是检查这个对象并没有发现任何有用的东西.当我记录每个线程的内容时,我只获得部分内容 - 比如线程中的5条消息中的4条.不确定这是Mailcore还是我的保存过程中的错误,因为我对这一切的工作原理不完全了解.
这是我获取消息的代码:
//创建获取操作以获取文件夹中的第(10)条消息(第一次提取由序列号完成,后续提取由UID完成
uint64_t location = MAX([info messageCount] - DefaultPageSize + 1, 1); uint64_t size = serverMessageCount < DefaultPageSize ? serverMessageCount - 1 : DefaultPageSize - 1; MCOIndexSet *numbers = [MCOIndexSet indexSetWithRange:MCORangeMake(location, size)]; MCOIMAPMessagesRequestKind kind = MCOIMAPMessagesRequestKindUid | MCOIMAPMessagesRequestKindFullHeaders | MCOIMAPMessagesRequestKindFlags | MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindInternalDate; if ([capabilities containsIndex:MCOIMAPCapabilityGmail]) { kind |= MCOIMAPMessagesRequestKindGmailLabels | MCOIMAPMessagesRequestKindGmailThreadID | MCOIMAPMessagesRequestKindGmailMessageID; self.gmailCapability = YES; } fetchLatestEmails ([self.imapSession fetchMessagesByNumberOperationWithFolder:folder.folderId requestKind:kind numbers:numbers]);
//执行提取
void (^fetchLatestEmails)(MCOIMAPFetchMessagesOperation *) = ^(MCOIMAPFetchMessagesOperation *fetchOperation) { [fetchOperation start:^(NSError *error, NSArray *emails, MCOIndexSet *vanishedMessages) { if (nil != error) { failure(error); NSLog(@"the fetch error is %@", error); return; } [self.dataManager performBatchedChanges:^{ if ([emails count] !=0) { MCOIndexSet *savedThreadIds = [[MCOIndexSet alloc]init]; for (MCOIMAPMessage *email in emails) { //do stuff with emails Thread *thread = [self.dataManager fetchOrInsertNewThreadForFolder:folder threadId:email.gmailThreadID ?: email.gmailMessageID ?: email.uid error:nil]; if (nil != thread) { [savedThreadIds addIndex:thread.threadId]; [self.dataManager updateOrInsertNewEmailForThread:thread uid:email.uid messageId:email.gmailMessageID date:email.header.receivedDate subject:email.header.subject from:email.header.from.mailbox to:[email.header.to valueForKey:@"mailbox"] cc:[email.header.cc valueForKey:@"mailbox"] labels:labels flags:flags error:nil]; } if (nil != error) { failure(error); return; } } [savedThreadIds enumerateIndexes:^(uint64_t threadId) { [self.dataManager updateFlagsForThreadWithThreadId:threadId inFolder:folder]; }]; } NSError *folderUpdateError; [self.dataManager updateFolder:folder withMessageCount:serverMessageCount error:&folderUpdateError]; } error:&error]; if (nil == error) { [self refreshFolder:folder success:^{ success(); }failure:^(NSError *error) { }]; } else { failure(error); } }]; };
显然,就我对Gmail或Mailcore2的理解而言,有些不妥.如果有人能指出我的误解,我会很感激.
在打开Mailcore的问题和一些研究之后,我找到了自己问题的答案.
首先,我对UID,gmailMessageID和gmailThreadID的上述假设是正确的.我在网上查看了我的电子邮件帐户的Gmail对话视图,并希望我的Mailcore提取与之匹配,这让人感到困惑.这不会发生,因为会话视图,如名称所暗示的,将对话的所有消息拼接在一起,甚至是那些回复收件箱中的传入消息的消息 - 通常这些消息可以在'已发送'或'所有邮件中找到'文件夹.换句话说,从Mailcore获取的内容看起来不完整只是因为它正在获取收件箱中的实际内容(或者从中获取消息的任何文件夹).这不包括对传入消息的回复.为了包含此类消息(即重新创建Gmail的会话视图),我了解必须通过使用消息的gmailThreadID执行搜索操作来从"所有邮件"(或者我认为"发送"邮件)中获取已发送的消息.利益.
在测试我的Mailcore提取操作时,将网络上的Gmail帐户的会话视图切换为"关闭",使测试更加清晰.