aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2011-12-22 23:38:51 +0800
committerMilan Crha <mcrha@redhat.com>2011-12-22 23:38:51 +0800
commit0cd98f1a85724293e2583180b8d8dc4b2284647f (patch)
treef7bda6377ad95c40ed5cf8d5a79590f2a9094344 /mail
parent987fb91d5ec4b61d1283acdb9cf02960cc47b74d (diff)
downloadgsoc2013-evolution-0cd98f1a85724293e2583180b8d8dc4b2284647f.tar.gz
gsoc2013-evolution-0cd98f1a85724293e2583180b8d8dc4b2284647f.tar.zst
gsoc2013-evolution-0cd98f1a85724293e2583180b8d8dc4b2284647f.zip
Bug #661087 - Add ability to remove localized "Re:" prefixes in subject
Diffstat (limited to 'mail')
-rw-r--r--mail/em-composer-utils.c13
-rw-r--r--mail/em-utils.c77
-rw-r--r--mail/em-utils.h5
-rw-r--r--mail/message-list.c26
4 files changed, 98 insertions, 23 deletions
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))