+static void
+set_contact_from_display_name (EContact *contact, const gchar *disp_name)
+{
+ const gchar *parent_open;
+ const gchar *comma_separator;
+ GString *buffer;
+ gchar *display_name;
+
+ display_name = unquote_string (disp_name);
+ buffer = g_string_new ("");
+
+ /* First we remove part in () */
+ parent_open = g_strstr_len (display_name, -1, "(");
+ if (parent_open) {
+ const gchar *parent_close;
+
+ parent_close = g_strstr_len (parent_open, -1, ")");
+
+ buffer = g_string_append_len (buffer, display_name, parent_open - display_name);
+ if (parent_close) {
+ buffer = g_string_append (buffer, parent_close + 1);
+ }
+ } else {
+ buffer = g_string_append (buffer, display_name);
+ }
+
+ comma_separator = g_strstr_len (buffer->str, -1, ", ");
+ if (comma_separator) {
+ gchar *surname, *name;
+ surname = g_strndup (buffer->str, comma_separator - buffer->str);
+ name = g_strdup (comma_separator + 2);
+
+ e_contact_set (contact, E_CONTACT_FAMILY_NAME, (const gpointer) surname);
+ e_contact_set (contact, E_CONTACT_GIVEN_NAME, (const gpointer) name);
+ g_free (name);
+ g_free (surname);
+ } else {
+ e_contact_set (contact, E_CONTACT_GIVEN_NAME, (const gpointer) buffer->str);
+ }
+
+ g_string_free (buffer, TRUE);
+ g_free (display_name);
+}