diff options
author | Ryan Johnson <ryan@iambismark.net> | 2013-07-02 14:30:09 -0700 |
---|---|---|
committer | Ryan Johnson <ryan@iambismark.net> | 2013-07-16 14:50:01 -0700 |
commit | 73ea92fd846adbb4e3b25d8c12c04916da25b340 (patch) | |
tree | 07b3a9316b46b6ca7b9209281e91eb9d70289f37 /src/core/abstract | |
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/abstract')
-rw-r--r-- | src/core/abstract/MCMessageConstants.h | 3 | ||||
-rw-r--r-- | src/core/abstract/MCMessageHeader.cc | 297 |
2 files changed, 181 insertions, 119 deletions
diff --git a/src/core/abstract/MCMessageConstants.h b/src/core/abstract/MCMessageConstants.h index 4949bb95..2ecde808 100644 --- a/src/core/abstract/MCMessageConstants.h +++ b/src/core/abstract/MCMessageConstants.h @@ -68,6 +68,7 @@ namespace mailcore { IMAPMessagesRequestKindGmailLabels = 1 << 6, IMAPMessagesRequestKindGmailMessageID = 1 << 7, IMAPMessagesRequestKindGmailThreadID = 1 << 8, + IMAPMessagesRequestKindExtraHeaders = 1 << 9, }; enum IMAPFetchRequestType { @@ -225,4 +226,4 @@ namespace mailcore { #endif -#endif
\ No newline at end of file +#endif diff --git a/src/core/abstract/MCMessageHeader.cc b/src/core/abstract/MCMessageHeader.cc index bdeb6907..b1fe740e 100644 --- a/src/core/abstract/MCMessageHeader.cc +++ b/src/core/abstract/MCMessageHeader.cc @@ -22,6 +22,9 @@ static Array * lep_address_list_from_lep_mailbox(struct mailimf_mailbox_list * m static Array * msg_id_to_string_array(clist * msgids); static clist * msg_id_from_string_array(Array * msgids); +static Array * keyword_to_string_array(clist * keywords); +static Array * clist_to_string_array(clist * cstrs); + #define MAX_HOSTNAME 512 MessageHeader::MessageHeader() @@ -155,6 +158,11 @@ String * MessageHeader::description() if (mUserAgent != NULL) { result->appendUTF8Format("X-Mailer: %s\n", mUserAgent->UTF8Characters()); } + if (mExtraHeaders != NULL) { + mc_foreachdictionaryKeyAndValue(String, header, String, value, mExtraHeaders) { + result->appendUTF8Format("%s: %s\n", header->UTF8Characters(), value->UTF8Characters()); + } + } result->appendUTF8Format(">"); return result; @@ -355,127 +363,170 @@ void MessageHeader::importHeadersData(Data * data) } importIMFFields(fields); - + mailimf_fields_free(fields); } void MessageHeader::importIMFFields(struct mailimf_fields * fields) { - struct mailimf_single_fields single_fields; - - mailimf_single_fields_init(&single_fields, fields); - - /* date */ - - if (single_fields.fld_orig_date != NULL) { - time_t timestamp; - timestamp = timestamp_from_date(single_fields.fld_orig_date->dt_date_time); - setDate(timestamp); - setReceivedDate(timestamp); - //MCLog("%lu %lu", (unsigned long) timestamp, date()); - } - - /* subject */ - if (single_fields.fld_subject != NULL) { - char * subject; - - subject = single_fields.fld_subject->sbj_value; - setSubject(String::stringByDecodingMIMEHeaderValue(subject)); - } - - /* sender */ - if (single_fields.fld_sender != NULL) { - struct mailimf_mailbox * mb; - Address * address; + clistiter * cur; + cur = clist_begin(fields->fld_list); + while (cur != NULL) { + struct mailimf_field * field; + + field = (mailimf_field *)clist_content(cur); - mb = single_fields.fld_sender->snd_mb; - if (mb != NULL) { - address = Address::addressWithIMFMailbox(mb); - setSender(address); - } - } + switch (field->fld_type) { + case MAILIMF_FIELD_ORIG_DATE: + if (date() == 0) { + time_t timestamp; + timestamp = timestamp_from_date(field->fld_data.fld_orig_date->dt_date_time); + setDate(timestamp); + setReceivedDate(timestamp); + } + break; + case MAILIMF_FIELD_SUBJECT: + if (subject() == NULL) { + char * subject; + subject = field->fld_data.fld_subject->sbj_value; + setSubject(String::stringByDecodingMIMEHeaderValue(subject)); + } + break; + case MAILIMF_FIELD_SENDER: + if (sender() == NULL) { + struct mailimf_mailbox * mb; + Address * address; + + mb = field->fld_data.fld_sender->snd_mb; + if (mb != NULL) { + address = Address::addressWithIMFMailbox(mb); + setSender(address); + } + } + break; + case MAILIMF_FIELD_FROM: + if (from() == NULL) { + struct mailimf_mailbox_list * mb_list; + Array * addresses; + + mb_list = field->fld_data.fld_from->frm_mb_list; + addresses = lep_address_list_from_lep_mailbox(mb_list); + if (addresses->count() > 0) { + setFrom((Address *) (addresses->objectAtIndex(0))); + } + } + break; + case MAILIMF_FIELD_REPLY_TO: + if (replyTo() == NULL) { + struct mailimf_address_list * addr_list; + Array * addresses; + + addr_list = field->fld_data.fld_reply_to->rt_addr_list; + addresses = lep_address_list_from_lep_addr(addr_list); + setReplyTo(addresses); + } + break; + case MAILIMF_FIELD_TO: + if (to() == NULL) { + struct mailimf_address_list * addr_list; + Array * addresses; + + addr_list = field->fld_data.fld_to->to_addr_list; + addresses = lep_address_list_from_lep_addr(addr_list); + setTo(addresses); + } + break; + case MAILIMF_FIELD_CC: + if (cc() == NULL) { + struct mailimf_address_list * addr_list; + Array * addresses; + + addr_list = field->fld_data.fld_cc->cc_addr_list; + addresses = lep_address_list_from_lep_addr(addr_list); + setCc(addresses); + } + break; + case MAILIMF_FIELD_BCC: + if (bcc() == NULL) { + struct mailimf_address_list * addr_list; + Array * addresses; + + addr_list = field->fld_data.fld_bcc->bcc_addr_list; + addresses = lep_address_list_from_lep_addr(addr_list); + setBcc(addresses); + } + break; + case MAILIMF_FIELD_MESSAGE_ID: + char * msgid; + String * str; + + msgid = field->fld_data.fld_message_id->mid_value; + str = String::stringWithUTF8Characters(msgid); + setMessageID(str); + break; + case MAILIMF_FIELD_REFERENCES: + if (references() == NULL) { + clist * msg_id_list; + Array * msgids; + + msg_id_list = field->fld_data.fld_references->mid_list; + msgids = msg_id_to_string_array(msg_id_list); + setReferences(msgids); + } + break; + case MAILIMF_FIELD_IN_REPLY_TO: + if (inReplyTo() == NULL) { + clist * msg_id_list; + Array * msgids; + + msg_id_list = field->fld_data.fld_references->mid_list; + msgids = msg_id_to_string_array(msg_id_list); + setReferences(msgids); + } + break; + case MAILIMF_FIELD_COMMENTS: + if (headerValueForName(MCSTR("Comments")) == NULL) { + char * comments; + String * str; + + comments = field->fld_data.fld_comments->cm_value; + str = String::stringWithUTF8Characters(comments); + addHeader(MCSTR("Comments"), str); + } + break; + case MAILIMF_FIELD_OPTIONAL_FIELD: + char * fieldName; + String * fieldNameStr; + + fieldName = field->fld_data.fld_optional_field->fld_name; + fieldNameStr = String::stringWithUTF8Characters(fieldName); + if (headerValueForName(fieldNameStr) == NULL) { + char * fieldValue; + String * fieldValueStr; + + fieldValue = field->fld_data.fld_optional_field->fld_value; + fieldValueStr = String::stringWithUTF8Characters(fieldValue); + addHeader(fieldNameStr, fieldValueStr); + } + break; + case MAILIMF_FIELD_KEYWORDS: +// TODO: deal with non-string headers in mExtraHeaders +// if (headerForName(MCSTR("Keywords")) == NULL) { +// clist * keywords_list; +// Array * keywords; +// +// keywords_list = field->fld_data.fld_keywords->kw_list; +// keywords = keyword_to_string_array(keywords_list); +// addHeader(MCSTR("Keywords"), keywords); +// } +// break; + default: + break; + } + cur = clist_next(cur); + - /* from */ - if (single_fields.fld_from != NULL) { - struct mailimf_mailbox_list * mb_list; - Array * addresses; - - mb_list = single_fields.fld_from->frm_mb_list; - addresses = lep_address_list_from_lep_mailbox(mb_list); - if (addresses->count() > 0) { - setFrom((Address *) (addresses->objectAtIndex(0))); - } - } - - /* replyto */ - if (single_fields.fld_reply_to != NULL) { - struct mailimf_address_list * addr_list; - Array * addresses; - - addr_list = single_fields.fld_reply_to->rt_addr_list; - addresses = lep_address_list_from_lep_addr(addr_list); - setReplyTo(addresses); - } - - /* to */ - if (single_fields.fld_to != NULL) { - struct mailimf_address_list * addr_list; - Array * addresses; - - addr_list = single_fields.fld_to->to_addr_list; - addresses = lep_address_list_from_lep_addr(addr_list); - setTo(addresses); - } - - /* cc */ - if (single_fields.fld_cc != NULL) { - struct mailimf_address_list * addr_list; - Array * addresses; - - addr_list = single_fields.fld_cc->cc_addr_list; - addresses = lep_address_list_from_lep_addr(addr_list); - setCc(addresses); - } - - /* bcc */ - if (single_fields.fld_bcc != NULL) { - struct mailimf_address_list * addr_list; - Array * addresses; - - addr_list = single_fields.fld_bcc->bcc_addr_list; - addresses = lep_address_list_from_lep_addr(addr_list); - setBcc(addresses); - } - - /* msgid */ - if (single_fields.fld_message_id != NULL) { - char * msgid; - String * str; - - msgid = single_fields.fld_message_id->mid_value; - str = String::stringWithUTF8Characters(msgid); - setMessageID(str); - } - - /* references */ - if (single_fields.fld_references != NULL) { - clist * msg_id_list; - Array * msgids; - - msg_id_list = single_fields.fld_references->mid_list; - msgids = msg_id_to_string_array(msg_id_list); - setReferences(msgids); - } - - /* inreplyto */ - if (single_fields.fld_in_reply_to != NULL) { - clist * msg_id_list; - Array * msgids; - - msg_id_list = single_fields.fld_in_reply_to->mid_list; - msgids = msg_id_to_string_array(msg_id_list); - setInReplyTo(msgids); - } + } } static time_t timestamp_from_date(struct mailimf_date_time * date_time) @@ -753,17 +804,27 @@ static struct mailimf_address_list * lep_address_list_from_array(Array * address static Array * msg_id_to_string_array(clist * msgids) { + return clist_to_string_array(msgids); +} + +static Array * keyword_to_string_array(clist * keywords) +{ + return clist_to_string_array(keywords); +} + +static Array * clist_to_string_array(clist * cstrs) +{ clistiter * cur; Array * result; result = Array::array(); - for(cur = clist_begin(msgids) ; cur != NULL ; cur = clist_next(cur)) { - char * msgid; + for(cur = clist_begin(cstrs) ; cur != NULL ; cur = clist_next(cur)) { + char * cstr; String * str; - msgid = (char *) clist_content(cur); - str = String::stringWithUTF8Characters(msgid); + cstr = (char *) clist_content(cur); + str = String::stringWithUTF8Characters(cstr); result->addObject(str); } |