Do not use the localized form of "Re:" and "Fw:" if those versions are already presen...
authorSergio Villar Senin <svillar@igalia.com>
Mon, 16 Nov 2009 17:07:19 +0000 (18:07 +0100)
committerSergio Villar Senin <svillar@igalia.com>
Mon, 16 Nov 2009 17:07:19 +0000 (18:07 +0100)
Fixes NB#142363

src/modest-text-utils.c
src/modest-text-utils.h
src/modest-tny-msg.c

index 5aab3a3..af46517 100644 (file)
@@ -297,10 +297,12 @@ modest_text_utils_strftime(char *s, gsize max, const char *fmt, time_t timet)
 }
 
 gchar *
-modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix)
+modest_text_utils_derived_subject (const gchar *subject, gboolean is_reply)
 {
-       gchar *tmp, *subject_dup, *retval;
-       gint 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);
 
@@ -310,13 +312,23 @@ modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix)
        subject_dup = g_strdup (subject);
        tmp = g_strchug (subject_dup);
 
+       prefix = (is_reply) ? _("mail_va_re") : _("mail_va_fw");
+       prefix = g_strconcat (prefix, ":", NULL);
+       prefix_len = g_utf8_strlen (prefix, -1);
+
+       untranslated_prefix =  (is_reply) ? "Re:" : "Fw:";
+       untranslated_prefix_len = 3;
+
        /* We do not want things like "Re: Re: Re:" or "Fw: Fw:" so
           delete the previous ones */
-       prefix_len = strlen (prefix);
        do {
                if (g_str_has_prefix (tmp, prefix)) {
                        tmp += 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;
 
@@ -338,8 +350,9 @@ modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix)
                }
        } while (tmp);
 
-       retval = g_strdup_printf ("%s %s", prefix, tmp);
+       retval = g_strdup_printf ("%s %s", (untranslated_found) ? untranslated_prefix : prefix, tmp);
        g_free (subject_dup);
+       g_free (prefix);
 
        return retval;
 }
index 59c0714..00c42ca 100644 (file)
@@ -62,16 +62,22 @@ extern const guint USER_NAME_FORBIDDEN_CHARS_LENGTH;
 /**
  * modest_text_utils_derived_subject:
  * @subject: a string which contains the original subject
- * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:'),
- *           must not be NULL
+ * @is_reply: whether the derived subject is for a reply or a forward message
+ *
+ * create a 'derived' subject line for eg. replies and forwards. Note
+ * that this function will use the localized versions of "Re" and
+ * "Fw", unless one of these two versions was already included. For
+ * example replying to an email in Finish would work as:
+ *
+ * "some subject"     -> "VS: some subject"
+ * "VS: some subject" -> "VS: some subject"
+ * "Re: some subject" -> "Re: some subject"
+ * "Fw: some subject" -> "VS: Fw: some subject"
  *
- * create a 'derived' subject line for eg. replies and forwards 
- * 
  * Returns: a newly allocated string containing the resulting subject
- * subject == NULL, then @prefix " " will be returned
  */
-gchar* modest_text_utils_derived_subject (const gchar *subject, 
-                                         const gchar* prefix);
+gchar* modest_text_utils_derived_subject (const gchar *subject,
+                                         gboolean is_reply);
 
 
 /**
index 2399070..295af0a 100644 (file)
@@ -664,7 +664,6 @@ create_reply_forward_mail (TnyMsg *msg, TnyHeader *header, const gchar *from,
        TnyMimePart *body = NULL;
        TnyMimePart *html_body = NULL;
        ModestFormatter *formatter;
-       gchar *subject_prefix;
        gboolean no_text_part;
        gchar *parent_uid;
        gboolean forward_as_attach = FALSE;
@@ -718,16 +717,10 @@ create_reply_forward_mail (TnyMsg *msg, TnyHeader *header, const gchar *from,
        tny_header_set_replyto (new_header, from);
 
        /* Change the subject */
-       if (is_reply)
-               subject_prefix = g_strconcat (_("mail_va_re"), ":", NULL);
-       else
-               subject_prefix = g_strconcat (_("mail_va_fw"), ":", NULL);
        old_subject = tny_header_dup_subject (header);
        new_subject =
-               (gchar *) modest_text_utils_derived_subject (old_subject,
-                                                            subject_prefix);
+               (gchar *) modest_text_utils_derived_subject (old_subject, is_reply);
        g_free (old_subject);
-       g_free (subject_prefix);
        tny_header_set_subject (new_header, (const gchar *) new_subject);
        g_free (new_subject);