From: Sergio Villar Senin Date: Fri, 4 Sep 2009 11:41:07 +0000 (+0200) Subject: Check emails addresses case when checking the presence of our email address when... X-Git-Tag: 3.0.17-rc49~1 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=a97791ec68e7d15593080049399bda9366517b1e;ds=inline Check emails addresses case when checking the presence of our email address when replying to emails (fixes NB#132706) --- diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 8161ae5..020b160 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -342,6 +342,39 @@ modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix) return retval; } + +/* Performs a case-insensitive strstr for ASCII strings */ +static const gchar * +ascii_stristr(const gchar *haystack, const gchar *needle) +{ + int needle_len; + int haystack_len; + const gchar *pos; + const gchar *max_pos; + + if (haystack == NULL || needle == NULL) { + return haystack; /* as in strstr */ + } + + needle_len = strlen(needle); + + if (needle_len == 0) { + return haystack; /* as in strstr */ + } + + haystack_len = strlen(haystack); + max_pos = haystack + haystack_len - needle_len; + + for (pos = haystack; pos <= max_pos; pos++) { + if (g_ascii_strncasecmp (pos, needle, needle_len) == 0) { + return pos; + } + } + + return NULL; +} + + gchar* modest_text_utils_remove_address (const gchar *address_list, const gchar *address) { @@ -350,26 +383,26 @@ modest_text_utils_remove_address (const gchar *address_list, const gchar *addres gchar *email_address; g_return_val_if_fail (address_list, NULL); - + if (!address) return g_strdup (address_list); email_address = get_email_from_address (address); - + /* search for substring */ - if (!strstr ((const char *) address_list, (const char *) email_address)) { + if (!ascii_stristr ((const char *) address_list, (const char *) email_address)) { g_free (email_address); return g_strdup (address_list); } dup = g_strdup (address_list); filtered_emails = g_string_new (NULL); - + token = strtok_r (dup, ",", &ptr); while (token != NULL) { /* Add to list if not found */ - if (!strstr ((const char *) token, (const char *) email_address)) { + if (!ascii_stristr ((const char *) token, (const char *) email_address)) { if (filtered_emails->len == 0) g_string_append_printf (filtered_emails, "%s", g_strstrip (token)); else