[evolution] Bug 774164 - Unicode colon in localized Re: not handled
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 774164 - Unicode colon in localized Re: not handled
- Date: Tue, 29 Nov 2016 20:01:06 +0000 (UTC)
commit 8f15dfa69eb0b58021643a9125657c4309ece96e
Author: Milan Crha <mcrha redhat com>
Date: Tue Nov 29 20:59:01 2016 +0100
Bug 774164 - Unicode colon in localized Re: not handled
data/org.gnome.evolution.mail.gschema.xml.in | 5 ++
src/mail/em-composer-utils.c | 2 +-
src/mail/em-utils.c | 81 ++++++++++++++++++++++----
src/mail/em-utils.h | 3 +-
src/mail/message-list.c | 19 ++++++-
5 files changed, 94 insertions(+), 16 deletions(-)
---
diff --git a/data/org.gnome.evolution.mail.gschema.xml.in b/data/org.gnome.evolution.mail.gschema.xml.in
index 3ca38b9..eb393af 100644
--- a/data/org.gnome.evolution.mail.gschema.xml.in
+++ b/data/org.gnome.evolution.mail.gschema.xml.in
@@ -180,6 +180,11 @@
<_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="composer-localized-re-separators" type="as">
+ <default>['']</default>
+ <_summary>List of localized “Re” separators</_summary>
+ <_description>A list of localized “Re” separators, used to skip in a subject text when replying to a
message, as an addition to the standard “:” and the Unicode “︰” separators.</_description>
+ </key>
<key name="composer-word-wrap-length" type="i">
<default>71</default>
<_summary>Number of characters for wrapping</_summary>
diff --git a/src/mail/em-composer-utils.c b/src/mail/em-composer-utils.c
index d7c1e86..d07108d 100644
--- a/src/mail/em-composer-utils.c
+++ b/src/mail/em-composer-utils.c
@@ -2458,7 +2458,7 @@ reply_setup_composer (EMsgComposer *composer,
if ((subject = (gchar *) camel_mime_message_get_subject (message))) {
gboolean skip_len = -1;
- if (em_utils_is_re_in_subject (subject, &skip_len, NULL) && skip_len > 0)
+ if (em_utils_is_re_in_subject (subject, &skip_len, NULL, NULL) && skip_len > 0)
subject = subject + skip_len;
subject = g_strdup_printf ("Re: %s", subject);
diff --git a/src/mail/em-utils.c b/src/mail/em-utils.c
index 6d4c762..3c37e43 100644
--- a/src/mail/em-utils.c
+++ b/src/mail/em-utils.c
@@ -1404,9 +1404,11 @@ emu_restore_folder_tree_state (EMFolderTree *folder_tree)
static gboolean
check_prefix (const gchar *subject,
- const gchar *prefix,
+ const gchar *prefix,
+ const gchar * const *separators,
gint *skip_len)
{
+ gboolean res = FALSE;
gint plen;
g_return_val_if_fail (subject != NULL, FALSE);
@@ -1418,25 +1420,51 @@ check_prefix (const gchar *subject,
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_isspace (subject[plen]))
+ plen++;
+
+ res = e_util_utf8_strstrcase (subject + plen, ":") == subject + plen;
+ if (res)
+ plen += strlen (":");
+
+ if (!res) {
+ res = e_util_utf8_strstrcase (subject + plen, "︰") == subject + plen;
+ if (res)
+ plen += strlen ("︰");
}
- if (g_ascii_strncasecmp (subject + plen, " : ", 3) == 0) {
- *skip_len = plen + 3;
- return TRUE;
+ if (!res && separators) {
+ gint ii;
+
+ for (ii = 0; separators[ii]; ii++) {
+ const gchar *separator = separators[ii];
+
+ res = *separator && e_util_utf8_strstrcase (subject + plen, separator) == subject +
plen;
+ if (res) {
+ plen += strlen (separator);
+ break;
+ }
+ }
}
- return FALSE;
+ if (res) {
+ if (g_ascii_isspace (subject[plen]))
+ plen++;
+
+ *skip_len = plen;
+ }
+
+ return res;
}
gboolean
em_utils_is_re_in_subject (const gchar *subject,
gint *skip_len,
- const gchar * const *use_prefixes_strv)
+ const gchar * const *use_prefixes_strv,
+ const gchar * const *use_separators_strv)
{
gchar **prefixes_strv;
+ gchar **separators_strv;
gboolean res;
gint ii;
@@ -1448,8 +1476,27 @@ em_utils_is_re_in_subject (const gchar *subject,
if (strlen (subject) < 3)
return FALSE;
- if (check_prefix (subject, "Re", skip_len))
+ if (use_separators_strv) {
+ separators_strv = (gchar **) use_separators_strv;
+ } else {
+ GSettings *settings;
+
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+ separators_strv = g_settings_get_strv (settings, "composer-localized-re-separators");
+ g_object_unref (settings);
+
+ if (separators_strv && !*separators_strv) {
+ g_strfreev (separators_strv);
+ separators_strv = NULL;
+ }
+ }
+
+ if (check_prefix (subject, "Re", (const gchar * const *) separators_strv, skip_len)) {
+ if (!use_separators_strv)
+ g_strfreev (separators_strv);
+
return TRUE;
+ }
if (use_prefixes_strv) {
prefixes_strv = (gchar **) use_prefixes_strv;
@@ -1463,6 +1510,10 @@ em_utils_is_re_in_subject (const gchar *subject,
if (!prefixes || !*prefixes) {
g_free (prefixes);
+
+ if (!use_separators_strv)
+ g_strfreev (separators_strv);
+
return FALSE;
}
@@ -1470,8 +1521,12 @@ em_utils_is_re_in_subject (const gchar *subject,
g_free (prefixes);
}
- if (!prefixes_strv)
+ if (!prefixes_strv) {
+ if (!use_separators_strv)
+ g_strfreev (separators_strv);
+
return FALSE;
+ }
res = FALSE;
@@ -1479,11 +1534,13 @@ em_utils_is_re_in_subject (const gchar *subject,
const gchar *prefix = prefixes_strv[ii];
if (*prefix)
- res = check_prefix (subject, prefix, skip_len);
+ res = check_prefix (subject, prefix, (const gchar * const *) separators_strv,
skip_len);
}
if (!use_prefixes_strv)
g_strfreev (prefixes_strv);
+ if (!use_separators_strv)
+ g_strfreev (separators_strv);
return res;
}
diff --git a/src/mail/em-utils.h b/src/mail/em-utils.h
index fe61984..6a0787c 100644
--- a/src/mail/em-utils.h
+++ b/src/mail/em-utils.h
@@ -77,7 +77,8 @@ void emu_restore_folder_tree_state (EMFolderTree *folder_tree);
gboolean em_utils_is_re_in_subject (const gchar *subject,
gint *skip_len,
- const gchar * const *use_prefixes_strv);
+ const gchar * const *use_prefixes_strv,
+ const gchar * const *use_separators_strv);
gchar * em_utils_get_archive_folder_uri_from_folder
(CamelFolder *folder,
diff --git a/src/mail/message-list.c b/src/mail/message-list.c
index ad6b1e3..c7fe249 100644
--- a/src/mail/message-list.c
+++ b/src/mail/message-list.c
@@ -124,6 +124,7 @@ struct _MessageListPrivate {
GSettings *mail_settings;
gchar **re_prefixes;
+ gchar **re_separators;
GMutex re_prefixes_lock;
};
@@ -790,7 +791,8 @@ get_normalised_string (MessageList *message_list,
while (found_re) {
g_mutex_lock (&message_list->priv->re_prefixes_lock);
found_re = em_utils_is_re_in_subject (
- subject, &skip_len, (const gchar * const *) message_list->priv->re_prefixes)
&& skip_len > 0;
+ subject, &skip_len, (const gchar * const *) message_list->priv->re_prefixes,
+ (const gchar * const *) message_list->priv->re_separators) && skip_len > 0;
g_mutex_unlock (&message_list->priv->re_prefixes_lock);
if (found_re)
@@ -1729,7 +1731,8 @@ get_trimmed_subject (CamelMessageInfo *info,
g_mutex_lock (&message_list->priv->re_prefixes_lock);
found_re = em_utils_is_re_in_subject (
- subject, &skip_len, (const gchar * const *) message_list->priv->re_prefixes)
&& skip_len > 0;
+ subject, &skip_len, (const gchar * const *) message_list->priv->re_prefixes,
+ (const gchar * const *) message_list->priv->re_separators) && skip_len > 0;
g_mutex_unlock (&message_list->priv->re_prefixes_lock);
if (found_re)
subject += skip_len;
@@ -2968,6 +2971,7 @@ message_list_finalize (GObject *object)
g_free (message_list->frozen_search);
g_free (message_list->cursor_uid);
g_strfreev (message_list->priv->re_prefixes);
+ g_strfreev (message_list->priv->re_separators);
g_mutex_clear (&message_list->priv->regen_lock);
g_mutex_clear (&message_list->priv->thread_tree_lock);
@@ -3669,6 +3673,7 @@ message_list_init (MessageList *message_list)
message_list->priv->mail_settings = e_util_ref_settings ("org.gnome.evolution.mail");
message_list->priv->re_prefixes = NULL;
+ message_list->priv->re_separators = NULL;
message_list->priv->group_by_threads = TRUE;
}
@@ -6313,10 +6318,20 @@ mail_regen_list (MessageList *message_list,
}
g_mutex_lock (&message_list->priv->re_prefixes_lock);
+
g_strfreev (message_list->priv->re_prefixes);
prefixes = g_settings_get_string (message_list->priv->mail_settings, "composer-localized-re");
message_list->priv->re_prefixes = g_strsplit (prefixes ? prefixes : "", ",", -1);
g_free (prefixes);
+
+ g_strfreev (message_list->priv->re_separators);
+ message_list->priv->re_separators = g_settings_get_strv (message_list->priv->mail_settings,
"composer-localized-re-separators");
+
+ if (message_list->priv->re_separators && !*message_list->priv->re_separators) {
+ g_strfreev (message_list->priv->re_separators);
+ message_list->priv->re_separators = NULL;
+ }
+
g_mutex_unlock (&message_list->priv->re_prefixes_lock);
g_mutex_lock (&message_list->priv->regen_lock);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]