X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodest-text-utils.c;h=5cf47bc0c711a4d6a5c889be6a8de51855bbf6ae;hb=b09daad954384d34091b51a04eda7fd3a57a5f22;hp=65b2e9a84f5b2a968c377aeb384ab0f77a82c5ca;hpb=3084439a659fa9aec750337f94cad4bca0c92898;p=modest diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 65b2e9a..5cf47bc 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -198,8 +198,10 @@ modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix) { gchar *tmp; + g_return_val_if_fail (prefix, NULL); + if (!subject) - return g_strdup_printf ("%s ", prefix); + return g_strdup (prefix); tmp = g_strchug (g_strdup (subject)); @@ -211,16 +213,18 @@ modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix) } } -gchar * -modest_text_utils_remove_address (const gchar *address, const gchar *address_list) +gchar* +modest_text_utils_remove_address (const gchar *address_list, const gchar *address) { - char *dup, *token, *ptr, *result; + gchar *dup, *token, *ptr, *result; GString *filtered_emails; - if (!address_list) - return NULL; + g_return_val_if_fail (address_list, NULL); - /* Search for substring */ + if (!address) + return g_strdup (address_list); + + /* search for substring */ if (!strstr ((const char *) address_list, (const char *) address)) return g_strdup (address_list); @@ -233,9 +237,9 @@ modest_text_utils_remove_address (const gchar *address, const gchar *address_lis /* Add to list if not found */ if (!strstr ((const char *) token, (const char *) address)) { if (filtered_emails->len == 0) - g_string_append_printf (filtered_emails, "%s", token); + g_string_append_printf (filtered_emails, "%s", g_strstrip (token)); else - g_string_append_printf (filtered_emails, ",%s", token); + g_string_append_printf (filtered_emails, ",%s", g_strstrip (token)); } token = strtok_r (NULL, ",", &ptr); } @@ -651,3 +655,37 @@ hyperlinkify_plain_text (GString *txt) g_slist_free (match_list); } + + + +gchar* +modest_text_utils_display_address (gchar *address) +{ + gchar *cursor; + + if (!address) + return NULL; + + g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL); + + g_strchug (address); /* remove leading whitespace */ + + /* from display name */ + cursor = g_strstr_len (address, strlen(address), "<"); + if (cursor == address) /* there's nothing else? leave it */ + return address; + if (cursor) + cursor[0]='\0'; + + /* remove (bla bla) from display name */ + cursor = g_strstr_len (address, strlen(address), "("); + if (cursor == address) /* there's nothing else? leave it */ + return address; + if (cursor) + cursor[0]='\0'; + + g_strchomp (address); /* remove trailing whitespace */ + + return address; +} +