Commit 5b0e9e77 authored by Milan Crha's avatar Milan Crha
Browse files

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.
parent 853c7125
......@@ -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);
......
......@@ -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);
}
}
}
}
......@@ -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 */
......@@ -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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment