* modest-text-utils.[ch]:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sun, 10 Dec 2006 18:17:51 +0000 (18:17 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sun, 10 Dec 2006 18:17:51 +0000 (18:17 +0000)
  - add modest_text_utils_display_address

pmo-trunk-r533

src/modest-text-utils.c
src/modest-text-utils.h

index ab90ef3..1fb11e7 100644 (file)
@@ -651,3 +651,29 @@ hyperlinkify_plain_text (GString *txt)
        
        g_slist_free (match_list);
 }
        
        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);
+
+       /* simplistic --> remove <email@address> from display name */
+       cursor = g_strstr_len (address, strlen(address), "<");
+       if (cursor) 
+               cursor[0]='\0';
+
+       /* simplistic --> remove (bla bla) from display name */
+       cursor = g_strstr_len (address, strlen(address), "(");
+       if (cursor) 
+               cursor[0]='\0';
+       
+       return address;
+}
+
index c3199f9..05a4b9b 100644 (file)
@@ -139,4 +139,19 @@ gchar*  modest_text_utils_convert_to_html (const gchar *data);
 size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, const  struct tm *tm);
 
 
 size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, const  struct tm *tm);
 
 
+
+/**
+ * modest_text_utils_display_addres:
+ * @address: original address (UTF8 string)
+ *
+ * make a 'display address' from an address:
+ * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar" 
+ * the change is in-place
+ * 
+ * Returns: the new address. The string is *not* newly allocated.
+ * NULL in case of error
+ */
+gchar* modest_text_utils_display_address (gchar *address);
+
+
 #endif /* __MODEST_TEXT_UTILS_H__ */
 #endif /* __MODEST_TEXT_UTILS_H__ */