diff options
-rw-r--r-- | libemail-engine/e-mail-session-utils.c | 3 | ||||
-rw-r--r-- | libemail-engine/e-mail-utils.c | 41 | ||||
-rw-r--r-- | libemail-engine/e-mail-utils.h | 2 | ||||
-rw-r--r-- | libemail-engine/mail-ops.c | 3 |
4 files changed, 49 insertions, 0 deletions
diff --git a/libemail-engine/e-mail-session-utils.c b/libemail-engine/e-mail-session-utils.c index 7e1aae3ef8..b2d3643319 100644 --- a/libemail-engine/e-mail-session-utils.c +++ b/libemail-engine/e-mail-session-utils.c @@ -880,6 +880,9 @@ e_mail_session_send_to (EMailSession *session, get_message_size (message, cancellable); camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, ~0); + /* expand, or remove empty, group addresses */ + em_utils_expand_groups (CAMEL_INTERNET_ADDRESS (recipients)); + /* The rest of the processing happens in a thread. */ context = g_slice_new0 (AsyncContext); diff --git a/libemail-engine/e-mail-utils.c b/libemail-engine/e-mail-utils.c index 2644c00638..48b2a7b679 100644 --- a/libemail-engine/e-mail-utils.c +++ b/libemail-engine/e-mail-utils.c @@ -706,3 +706,44 @@ em_utils_is_local_delivery_mbox_file (CamelURL *url) !g_file_test (url->path, G_FILE_TEST_IS_DIR); } +/* Expands groups to individual addresses, or removes empty groups completely. + Usual email addresses are left untouched. +*/ +void +em_utils_expand_groups (CamelInternetAddress *addresses) +{ + gint ii, len; + const gchar *addr; + CamelAddress *addrs; + + g_return_if_fail (CAMEL_IS_INTERNET_ADDRESS (addresses)); + + addrs = CAMEL_ADDRESS (addresses); + len = camel_address_length (addrs); + for (ii = len - 1; ii >= 0; ii--) { + addr = NULL; + + if (!camel_internet_address_get (addresses, ii, NULL, &addr)) { + camel_address_remove (addrs, ii); + } else if (addr) { + gchar *encoded = camel_internet_address_encode_address (NULL, NULL, addr); + + if (encoded) { + CamelInternetAddress *iaddr = camel_internet_address_new (); + gint decoded; + + /* decode expands respective groups */ + decoded = camel_address_decode (CAMEL_ADDRESS (iaddr), encoded); + if (decoded <= 0 || decoded > 1) { + camel_address_remove (addrs, ii); + + if (decoded > 1) + camel_address_cat (addrs, CAMEL_ADDRESS (iaddr)); + } + + g_object_unref (iaddr); + g_free (encoded); + } + } + } +} diff --git a/libemail-engine/e-mail-utils.h b/libemail-engine/e-mail-utils.h index b9201d9c14..dbe6fb6846 100644 --- a/libemail-engine/e-mail-utils.h +++ b/libemail-engine/e-mail-utils.h @@ -74,4 +74,6 @@ void em_utils_uids_free (GPtrArray *uids); gboolean em_utils_is_local_delivery_mbox_file (CamelURL *url); +void em_utils_expand_groups (CamelInternetAddress *addresses); + #endif /* E_MAIL_UTILS_H */ diff --git a/libemail-engine/mail-ops.c b/libemail-engine/mail-ops.c index ec3e9bc992..dccd001335 100644 --- a/libemail-engine/mail-ops.c +++ b/libemail-engine/mail-ops.c @@ -635,6 +635,9 @@ mail_send_message (struct _send_queue_msg *m, service, cancellable, error)) goto exit; + /* expand, or remove empty, group addresses */ + em_utils_expand_groups (CAMEL_INTERNET_ADDRESS (recipients)); + if (!camel_transport_send_to_sync ( CAMEL_TRANSPORT (service), message, from, recipients, cancellable, error)) |