diff options
author | 2013-07-02 14:30:09 -0700 | |
---|---|---|
committer | 2013-07-16 14:50:01 -0700 | |
commit | 73ea92fd846adbb4e3b25d8c12c04916da25b340 (patch) | |
tree | 07b3a9316b46b6ca7b9209281e91eb9d70289f37 /src/core/imap/MCIMAPSession.cc | |
parent | f5e4186da2bc1c6d88582e8f2d4c6a236e278840 (diff) |
Allows for request custom headers when fetching messages
* Defines new request kind ExtraHeaders
* Exposes extraHeaders property on fetch messages operations
* Modifies MessageHeader::importIMFFields for handling any headers
Diffstat (limited to 'src/core/imap/MCIMAPSession.cc')
-rw-r--r-- | src/core/imap/MCIMAPSession.cc | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index b44efdfd..f2b9ccdc 100644 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -1722,7 +1722,8 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) hasHeader = true; } else if (att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { - if ((requestKind & IMAPMessagesRequestKindFullHeaders) != 0) { + if ((requestKind & IMAPMessagesRequestKindFullHeaders) != 0 || + (requestKind & IMAPMessagesRequestKindExtraHeaders) != 0) { char * bytes; size_t length; @@ -1849,7 +1850,7 @@ static void msg_att_handler(struct mailimap_msg_att * msg_att, void * context) IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequestKind requestKind, bool fetchByUID, struct mailimap_set * imapset, uint64_t modseq, HashMap * mapping, uint32_t startUid, - IMAPProgressCallback * progressCallback, ErrorCode * pError) + IMAPProgressCallback * progressCallback, ErrorCode * pError, Array *extraHeaders) { struct mailimap_fetch_type * fetch_type; clist * fetch_result; @@ -1986,6 +1987,30 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest fetch_att = mailimap_fetch_att_new_internaldate(); mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); } + if ((requestKind & IMAPMessagesRequestKindExtraHeaders) != 0) { + // custom header request + clist * hdrlist; + char * header; + struct mailimap_header_list * imap_hdrlist; + struct mailimap_section * section; + + MCLog("request extra headers"); + + if (extraHeaders && extraHeaders->count() > 0) { + hdrlist = clist_new(); + for (unsigned int i = 0; i < extraHeaders->count(); i++) { + String *headerString = (String *)extraHeaders->objectAtIndex(i); + header = strdup(headerString->UTF8Characters()); + clist_append(hdrlist, header); + } + + imap_hdrlist = mailimap_header_list_new(hdrlist); + section = mailimap_section_new_header_fields(imap_hdrlist); + fetch_att = mailimap_fetch_att_new_body_peek_section(section); + mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); + needsHeader = true; + } + } struct msg_att_handler_data msg_att_data; @@ -2086,7 +2111,7 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest requestKind = (IMAPMessagesRequestKind) (requestKind | IMAPMessagesRequestKindFullHeaders); result = fetchMessages(folder, requestKind, fetchByUID, - imapset, modseq, NULL, startUid, progressCallback, pError); + imapset, modseq, NULL, startUid, progressCallback, pError, extraHeaders); if (result != NULL) { if (result->modifiedOrAddedMessages() != NULL) { if (result->modifiedOrAddedMessages()->count() > 0) { @@ -2105,11 +2130,12 @@ IMAPSyncResult * IMAPSession::fetchMessages(String * folder, IMAPMessagesRequest } Array * IMAPSession::fetchMessagesByUID(String * folder, IMAPMessagesRequestKind requestKind, - IndexSet * uids, IMAPProgressCallback * progressCallback, ErrorCode * pError) + IndexSet * uids, IMAPProgressCallback * progressCallback, ErrorCode * pError, + Array * extraHeaders) { struct mailimap_set * imapset = setFromIndexSet(uids); IMAPSyncResult * syncResult = fetchMessages(folder, requestKind, true, imapset, 0, NULL, 0, - progressCallback, pError); + progressCallback, pError, extraHeaders); if (syncResult == NULL) return NULL; Array * result = syncResult->modifiedOrAddedMessages(); @@ -2119,11 +2145,12 @@ Array * IMAPSession::fetchMessagesByUID(String * folder, IMAPMessagesRequestKind } Array * IMAPSession::fetchMessagesByNumber(String * folder, IMAPMessagesRequestKind requestKind, - IndexSet * numbers, IMAPProgressCallback * progressCallback, ErrorCode * pError) + IndexSet * numbers, IMAPProgressCallback * progressCallback, ErrorCode * pError, + Array * extraHeaders) { struct mailimap_set * imapset = setFromIndexSet(numbers); IMAPSyncResult * syncResult = fetchMessages(folder, requestKind, false, imapset, 0, NULL, 0, - progressCallback, pError); + progressCallback, pError, extraHeaders); if (syncResult == NULL) return NULL; Array * result = syncResult->modifiedOrAddedMessages(); @@ -2914,13 +2941,14 @@ uint32_t IMAPSession::firstUnseenUid() IMAPSyncResult * IMAPSession::syncMessagesByUID(String * folder, IMAPMessagesRequestKind requestKind, IndexSet * uids, uint64_t modseq, - IMAPProgressCallback * progressCallback, ErrorCode * pError) + IMAPProgressCallback * progressCallback, ErrorCode * pError, + Array * extraHeaders) { MCAssert(uids->rangesCount() > 0); struct mailimap_set * imapset = setFromIndexSet(uids); IMAPSyncResult * result = fetchMessages(folder, requestKind, true, imapset, modseq, NULL, (uint32_t) uids->allRanges()[0].location, - progressCallback, pError); + progressCallback, pError, extraHeaders); mailimap_set_free(imapset); return result; } |