static void ews_set_threading_data (CamelMessageInfo *mi, EEwsItem *item) { const gchar *references_str, *inreplyto_str; const gchar *message_id; GSList *refs, *irt, *link; guint8 *digest; gchar *msgid; CamelSummaryMessageID tmp_msgid; GArray *references; /* set message id */ message_id = e_ews_item_get_msg_id (item); msgid = camel_header_msgid_decode (message_id); if (msgid) { digest = get_md5_digest ((const guchar *) msgid); memcpy (tmp_msgid.id.hash, digest, sizeof (tmp_msgid.id.hash)); g_free (digest); g_free (msgid); camel_message_info_set_message_id (mi, tmp_msgid.id.id); } /* Process References: header */ references_str = e_ews_item_get_references (item); refs = camel_header_references_decode (references_str); /* Prepend In-Reply-To: contents to References: for summary info */ inreplyto_str = e_ews_item_get_in_replyto (item); irt = camel_header_references_decode (inreplyto_str); if (irt) { refs = g_slist_concat (irt, refs); } if (!refs) return; references = g_array_sized_new (FALSE, FALSE, sizeof (guint64), g_slist_length (refs)); for (link = refs; link; link = g_slist_next (link)) { digest = get_md5_digest ((const guchar *) link->data); memcpy (tmp_msgid.id.hash, digest, sizeof (tmp_msgid.id.hash)); g_free (digest); g_array_append_val (references, tmp_msgid.id.id); } g_slist_free_full (refs, g_free); camel_message_info_take_references (mi, references); }
static int decode_envelope (CamelIMAP4Engine *engine, CamelMessageInfo *info, camel_imap4_token_t *token, CamelException *ex) { CamelIMAP4MessageInfo *iinfo = (CamelIMAP4MessageInfo *) info; unsigned char md5sum[16]; char *nstring, *msgid; if (camel_imap4_engine_next_token (engine, token, ex) == -1) return -1; if (token->token != '(') { camel_imap4_utils_set_unexpected_token_error (ex, engine, token); return -1; } if (envelope_decode_date (engine, &iinfo->info.date_sent, ex) == -1) goto exception; /* subject */ if (envelope_decode_nstring (engine, &nstring, TRUE, ex) == -1) goto exception; iinfo->info.needs_free = TRUE; iinfo->info.subject = camel_pstring_strdup (nstring); g_free(nstring); /* from */ if (envelope_decode_addresses (engine, &nstring, ex) == -1) goto exception; iinfo->info.from = camel_pstring_strdup (nstring); g_free(nstring); /* sender */ if (envelope_decode_addresses (engine, &nstring, ex) == -1) goto exception; g_free (nstring); /* reply-to */ if (envelope_decode_addresses (engine, &nstring, ex) == -1) goto exception; g_free (nstring); /* to */ if (envelope_decode_addresses (engine, &nstring, ex) == -1) goto exception; iinfo->info.to = camel_pstring_strdup (nstring); g_free(nstring); /* cc */ if (envelope_decode_addresses (engine, &nstring, ex) == -1) goto exception; iinfo->info.cc = camel_pstring_strdup (nstring); g_free(nstring); /* bcc */ if (envelope_decode_addresses (engine, &nstring, ex) == -1) goto exception; g_free (nstring); /* in-reply-to */ if (envelope_decode_nstring (engine, &nstring, FALSE, ex) == -1) goto exception; if (nstring != NULL) { if (!iinfo->info.references) iinfo->info.references = decode_references (NULL, nstring); g_free (nstring); } /* message-id */ if (envelope_decode_nstring (engine, &nstring, FALSE, ex) == -1) goto exception; if (nstring != NULL) { if ((msgid = camel_header_msgid_decode (nstring))) { md5_get_digest (msgid, strlen (msgid), md5sum); memcpy (iinfo->info.message_id.id.hash, md5sum, sizeof (CamelSummaryMessageID)); g_free (msgid); } g_free (nstring); } if (camel_imap4_engine_next_token (engine, token, ex) == -1) return -1; if (token->token != ')') { camel_imap4_utils_set_unexpected_token_error (ex, engine, token); goto exception; } return 0; exception: return -1; }
/* FIXME: check format of fields. */ static gboolean process_header (CamelMedium *medium, const gchar *name, const gchar *value) { CamelHeaderType header_type; CamelMimeMessage *message = CAMEL_MIME_MESSAGE (medium); CamelInternetAddress *addr; const gchar *charset; gchar *unfolded; header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, name); switch (header_type) { case HEADER_FROM: addr = camel_internet_address_new (); unfolded = camel_header_unfold (value); if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) { g_object_unref (addr); } else { if (message->from) g_object_unref (message->from); message->from = addr; } g_free (unfolded); break; case HEADER_REPLY_TO: addr = camel_internet_address_new (); unfolded = camel_header_unfold (value); if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) { g_object_unref (addr); } else { if (message->reply_to) g_object_unref (message->reply_to); message->reply_to = addr; } g_free (unfolded); break; case HEADER_SUBJECT: g_free (message->subject); if (((CamelDataWrapper *) message)->mime_type) { charset = camel_content_type_param (((CamelDataWrapper *) message)->mime_type, "charset"); charset = camel_iconv_charset_name (charset); } else charset = NULL; unfolded = camel_header_unfold (value); message->subject = g_strstrip (camel_header_decode_string (unfolded, charset)); g_free (unfolded); break; case HEADER_TO: case HEADER_CC: case HEADER_BCC: case HEADER_RESENT_TO: case HEADER_RESENT_CC: case HEADER_RESENT_BCC: addr = g_hash_table_lookup (message->recipients, name); if (value) { unfolded = camel_header_unfold (value); camel_address_decode (CAMEL_ADDRESS (addr), unfolded); g_free (unfolded); } else { camel_address_remove (CAMEL_ADDRESS (addr), -1); } return FALSE; case HEADER_DATE: if (value) { message->date = camel_header_decode_date (value, &message->date_offset); } else { message->date = CAMEL_MESSAGE_DATE_CURRENT; message->date_offset = 0; } break; case HEADER_MESSAGE_ID: g_free (message->message_id); if (value) message->message_id = camel_header_msgid_decode (value); else message->message_id = NULL; break; default: return FALSE; } return TRUE; }