diff options
author | Milan Crha <mcrha@redhat.com> | 2013-06-04 01:18:23 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2013-06-04 01:22:03 +0800 |
commit | 5b0e9e7791cc960408fb772e9a1ec05037b5719a (patch) | |
tree | d30f024f22fe83bf193beada7425736cffa7e39a /libemail-engine | |
parent | 853c7125c183cef4b72cf6904cc21114066a3117 (diff) | |
download | gsoc2013-evolution-5b0e9e7791cc960408fb772e9a1ec05037b5719a.tar.gz gsoc2013-evolution-5b0e9e7791cc960408fb772e9a1ec05037b5719a.tar.zst gsoc2013-evolution-5b0e9e7791cc960408fb772e9a1ec05037b5719a.zip |
Bug #250046 - Empty group address as recipient prevents message send
Empty group addresses were left as-is when sending an email directly,
not through Outbox, which could cause a send error through SMTP.
Expanding group addresses, or removing empty groups, from a list
or recipients before sending the message fixes the issue.
Diffstat (limited to 'libemail-engine')
-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 0938caeb33..1c9dcbb544 100644 --- a/libemail-engine/e-mail-session-utils.c +++ b/libemail-engine/e-mail-session-utils.c @@ -877,6 +877,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 83f90fe4f8..b65fbc32dd 100644 --- a/libemail-engine/e-mail-utils.c +++ b/libemail-engine/e-mail-utils.c @@ -705,3 +705,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 ff310efc52..2eb0dae853 100644 --- a/libemail-engine/mail-ops.c +++ b/libemail-engine/mail-ops.c @@ -645,6 +645,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)) |