X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-msg.c;h=797c03ffce43d95708053a337c63f3d6b562a49b;hp=307fe9490695853d149399f1e127961221033a8f;hb=5a383a31b2862f9ecface4a3a6fc3235754acb8f;hpb=644f009fa6c19d734059ef643c65cd60ef0489e1 diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index 307fe94..797c03f 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "modest-formatter.h" #include #include @@ -76,8 +77,11 @@ modest_tny_msg_new (const gchar* mailto, const gchar* from, const gchar *cc, tny_header_set_from (TNY_HEADER (header), from); tny_header_set_replyto (TNY_HEADER (header), from); } - if ((mailto != NULL) && (strlen(mailto) > 0)) - tny_header_set_to (TNY_HEADER (header), mailto); + if ((mailto != NULL) && (strlen(mailto) > 0)) { + gchar *removed_to = modest_text_utils_remove_duplicate_addresses (mailto); + tny_header_set_to (TNY_HEADER (header), removed_to); + g_free (removed_to); + } if ((cc != NULL) && (strlen(cc) > 0)) tny_header_set_cc (TNY_HEADER (header), cc); if ((bcc != NULL) && (strlen(bcc) > 0)) @@ -462,19 +466,14 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht /* no parts? assume it's single-part message */ if (tny_iterator_is_done(iter)) { gchar *content_type; - gchar *content_type_lower; gboolean is_text_part; g_object_unref (G_OBJECT(iter)); - content_type = g_strdup (tny_mime_part_get_content_type (msg)); + content_type = modest_tny_mime_part_get_content_type (msg); if (content_type == NULL) return NULL; - content_type = g_strstrip (content_type); - content_type_lower = g_ascii_strdown (content_type, -1); - g_free (content_type); is_text_part = - g_str_has_prefix (content_type_lower, "text/") || - g_str_has_prefix (content_type_lower, "message/rfc822"); - g_free (content_type_lower); + g_str_has_prefix (content_type, "text/"); + g_free (content_type); /* if this part cannot be a supported body return NULL */ if (!is_text_part) { return NULL; @@ -490,6 +489,7 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht if (!part) { g_warning ("%s: not a valid mime part", __FUNCTION__); + tny_iterator_next (iter); continue; } @@ -595,17 +595,17 @@ create_reply_forward_mail (TnyMsg *msg, TnyHeader *header, const gchar *from, part of the message to create the reply/forwarded mail */ if (msg != NULL) body = modest_tny_msg_find_body_part (msg, FALSE); - + if (modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) formatter = modest_formatter_new ("text/html", signature); else formatter = modest_formatter_new ("text/plain", signature); - + /* if we don't have a text-part */ no_text_part = (!body) || (strcmp (tny_mime_part_get_content_type (body), "text/html")==0); - + /* when we're reply, include the text part if we have it, or nothing otherwise. */ if (is_reply) new_msg = modest_formatter_quote (formatter, no_text_part ? NULL: body, header, @@ -620,11 +620,11 @@ create_reply_forward_mail (TnyMsg *msg, TnyHeader *header, const gchar *from, attachments); } } - + g_object_unref (G_OBJECT(formatter)); if (body) g_object_unref (G_OBJECT(body)); - + /* Fill the header */ new_header = tny_msg_get_header (new_msg); tny_header_set_from (new_header, from); @@ -725,6 +725,26 @@ modest_tny_msg_create_forward_msg (TnyMsg *msg, return new_msg; } + + +static gint +count_addresses (const gchar* addresses) +{ + gint count = 1; + + if (!addresses) + return 0; + + while (*addresses) { + if (*addresses == ',' || *addresses == ';') + ++count; + ++addresses; + } + + return count; +} + + /* get the new To:, based on the old header, * result is newly allocated or NULL in case of error * */ @@ -732,7 +752,7 @@ static gchar* get_new_to (TnyMsg *msg, TnyHeader *header, const gchar* from, ModestTnyMsgReplyMode reply_mode) { - const gchar* old_reply_to; + gchar* old_reply_to; gchar* old_from; gchar* new_to; @@ -748,12 +768,11 @@ get_new_to (TnyMsg *msg, TnyHeader *header, const gchar* from, /* reply to sender, use ReplyTo or From */ - //old_reply_to = tny_header_get_replyto (header); old_reply_to = modest_tny_mime_part_get_header_value (TNY_MIME_PART(msg), "Reply-To"); old_from = tny_header_dup_from (header); - if (!old_from && !old_reply_to) { + if (!old_from && !old_reply_to) { g_warning ("%s: failed to get either Reply-To: or From: from header", __FUNCTION__); return NULL; @@ -769,6 +788,7 @@ get_new_to (TnyMsg *msg, TnyHeader *header, const gchar* from, /* otherwise use either Reply-To: (preferred) or From: */ new_to = g_strdup (old_reply_to ? old_reply_to : old_from); g_free (old_from); + g_free (old_reply_to); /* in case of ReplyAll, we need to add the Recipients in the old To: */ if (reply_mode == MODEST_TNY_MSG_REPLY_MODE_ALL) { @@ -787,7 +807,15 @@ get_new_to (TnyMsg *msg, TnyHeader *header, const gchar* from, /* remove duplicate entries */ gchar *tmp = modest_text_utils_remove_duplicate_addresses (new_to); g_free (new_to); - new_to = tmp; + new_to = tmp; + + /* now, strip me (the new From:) from the new_to, but only if + * there are >1 addresses there */ + if (count_addresses (new_to) > 1) { + gchar *tmp = modest_text_utils_remove_address (new_to, from); + g_free (new_to); + new_to = tmp; + } } return new_to; @@ -799,15 +827,16 @@ get_new_to (TnyMsg *msg, TnyHeader *header, const gchar* from, static gchar* get_new_cc (TnyHeader *header, const gchar* from) { - gchar *old_cc; - gchar *result; + gchar *old_cc, *result, *dup; old_cc = tny_header_dup_cc (header); if (!old_cc) return NULL; /* remove me (the new From:) from the Cc: list */ - result = modest_text_utils_remove_address (old_cc, from); + dup = modest_text_utils_remove_address (old_cc, from); + result = modest_text_utils_remove_duplicate_addresses (dup); + g_free (dup); g_free (old_cc); return result; } @@ -856,8 +885,8 @@ modest_tny_msg_create_reply_msg (TnyMsg *msg, else { tny_header_set_to (new_header, new_to); g_free (new_to); - } - + } + if (reply_mode == MODEST_TNY_MSG_REPLY_MODE_ALL) { gchar *new_cc = get_new_cc (header, from); if (new_cc) { @@ -865,7 +894,7 @@ modest_tny_msg_create_reply_msg (TnyMsg *msg, g_free (new_cc); } } - + /* Clean */ g_object_unref (G_OBJECT (new_header)); g_object_unref (G_OBJECT (header)); @@ -931,3 +960,55 @@ modest_tny_msg_estimate_size (const gchar *plain_body, const gchar *html_body, return result; } + +GSList * +modest_tny_msg_header_get_all_recipients_list (TnyHeader *header) +{ + GSList *recipients = NULL; + gchar *from = NULL, *to = NULL, *cc = NULL, *bcc = NULL; + + if (header == NULL) + return NULL; + + from = tny_header_dup_from (header); + to = tny_header_dup_to (header); + cc = tny_header_dup_cc (header); + bcc = tny_header_dup_bcc (header); + + recipients = NULL; + if (from) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (from)); + if (to) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (to)); + if (cc) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (cc)); + if (bcc) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (bcc)); + + g_free (from); + g_free (to); + g_free (cc); + g_free (bcc); + + return recipients; +} + +GSList * +modest_tny_msg_get_all_recipients_list (TnyMsg *msg) +{ + TnyHeader *header = NULL; + GSList *recipients = NULL; + + if (msg == NULL) + return NULL; + + header = tny_msg_get_header (msg); + if (header == NULL) + return NULL; + + recipients = modest_tny_msg_header_get_all_recipients_list (header); + g_object_unref (header); + + return recipients; +} +