aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--composer/e-composer-header-table.c99
-rw-r--r--composer/e-msg-composer.c93
2 files changed, 99 insertions, 93 deletions
diff --git a/composer/e-composer-header-table.c b/composer/e-composer-header-table.c
index 461c11efa1..44a4919e0d 100644
--- a/composer/e-composer-header-table.c
+++ b/composer/e-composer-header-table.c
@@ -19,6 +19,7 @@
#include <string.h>
#include <glib/gi18n-lib.h>
+#include <camel/camel-internet-address.h>
#include <libedataserverui/e-name-selector.h>
#include "e-signature-combo-box.h"
@@ -221,13 +222,90 @@ composer_header_table_bind_widget (const gchar *property_name,
(gpointer) property_name);
}
+static EDestination **
+composer_header_table_update_destinations (EDestination **old_destinations,
+ const gchar *auto_addresses)
+{
+ CamelAddress *address;
+ CamelInternetAddress *inet_address;
+ EDestination **new_destinations;
+ EDestination *destination;
+ GList *list = NULL;
+ guint length;
+ gint ii;
+
+ /* Include automatic recipients for the selected account. */
+
+ if (auto_addresses == NULL)
+ goto skip_auto;
+
+ inet_address = camel_internet_address_new ();
+ address = CAMEL_ADDRESS (inet_address);
+
+ if (camel_address_decode (address, auto_addresses) != -1) {
+ for (ii = 0; ii < camel_address_length (address); ii++) {
+ const gchar *name, *email;
+
+ if (!camel_internet_address_get (
+ inet_address, ii, &name, &email))
+ continue;
+
+ destination = e_destination_new ();
+ e_destination_set_auto_recipient (destination, TRUE);
+
+ if (name != NULL)
+ e_destination_set_name (destination, name);
+
+ if (email != NULL)
+ e_destination_set_email (destination, email);
+
+ list = g_list_prepend (list, destination);
+ }
+ }
+
+ camel_object_unref (inet_address);
+
+skip_auto:
+
+ /* Include custom recipients for this message. */
+
+ if (old_destinations == NULL)
+ goto skip_custom;
+
+ for (ii = 0; old_destinations[ii] != NULL; ii++) {
+ if (e_destination_is_auto_recipient (old_destinations[ii]))
+ continue;
+
+ destination = e_destination_copy (old_destinations[ii]);
+ list = g_list_prepend (list, destination);
+ }
+
+skip_custom:
+
+ list = g_list_reverse (list);
+ length = g_list_length (list);
+
+ new_destinations = g_new0 (EDestination *, length + 1);
+
+ for (ii = 0; list != NULL; ii++) {
+ new_destinations[ii] = E_DESTINATION (list->data);
+ list = g_list_delete_link (list, list);
+ }
+
+ return new_destinations;
+}
+
static void
composer_header_table_from_changed_cb (EComposerHeaderTable *table)
{
EAccount *account;
EComposerPostHeader *post_header;
EComposerTextHeader *text_header;
+ EDestination **old_destinations;
+ EDestination **new_destinations;
const gchar *reply_to;
+ gboolean always_cc;
+ gboolean always_bcc;
/* Keep "Post-To" and "Reply-To" synchronized with "From" */
@@ -239,6 +317,27 @@ composer_header_table_from_changed_cb (EComposerHeaderTable *table)
reply_to = (account != NULL) ? account->id->reply_to : NULL;
text_header = E_COMPOSER_HEADER_TABLE_GET_REPLY_TO_HEADER (table);
e_composer_text_header_set_text (text_header, reply_to);
+
+ always_cc = (account != NULL && account->always_cc);
+ always_bcc = (account != NULL && account->always_bcc);
+
+ /* Update automatic CC destinations. */
+ old_destinations =
+ e_composer_header_table_get_destinations_cc (table);
+ new_destinations =
+ composer_header_table_update_destinations (
+ old_destinations, always_cc ? account->cc_addrs : NULL);
+ e_composer_header_table_set_destinations_cc (table, new_destinations);
+ e_destination_freev (new_destinations);
+
+ /* Update automatic BCC destinations. */
+ old_destinations =
+ e_composer_header_table_get_destinations_bcc (table);
+ new_destinations =
+ composer_header_table_update_destinations (
+ old_destinations, always_bcc ? account->bcc_addrs : NULL);
+ e_composer_header_table_set_destinations_bcc (table, new_destinations);
+ e_destination_freev (new_destinations);
}
static GObject *
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 5384b4ab0a..933b40c5aa 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1344,90 +1344,6 @@ msg_composer_subject_changed_cb (EMsgComposer *composer)
gtk_window_set_title (GTK_WINDOW (composer), subject);
}
-enum {
- UPDATE_AUTO_CC,
- UPDATE_AUTO_BCC
-};
-
-static void
-update_auto_recipients (EComposerHeaderTable *table,
- gint mode,
- const gchar *auto_addrs)
-{
- EDestination *dest, **destv = NULL;
- CamelInternetAddress *iaddr;
- GList *list = NULL;
- guint length;
- gint i;
-
- if (auto_addrs) {
- iaddr = camel_internet_address_new ();
- if (camel_address_decode (CAMEL_ADDRESS (iaddr), auto_addrs) != -1) {
- for (i = 0; i < camel_address_length (CAMEL_ADDRESS (iaddr)); i++) {
- const gchar *name, *addr;
-
- if (!camel_internet_address_get (iaddr, i, &name, &addr))
- continue;
-
- dest = e_destination_new ();
- e_destination_set_auto_recipient (dest, TRUE);
-
- if (name)
- e_destination_set_name (dest, name);
-
- if (addr)
- e_destination_set_email (dest, addr);
-
- list = g_list_prepend (list, dest);
- }
- }
-
- camel_object_unref (iaddr);
- }
-
- switch (mode) {
- case UPDATE_AUTO_CC:
- destv = e_composer_header_table_get_destinations_cc (table);
- break;
- case UPDATE_AUTO_BCC:
- destv = e_composer_header_table_get_destinations_bcc (table);
- break;
- default:
- g_return_if_reached ();
- }
-
- if (destv) {
- for (i = 0; destv[i]; i++) {
- if (!e_destination_is_auto_recipient (destv[i])) {
- dest = e_destination_copy (destv[i]);
- list = g_list_prepend (list, dest);
- }
- }
-
- e_destination_freev (destv);
- }
-
- list = g_list_reverse (list);
-
- length = g_list_length (list);
- destv = destination_list_to_vector_sized (list, length);
-
- g_list_free (list);
-
- switch (mode) {
- case UPDATE_AUTO_CC:
- e_composer_header_table_set_destinations_cc (table, destv);
- break;
- case UPDATE_AUTO_BCC:
- e_composer_header_table_set_destinations_bcc (table, destv);
- break;
- default:
- g_return_if_reached ();
- }
-
- e_destination_freev (destv);
-}
-
static void
msg_composer_account_changed_cb (EMsgComposer *composer)
{
@@ -1438,8 +1354,6 @@ msg_composer_account_changed_cb (EMsgComposer *composer)
EAccount *account;
gboolean active;
gboolean sensitive;
- const gchar *cc_addrs = NULL;
- const gchar *bcc_addrs = NULL;
const gchar *uid;
table = e_msg_composer_get_header_table (composer);
@@ -1462,11 +1376,6 @@ msg_composer_account_changed_cb (EMsgComposer *composer)
active = account->smime_encrypt_default;
gtk_toggle_action_set_active (action, active);
- if (account->always_cc)
- cc_addrs = account->cc_addrs;
- if (account->always_bcc)
- bcc_addrs = account->bcc_addrs;
-
uid = account->id->sig_uid;
signature = uid ? e_get_signature_by_uid (uid) : NULL;
e_composer_header_table_set_signature (table, signature);
@@ -1479,8 +1388,6 @@ msg_composer_account_changed_cb (EMsgComposer *composer)
gtk_action_set_sensitive (ACTION (SEND_OPTIONS), sensitive);
exit:
- update_auto_recipients (table, UPDATE_AUTO_CC, cc_addrs);
- update_auto_recipients (table, UPDATE_AUTO_BCC, bcc_addrs);
e_msg_composer_show_sig_file (composer);
}