Do ignore empty recipients when checking names
[modest] / src / modest-text-utils.c
index af46517..fb4da84 100644 (file)
@@ -302,9 +302,8 @@ modest_text_utils_derived_subject (const gchar *subject, gboolean is_reply)
        gchar *tmp, *subject_dup, *retval, *prefix;
        const gchar *untranslated_prefix;
        gint prefix_len, untranslated_prefix_len;
        gchar *tmp, *subject_dup, *retval, *prefix;
        const gchar *untranslated_prefix;
        gint prefix_len, untranslated_prefix_len;
-       gboolean untranslated_found = FALSE;
-
-       g_return_val_if_fail (prefix, NULL);
+       gboolean translated_found = FALSE;
+       gboolean first_time;
 
        if (!subject || subject[0] == '\0')
                subject = _("mail_va_no_subject");
 
        if (!subject || subject[0] == '\0')
                subject = _("mail_va_no_subject");
@@ -321,14 +320,18 @@ modest_text_utils_derived_subject (const gchar *subject, gboolean is_reply)
 
        /* We do not want things like "Re: Re: Re:" or "Fw: Fw:" so
           delete the previous ones */
 
        /* We do not want things like "Re: Re: Re:" or "Fw: Fw:" so
           delete the previous ones */
+       first_time = TRUE;
        do {
                if (g_str_has_prefix (tmp, prefix)) {
                        tmp += prefix_len;
                        tmp = g_strchug (tmp);
        do {
                if (g_str_has_prefix (tmp, prefix)) {
                        tmp += prefix_len;
                        tmp = g_strchug (tmp);
+                       /* Do not consider translated prefixes in the
+                          middle of a Re:Re:..Re: like sequence */
+                       if (G_UNLIKELY (first_time))
+                               translated_found = TRUE;
                } else if (g_str_has_prefix (tmp, untranslated_prefix)) {
                        tmp += untranslated_prefix_len;
                        tmp = g_strchug (tmp);
                } else if (g_str_has_prefix (tmp, untranslated_prefix)) {
                        tmp += untranslated_prefix_len;
                        tmp = g_strchug (tmp);
-                       untranslated_found = TRUE;
                } else {
                        gchar *prefix_down, *tmp_down;
 
                } else {
                        gchar *prefix_down, *tmp_down;
 
@@ -348,9 +351,20 @@ modest_text_utils_derived_subject (const gchar *subject, gboolean is_reply)
                                break;
                        }
                }
                                break;
                        }
                }
+               first_time = FALSE;
        } while (tmp);
 
        } while (tmp);
 
-       retval = g_strdup_printf ("%s %s", (untranslated_found) ? untranslated_prefix : prefix, tmp);
+       if (!g_strcmp0 (subject, tmp)) {
+               /* normal case */
+               retval = g_strdup_printf ("%s %s", untranslated_prefix, tmp);
+       } else {
+               if (translated_found) {
+                       /* Found a translated prefix, i.e, "VS:" in Finish */
+                       retval = g_strdup_printf ("%s %s", prefix, tmp);
+               } else {
+                       retval = g_strdup_printf ("%s %s", untranslated_prefix, tmp);
+               }
+       }
        g_free (subject_dup);
        g_free (prefix);
 
        g_free (subject_dup);
        g_free (prefix);
 
@@ -502,7 +516,7 @@ modest_text_utils_convert_buffer_to_html_start (GString *html, const gchar *data
                guchar kar = data[i];
                
                if (space_seen && kar != ' ') {
                guchar kar = data[i];
                
                if (space_seen && kar != ' ') {
-                       g_string_append (html, " ");
+                       g_string_append (html, " ");
                        space_seen = FALSE;
                }
                
                        space_seen = FALSE;
                }
                
@@ -638,7 +652,7 @@ modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_
                        gchar *next_char = g_utf8_next_char (cur);
 
                        if (!g_utf8_strchr (start, (cur - start + 1), g_utf8_get_char ("@")) &&
                        gchar *next_char = g_utf8_next_char (cur);
 
                        if (!g_utf8_strchr (start, (cur - start + 1), g_utf8_get_char ("@")) &&
-                           next_char && *next_char != '\n')
+                           next_char && *next_char != '\n' && *next_char != '\0')
                                continue;
 
                        start_index = g_new0 (gint, 1);
                                continue;
 
                        start_index = g_new0 (gint, 1);
@@ -2179,8 +2193,7 @@ static void
 quote_name_part (GString **str, gchar **cur, gchar **start)
 {
        gchar *blank;
 quote_name_part (GString **str, gchar **cur, gchar **start)
 {
        gchar *blank;
-       gint str_len = g_utf8_pointer_to_offset (*start, *cur) -
-               g_utf8_pointer_to_offset (*start, *start);
+       gint str_len = *cur - *start;
 
        while (**start == ' ') {
                *start = g_utf8_next_char (*start);
 
        while (**start == ' ') {
                *start = g_utf8_next_char (*start);
@@ -2195,13 +2208,9 @@ quote_name_part (GString **str, gchar **cur, gchar **start)
                        *start = g_utf8_next_char (*cur);
                } else {
                        *str = g_string_append_c (*str, '"');
                        *start = g_utf8_next_char (*cur);
                } else {
                        *str = g_string_append_c (*str, '"');
-                       *str = g_string_append_len (*str, *start,
-                                                   (g_utf8_pointer_to_offset (*start, blank) -
-                                                    g_utf8_pointer_to_offset (*start, *start)));
+                       *str = g_string_append_len (*str, *start, (blank - *start));
                        *str = g_string_append_c (*str, '"');
                        *str = g_string_append_c (*str, '"');
-                       *str = g_string_append_len (*str, blank,
-                                                   (g_utf8_pointer_to_offset (*start, *cur) -
-                                                    g_utf8_pointer_to_offset (*start, blank)));
+                       *str = g_string_append_len (*str, blank, (*cur - blank));
                        *str = g_string_append (*str, ";");
                        *start = g_utf8_next_char (*cur);
                }
                        *str = g_string_append (*str, ";");
                        *start = g_utf8_next_char (*cur);
                }