From b0a968ba727c703528efbfa803267fa67aec37d1 Mon Sep 17 00:00:00 2001 From: CodaFi Date: Sat, 22 Jun 2013 22:04:03 -0600 Subject: Implement Gmail Thread ID --- src/core/imap/MCIMAPMessage.cc | 11 +++++++++++ src/core/imap/MCIMAPMessage.h | 4 ++++ src/core/imap/MCIMAPSession.cc | 31 +++++++++++++++++++++++++++---- src/objc/abstract/MCOConstants.h | 2 ++ src/objc/imap/MCOIMAPMessage.h | 3 +++ src/objc/imap/MCOIMAPMessage.mm | 1 + 6 files changed, 48 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/imap/MCIMAPMessage.cc b/src/core/imap/MCIMAPMessage.cc index 6f8a0dbb..5e55ddcc 100644 --- a/src/core/imap/MCIMAPMessage.cc +++ b/src/core/imap/MCIMAPMessage.cc @@ -35,6 +35,7 @@ IMAPMessage::IMAPMessage(IMAPMessage * other) setOriginalFlags(other->originalFlags()); setMainPart((AbstractPart *) other->mainPart()->copy()->autorelease()); setGmailLabels(other->gmailLabels()); + setGmailThreadID(other->gmailThreadID()); } IMAPMessage::~IMAPMessage() @@ -121,6 +122,16 @@ Array * IMAPMessage::gmailLabels() return mLabels; } +void IMAPMessage::setGmailThreadID(String * threadID) +{ + MC_SAFE_REPLACE_COPY(String, mThreadID, threadID); +} + +String * IMAPMessage::gmailThreadID() +{ + return mThreadID; +} + AbstractPart * IMAPMessage::partForPartID(String * partID) { return partForPartIDInPart(mainPart(), partID); diff --git a/src/core/imap/MCIMAPMessage.h b/src/core/imap/MCIMAPMessage.h index 5a9cadcb..dd3edb89 100644 --- a/src/core/imap/MCIMAPMessage.h +++ b/src/core/imap/MCIMAPMessage.h @@ -38,6 +38,9 @@ namespace mailcore { virtual void setGmailLabels(Array * /* String */ labels); virtual Array * /* String */ gmailLabels(); + virtual void setGmailThreadID(String * threadID); + virtual String * /* String */ gmailThreadID(); + virtual AbstractPart * partForPartID(String * partID); virtual AbstractPart * partForContentID(String * contentID); @@ -59,6 +62,7 @@ namespace mailcore { MessageFlag mOriginalFlags; AbstractPart * mMainPart; Array * /* String */ mLabels; + String * mThreadID; void init(); }; diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index 52e819d9..e0c00d39 100644 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -1582,6 +1582,7 @@ struct msg_att_handler_data { bool needsBody; bool needsFlags; bool needsGmailLabels; + bool needsGmailThreadID; uint32_t startUid; }; @@ -1594,6 +1595,7 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) bool hasBody; bool hasFlags; bool hasGmailLabels; + bool hasGmailThreadID; struct msg_att_handler_data * msg_att_context; // struct IMAPSession * self; @@ -1607,6 +1609,7 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) bool needsBody; bool needsFlags; bool needsGmailLabels; + bool needsGmailThreadID; uint32_t startUid; msg_att_context = (struct msg_att_handler_data *) context; @@ -1621,13 +1624,15 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) needsBody = msg_att_context->needsBody; needsFlags = msg_att_context->needsFlags; needsGmailLabels = msg_att_context->needsGmailLabels; + needsGmailThreadID = msg_att_context->needsGmailThreadID; startUid = msg_att_context->startUid; hasHeader = false; hasBody = false; hasFlags = false; hasGmailLabels = false; - + hasGmailThreadID = false; + msg = new IMAPMessage(); uid = 0; @@ -1718,6 +1723,13 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) } labels->release(); } + if (ext_data->ext_extension == &mailimap_extension_xgmthrid) { + String * threadID; + + threadID = String::stringWithUTF8Characters((char *) ext_data->ext_data); + msg->setGmailThreadID(threadID); + hasGmailThreadID = true; + } } } for(item_iter = clist_begin(msg_att->att_list) ; item_iter != NULL ; item_iter = clist_next(item_iter)) { @@ -1752,7 +1764,10 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) msg->release(); return; } - + if (needsGmailThreadID && !hasGmailThreadID) { + msg->release(); + return; + } if (uid != 0) { msg->setUid(uid); } @@ -1780,6 +1795,7 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest bool needsBody; bool needsFlags; bool needsGmailLabels; + bool needsGmailThreadID; Array * messages; IndexSet * vanishedMessages; @@ -1803,7 +1819,8 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest needsBody = false; needsFlags = false; needsGmailLabels = false; - + needsGmailThreadID = false; + fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); fetch_att = mailimap_fetch_att_new_uid(); mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); @@ -1819,6 +1836,12 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); needsGmailLabels = true; } + if ((requestKind & IMAPMessagesRequestKindGmailThreadID) != 0) { + MCLog("request flags"); + fetch_att = mailimap_fetch_att_new_xgmthrid(); + mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); + needsGmailThreadID = true; + } if ((requestKind & IMAPMessagesRequestKindFullHeaders) != 0) { clist * hdrlist; char * header; @@ -1908,7 +1931,7 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest msg_att_data.needsFlags = needsFlags; msg_att_data.needsGmailLabels = needsGmailLabels; msg_att_data.startUid = startUid; - + msg_att_data.needsGmailThreadID = needsGmailThreadID; mailimap_set_msg_att_handler(mImap, msg_att_handler, &msg_att_data); mBodyProgressEnabled = false; diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h index 6f9dd446..3ef785ab 100644 --- a/src/objc/abstract/MCOConstants.h +++ b/src/objc/abstract/MCOConstants.h @@ -134,6 +134,8 @@ typedef enum { MCOIMAPMessagesRequestKindHeaderSubject = 1 << 5, /** Gmail Labels.*/ MCOIMAPMessagesRequestKindGmailLabels = 1 << 6, + /** Gmail Thread ID.*/ + MCOIMAPMessagesRequestKindGmailThreadID = 1 << 7, } MCOIMAPMessagesRequestKind; /** It defines the behavior of the STORE flags request.*/ diff --git a/src/objc/imap/MCOIMAPMessage.h b/src/objc/imap/MCOIMAPMessage.h index c6d8595b..f8acd25b 100644 --- a/src/objc/imap/MCOIMAPMessage.h +++ b/src/objc/imap/MCOIMAPMessage.h @@ -49,6 +49,9 @@ /** All Gmail labels of the message */ @property (nonatomic, copy) NSArray * /* NSString */ gmailLabels; +/** Gmail thread iD of the message */ +@property (nonatomic, copy) NSString * /* NSString */ gmailThreadID; + /** Returns the part with the given part identifier. @param partID A part identifier looks like 1.2.1 diff --git a/src/objc/imap/MCOIMAPMessage.mm b/src/objc/imap/MCOIMAPMessage.mm index 9984443e..5b8f7cdc 100644 --- a/src/objc/imap/MCOIMAPMessage.mm +++ b/src/objc/imap/MCOIMAPMessage.mm @@ -47,6 +47,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(MCOMessageFlag, mailcore::MessageFlag, setOriginalFla MCO_OBJC_SYNTHESIZE_SCALAR(uint64_t, uint64_t, setModSeqValue, modSeqValue) MCO_OBJC_SYNTHESIZE(AbstractPart, setMainPart, mainPart) MCO_OBJC_SYNTHESIZE_ARRAY(setGmailLabels, gmailLabels) +MCO_OBJC_SYNTHESIZE_STRING(setGmailThreadID, gmailThreadID) - (MCOAbstractPart *) partForPartID:(NSString *)partID { -- cgit v1.2.3