{
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));
}
}
-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);
/* 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);
}
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 */
+
+ /* <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';
+
+ /* 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;
+}
+