From fc1df29aa18130cee9e36cbc32f076cc2802f110 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 3 May 2020 09:00:52 +0200 Subject: [PATCH] Aggiunta funzione SolipaMail::send_mail_Ext. --- src/mail.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/mail.h | 13 +++++- 2 files changed, 126 insertions(+), 2 deletions(-) diff --git a/src/mail.c b/src/mail.c index 61b97ef..4471e5d 100644 --- a/src/mail.c +++ b/src/mail.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Andrea Zagli + * Copyright (C) 2010-2020 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -899,6 +899,119 @@ noconnect: #endif } +/** + * solipa_mail_send_ext: + * @smail: + * @from: + * @to: + * @cc: + * @bcc: + * @subject: + * @body: + * @attachments: + * + * An utility function to send an email. + */ +void +solipa_mail_send_ext (Solipa *solipa, + SolipaMail *smail, + const gchar *from, + const gchar *to, + const gchar *cc, + const gchar *bcc, + const gchar *subject, + const gchar *body, + GSList *attachments, + const gchar *smtp_uri) +{ + SolipaMail *_smail; + CamelInternetAddress *addr; + GSList *addrs; + guint i_attachments; + + g_return_if_fail (solipa == NULL); + + if (smail == NULL) + { + _smail = solipa_mail_new (solipa); + } + else + { + _smail = smail; + } + + solipa_mail_set_subject (_smail, subject); + + addr = camel_internet_address_new (); + + addrs = solipa_mail_get_addresses_from_string (from); + camel_internet_address_add (addr, + g_hash_table_lookup ((GHashTable *)addrs->data, "name"), + g_hash_table_lookup ((GHashTable *)addrs->data, "address")); + solipa_mail_set_from (_smail, addr); + + camel_address_remove (CAMEL_ADDRESS (addr), -1); + + addrs = solipa_mail_get_addresses_from_string (to); + while (addrs) + { + addr = camel_internet_address_new (); + camel_internet_address_add (addr, + g_hash_table_lookup ((GHashTable *)addrs->data, "name"), + g_hash_table_lookup ((GHashTable *)addrs->data, "address")); + solipa_mail_add_recipient (_smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_TO); + g_object_unref (addr); + + addrs = g_slist_next (addrs); + } + + if (cc != NULL) + { + addrs = solipa_mail_get_addresses_from_string (cc); + while (addrs) + { + addr = camel_internet_address_new (); + camel_internet_address_add (addr, + g_hash_table_lookup ((GHashTable *)addrs->data, "name"), + g_hash_table_lookup ((GHashTable *)addrs->data, "address")); + solipa_mail_add_recipient (_smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_CC); + g_object_unref (addr); + + addrs = g_slist_next (addrs); + } + } + + if (bcc != NULL) + { + addrs = solipa_mail_get_addresses_from_string (bcc); + while (addrs) + { + addr = camel_internet_address_new (); + camel_internet_address_add (addr, + g_hash_table_lookup ((GHashTable *)addrs->data, "name"), + g_hash_table_lookup ((GHashTable *)addrs->data, "address")); + solipa_mail_add_recipient (_smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_BCC); + g_object_unref (addr); + + addrs = g_slist_next (addrs); + } + } + + solipa_mail_set_body (_smail, + body, + NULL); + + if (attachments != NULL) + { + for (i_attachments = 0; i_attachments < g_slist_length (attachments); i_attachments++) + { + solipa_mail_add_attachment (_smail, (gchar *)g_slist_nth_data (attachments, i_attachments)); + } + } + + solipa_mail_send (_smail, smtp_uri); +} + /** * solipa_mail_check_email_address: * @address: diff --git a/src/mail.h b/src/mail.h index 8a195da..554342d 100644 --- a/src/mail.h +++ b/src/mail.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Andrea Zagli + * Copyright (C) 2010-2020 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -84,6 +84,17 @@ void solipa_mail_set_proxy (SolipaMail *mail, GProxyResolver *resolver, const gc void solipa_mail_send (SolipaMail *mail, const gchar *url); +void solipa_mail_send_ext (Solipa *solipa, + SolipaMail *smail, + const gchar *from, + const gchar *to, + const gchar *cc, + const gchar *bcc, + const gchar *subject, + const gchar *body, + GSList *attachments, + const gchar *smtp_uri); + gboolean solipa_mail_check_email_address (const gchar *address); GSList *solipa_mail_get_addresses_from_string (const gchar *addresses); -- 2.49.0