* Fixes NB#91689. fixes a wrong check for ASCII
[modest] / src / modest-tny-msg.c
index 0bb700b..db282e1 100644 (file)
@@ -76,8 +76,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)) 
@@ -450,7 +453,7 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht
                g_free (header_content_type_lower);
                g_free (header_content_type);
                return NULL;
-       }
+       }       
        g_free (header_content_type_lower);
        g_free (header_content_type);
 
@@ -471,7 +474,9 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht
                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/");
+               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);
                /* if this part cannot be a supported body return NULL */
                if (!is_text_part) {
@@ -494,6 +499,7 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht
                        /* it's a message --> ignore */
                        if (part && TNY_IS_MSG (part)) {
                                g_object_unref (part);
+                               part = NULL;
                                tny_iterator_next (iter);
                                continue;
                        }                       
@@ -749,7 +755,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;
        
@@ -765,12 +771,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;
@@ -786,6 +791,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) {