diff options
-rw-r--r-- | data/org.gnome.evolution.mail.gschema.xml.in | 5 | ||||
-rw-r--r-- | mail/em-composer-utils.c | 13 | ||||
-rw-r--r-- | mail/em-utils.c | 77 | ||||
-rw-r--r-- | mail/em-utils.h | 5 | ||||
-rw-r--r-- | mail/message-list.c | 26 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-settings.c | 5 |
6 files changed, 108 insertions, 23 deletions
diff --git a/data/org.gnome.evolution.mail.gschema.xml.in b/data/org.gnome.evolution.mail.gschema.xml.in index 150fff59c6..e6b02d37f5 100644 --- a/data/org.gnome.evolution.mail.gschema.xml.in +++ b/data/org.gnome.evolution.mail.gschema.xml.in @@ -125,6 +125,11 @@ <_summary>Ignore list Reply-To:</_summary> <_description>Some mailing lists set a Reply-To: header to trick users into sending replies to the list, even when they ask Evolution to make a private reply. Setting this option to TRUE will attempt to ignore such Reply-To: headers, so that Evolution will do as you ask it. If you use the private reply action, it will reply privately, while if you use the 'Reply to List' action it will do that. It works by comparing the Reply-To: header with a List-Post: header, if there is one.</_description> </key> + <key name="composer-localized-re" type="s"> + <default>''</default> + <_summary>List of localized 'Re'</_summary> + <_description>Comma-separated list of localized 'Re' abbreviations to skip in a subject text when replying to a message, as an addition to the standard "Re" prefix. An example is 'SV,AV'.</_description> + </key> <key name="show-animated-images" type="b"> <default>false</default> <_summary>Show image animations</_summary> diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index be2b965541..850a5e5796 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -1936,13 +1936,12 @@ reply_get_composer (EShell *shell, /* Set the subject of the new message. */ if ((subject = (gchar *) camel_mime_message_get_subject (message))) { - if (g_ascii_strncasecmp (subject, "Re: ", 4) != 0 && - g_ascii_strncasecmp (subject, "Re : ", 5) != 0) - subject = g_strdup_printf ("Re: %s", subject); - else if (g_ascii_strncasecmp (subject, "Re : ", 5) == 0) - subject = g_strdup_printf ("Re: %s", subject + 5); - else - subject = g_strdup (subject); + gboolean skip_len = -1; + + if (em_utils_is_re_in_subject (shell, subject, &skip_len) && skip_len > 0) + subject = subject + skip_len; + + subject = g_strdup_printf ("Re: %s", subject); } else { subject = g_strdup (""); } diff --git a/mail/em-utils.c b/mail/em-utils.c index bb6625671e..ac8a4369c4 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -2380,3 +2380,80 @@ em_utils_disconnect_service_sync (CamelService *service, return res; } +static gboolean +check_prefix (const gchar *subject, + const gchar *prefix, + gint *skip_len) +{ + gint plen; + + g_return_val_if_fail (subject != NULL, FALSE); + g_return_val_if_fail (prefix != NULL, FALSE); + g_return_val_if_fail (*prefix, FALSE); + g_return_val_if_fail (skip_len != NULL, FALSE); + + plen = strlen (prefix); + if (g_ascii_strncasecmp (subject, prefix, plen) != 0) + return FALSE; + + if (g_ascii_strncasecmp (subject + plen, ": ", 2) == 0) { + *skip_len = plen + 2; + return TRUE; + } + + if (g_ascii_strncasecmp (subject + plen, " : ", 3) == 0) { + *skip_len = plen + 3; + return TRUE; + } + + return FALSE; +} + +gboolean +em_utils_is_re_in_subject (EShell *shell, + const gchar *subject, + gint *skip_len) +{ + EShellSettings *shell_settings; + gchar *prefixes, **prefixes_strv; + gboolean res; + gint ii; + + g_return_val_if_fail (shell != NULL, FALSE); + g_return_val_if_fail (subject != NULL, FALSE); + g_return_val_if_fail (skip_len != NULL, FALSE); + + *skip_len = -1; + + if (strlen (subject) < 3) + return FALSE; + + if (check_prefix (subject, "Re", skip_len)) + return TRUE; + + shell_settings = e_shell_get_shell_settings (shell); + prefixes = e_shell_settings_get_string (shell_settings, "composer-localized-re"); + if (!prefixes || !*prefixes) { + g_free (prefixes); + return FALSE; + } + + prefixes_strv = g_strsplit (prefixes, ",", -1); + g_free (prefixes); + + if (!prefixes_strv) + return FALSE; + + res = FALSE; + + for (ii = 0; !res && prefixes_strv[ii]; ii++) { + const gchar *prefix = prefixes_strv[ii]; + + if (*prefix) + res = check_prefix (subject, prefix, skip_len); + } + + g_strfreev (prefixes_strv); + + return res; +} diff --git a/mail/em-utils.h b/mail/em-utils.h index 6f18d96521..f3879ae484 100644 --- a/mail/em-utils.h +++ b/mail/em-utils.h @@ -36,6 +36,7 @@ G_BEGIN_DECLS struct _EMFormat; +struct _EShell; gboolean em_utils_ask_open_many (GtkWindow *parent, gint how_many); gboolean em_utils_prompt_user (GtkWindow *parent, const gchar *promptkey, const gchar *tag, ...); @@ -104,6 +105,10 @@ gboolean em_utils_is_local_delivery_mbox_file (CamelURL *url); gboolean em_utils_connect_service_sync (CamelService *service, GCancellable *cancellable, GError **error); gboolean em_utils_disconnect_service_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error); +gboolean em_utils_is_re_in_subject (struct _EShell *shell, + const gchar *subject, + gint *skip_len); + G_END_DECLS #endif /* __EM_UTILS_H__ */ diff --git a/mail/message-list.c b/mail/message-list.c index 79b6875328..b2fb46e9e1 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -499,20 +499,16 @@ get_normalised_string (MessageList *message_list, } if (col == COL_SUBJECT_NORM) { + EShell *shell = e_shell_get_default (); + gint skip_len; const guchar *subject; gboolean found_re = TRUE; subject = (const guchar *) string; while (found_re) { - found_re = FALSE; - - if (g_ascii_strncasecmp ((gchar *) subject, "Re:", 3) == 0) { - found_re = TRUE; - subject += 3; - } else if (g_ascii_strncasecmp ((gchar *) subject, "Re :", 4) == 0) { - found_re = TRUE; - subject += 4; - } + found_re = em_utils_is_re_in_subject (shell, (const gchar *) subject, &skip_len) && skip_len > 0; + if (found_re) + subject += skip_len; /* jump over any spaces */ while (*subject && isspace ((gint) *subject)) @@ -1553,6 +1549,8 @@ get_trimmed_subject (CamelMessageInfo *info) } do { + EShell *shell = e_shell_get_default (); + gint skip_len; gboolean found_re = TRUE; found_mlist = FALSE; @@ -1560,13 +1558,9 @@ get_trimmed_subject (CamelMessageInfo *info) while (found_re) { found_re = FALSE; - if (g_ascii_strncasecmp ((gchar *) subject, "Re:", 3) == 0) { - found_re = TRUE; - subject += 3; - } else if (g_ascii_strncasecmp ((gchar *) subject, "Re :", 4) == 0) { - found_re = TRUE; - subject += 4; - } + found_re = em_utils_is_re_in_subject (shell, (const gchar *) subject, &skip_len) && skip_len > 0; + if (found_re) + subject += skip_len; /* jump over any spaces */ while (*subject && isspace ((gint) *subject)) diff --git a/modules/mail/e-mail-shell-settings.c b/modules/mail/e-mail-shell-settings.c index c74dd3eee0..49a406e0d0 100644 --- a/modules/mail/e-mail-shell-settings.c +++ b/modules/mail/e-mail-shell-settings.c @@ -314,6 +314,11 @@ e_mail_shell_settings_init (EShellBackend *shell_backend) "composer-outlook-filenames"); e_shell_settings_install_property_for_key ( + "composer-localized-re", + MAIL_SCHEMA, + "composer-localized-re"); + + e_shell_settings_install_property_for_key ( "composer-ignore-list-reply-to", MAIL_SCHEMA, "composer-ignore-list-reply-to"); |