tny_header_set_from (TNY_HEADER (header), from);
tny_header_set_replyto (TNY_HEADER (header), from);
}
- if ((mailto != NULL) && (strlen(mailto) > 0))
- tny_header_set_to (TNY_HEADER (header), mailto);
+ if ((mailto != NULL) && (strlen(mailto) > 0)) {
+ gchar *removed_to = modest_text_utils_remove_duplicate_addresses (mailto);
+ tny_header_set_to (TNY_HEADER (header), removed_to);
+ g_free (removed_to);
+ }
if ((cc != NULL) && (strlen(cc) > 0))
tny_header_set_cc (TNY_HEADER (header), cc);
if ((bcc != NULL) && (strlen(bcc) > 0))
return new_msg;
}
+
+
+static gint
+count_addresses (const gchar* addresses)
+{
+ gint count = 1;
+
+ if (!addresses)
+ return 0;
+
+ while (*addresses) {
+ if (*addresses == ',' || *addresses == ';')
+ ++count;
+ ++addresses;
+ }
+
+ return count;
+}
+
+
/* get the new To:, based on the old header,
* result is newly allocated or NULL in case of error
* */
/* remove duplicate entries */
gchar *tmp = modest_text_utils_remove_duplicate_addresses (new_to);
g_free (new_to);
- new_to = tmp;
+ new_to = tmp;
+
+ /* now, strip me (the new From:) from the new_to, but only if
+ * there are >1 addresses there */
+ if (count_addresses (new_to) > 1) {
+ gchar *tmp = modest_text_utils_remove_address (new_to, from);
+ g_free (new_to);
+ new_to = tmp;
+ }
}
return new_to;