* Rewritten some async calls
[modest] / src / modest-text-utils.c
index 1fb11e7..4262066 100644 (file)
@@ -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));
 
@@ -233,9 +235,9 @@ modest_text_utils_remove_address (const gchar *address_list, const gchar *addres
                /* 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);
        }
@@ -664,16 +666,24 @@ modest_text_utils_display_address (gchar *address)
 
        g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
 
-       /* simplistic --> remove <email@address> from display name */
+       g_strchug (address); /* remove leading whitespace */
+
+       /*  <email@address> 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';
 
-       /* simplistic --> remove (bla bla) from display name */
+       /* 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;
 }