start_pos = (*((gint*) current_start->data)) + offset_delta;
end_pos = (*((gint*) current_end->data)) + offset_delta;
-
+
start_ptr = g_utf8_offset_to_pointer (recipients, start_pos);
end_ptr = g_utf8_offset_to_pointer (recipients, end_pos);
}
/* Add addresses to address-book */
- if (to_commit_addresses)
- add_to_address_book (to_commit_addresses);
+ if (to_commit_addresses) {
+ to_commit_addresses = modest_text_utils_remove_duplicate_addresses_list (to_commit_addresses);
+ if (to_commit_addresses)
+ add_to_address_book (to_commit_addresses);
+ }
if (current_start == NULL) {
gtk_text_buffer_get_end_iter (buffer, &end_iter);
return g_string_free (result, FALSE);
}
+
+GSList *
+modest_text_utils_remove_duplicate_addresses_list (GSList *address_list)
+{
+ GSList *new_list, *iter;
+ GHashTable *table;
+
+ g_return_val_if_fail (address_list, NULL);
+
+ table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ new_list = address_list;
+ iter = address_list;
+ while (iter) {
+ const gchar* address = (const gchar*)iter->data;
+
+ /* We need only the email to just compare it and not
+ the full address which would make "a <a@a.com>"
+ different from "a@a.com" */
+ const gchar *email = get_email_from_address (address);
+
+ /* ignore the address if already seen */
+ if (g_hash_table_lookup (table, email) == 0) {
+ g_hash_table_insert (table, (gchar*)email, GINT_TO_POINTER(1));
+ iter = g_slist_next (iter);
+ } else {
+ GSList *tmp = g_slist_next (iter);
+ new_list = g_slist_delete_link (new_list, iter);
+ iter = tmp;
+ }
+ }
+
+ g_hash_table_unref (table);
+
+ return new_list;
+}
*/
gchar *modest_text_utils_simplify_recipients (const gchar *recipient);
+/**
+ * modest_text_utils_remove_duplicate_addresses_list
+ * @address_list: non-NULL #GSList of email addresses
+ *
+ * remove duplicate addresses from a list of email addresses
+ *
+ * Returns: a list without the duplicate addresses or NULL in case of
+ * error or the original @address_list was NULL
+ */
+GSList *modest_text_utils_remove_duplicate_addresses_list (GSList *address_list);
+
#endif /* __MODEST_TEXT_UTILS_H__ */