Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.2003
diff -u -r1.2003 ChangeLog
--- mail/ChangeLog	2002/01/25 21:38:31	1.2003
+++ mail/ChangeLog	2002/01/26 14:58:58
@@ -1,1 +1,86 @@
+2002-01-25  Ian Goldberg  <ian@cypherpunks.ca>
+
+	* mail-config.glade: Add GUI widgets to allow the user
+	  to set alternate email addresses for an account.  These
+	  addresses will be used to figure out which account should
+	  be selected for a given message.  Also allow the user to
+	  select a set of addresses (presumably his own) which will be
+	  removed from the Cc: list in a reply-to-all situation.
+	  These are different settings, so that the "alternate
+	  addresses" could be, for example, all addresses at your work
+	  domain (corresponding to your account with your work address).
+	  That way, replying to any email destined to any recipient with
+	  a work address (mailing lists?) will correctly choose your
+	  work account.  But setting your "remove recipients" addresses
+	  to just your own will then prevent all your coworkers from
+	  being removed from your Cc: lists.  Note that you can always
+	  add addresses back to the list manually.
+
+	* mail-account-gui.c
+	  (mail_account_gui_new): New GUI widgets, as above.
+
+	  (mail_account_gui_identity_complete): If the alternate address
+	  regexp doesn't compile, don't let the user continue.
+
+	  (remove_recips_kind_value): Find out what set of addresses
+	  the user doesn't want added to Cc: lists in replies.
+
+	  (remove_recips_show, remove_recips_kind_changed): Show or hide
+	  the text entry widget as appropriate for the current setting
+	  of the remove_recips_kind option menu.
+
+	  (mail_account_gui_save): Check that any supplied regexps
+	  for the alternate addresses, or the recipients to be removed
+	  from the Cc: lists, are valid.  Save the new fields in the
+	  appropriate parts of the account structure.
+
+	* mail-account-gui.h (MailAccountGui): New GUI widgets, as above.
+
+	* mail-callbacks.c (list_add_addresses): Pass "me" (the account
+	  associated with this message) into this routine, rather than
+	  trying to set it here.  If we were asked to remove addresses
+	  from the Cc: list, then skip them instead of adding them to
+	  the Cc: list.
+
+	  (guess_me): When trying to figure out which account is
+	  associated to a given message, use the alternate addresses
+	  if you can't find an account matching on the main address.
+
+	  (mail_generate_reply): Use guess_me to figure out which
+	  account to use, rather than list_add_addresses.
+	
+	* mail-config-druid.c (get_fn): Make sure you can't hit "Next>"
+	  when you've entered an invalid regexp for your alternate
+	  addresses.
+	
+	* mail-config.c (identity_copy): Copy the alternate addresses.
+
+	  (identity_destroy): Free the alternate addresses.
+
+	  (mail_config_make_regexp_from_list): A new function which
+	  takes either a textual list (, or whitespace separated) or
+	  a regular expression, and returns a regular expression which
+	  will match the appropriate thing.
+
+	  (account_copy): Copy the removed recipients.
+
+	  (account_destroy): Free the removed recipients.
+
+	  (config_read): Read the alternate addresses and the removed
+	  recipients from the config db.
+
+	  (mail_config_write): Save the alternate addresses and the
+	  removed recipients to the config db.
+
+	  (impl_GNOME_Evolution_MailConfig_addAccount): Fill the
+	  created MailConfigIdentity with an empty list of alternate
+	  addresses.
+	
+	* mail-config.h: Add the mail_config_make_regexp_from_list
+	  public function.
+	
+	  (MailConfigIdentity): Add fields for the alternate addresses.
+
+	  (MailConfigAccount): Add fields for the removed recipients.
+
 
Index: mail/mail-account-gui.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-account-gui.c,v
retrieving revision 1.63
diff -u -r1.63 mail-account-gui.c
--- mail/mail-account-gui.c	2002/01/25 21:38:32	1.63
+++ mail/mail-account-gui.c	2002/01/26 14:59:00
@@ -96,6 +96,8 @@
 		if (incomplete)
 			*incomplete = get_focused_widget (GTK_WIDGET (gui->full_name),
 							  GTK_WIDGET (gui->email_address),
+							  GTK_WIDGET (gui->alt_addrs),
+							  GTK_WIDGET (gui->alt_addrs_is_re),
 							  NULL);
 		return FALSE;
 	}
@@ -105,9 +107,38 @@
 		if (incomplete)
 			*incomplete = get_focused_widget (GTK_WIDGET (gui->email_address),
 							  GTK_WIDGET (gui->full_name),
+							  GTK_WIDGET (gui->alt_addrs),
+							  GTK_WIDGET (gui->alt_addrs_is_re),
 							  NULL);
 		return FALSE;
 	}
+
+	text = gtk_entry_get_text (gui->alt_addrs);
+	if (text) {
+		int is_re = gtk_toggle_button_get_active (gui->alt_addrs_is_re);
+		if (is_re) {
+			/* Make sure this regexp compiles */
+			gchar *new_re;
+			regex_t new_re_comp;
+			int regerr;
+			new_re = mail_config_make_regexp_from_list (text, is_re);
+			regerr = regcomp (&new_re_comp, new_re,
+					REG_EXTENDED|REG_ICASE|REG_NOSUB);
+			g_free (new_re);
+			regfree (&new_re_comp);
+			if (regerr) {
+				if (incomplete) {
+					*incomplete = get_focused_widget
+						(GTK_WIDGET (gui->alt_addrs),
+						GTK_WIDGET (gui->alt_addrs_is_re),
+						GTK_WIDGET (gui->full_name),
+						GTK_WIDGET (gui->email_address),
+						NULL);
+				}
+				return FALSE;
+			}
+		}
+	}
 	
 	return TRUE;
 }
@@ -1219,10 +1250,42 @@
 				  *gtk_entry_get_text (GTK_ENTRY (gnome_file_entry_gtk_entry (gui->html_signature))) != 0);
 }
 
+static int
+remove_recips_kind_value (MailAccountGui *gui)
+{
+	GtkMenu *menu =
+		GTK_MENU (gtk_option_menu_get_menu (gui->remove_recips_kind));
+	GtkObject *item = GTK_OBJECT (gtk_menu_get_active (menu));
+	return (int) gtk_object_get_data (item, "choice");
+}
+
+static void
+remove_recips_show (GtkEntry *entry, MailAccountGui *gui)
+{
+	int new_value = remove_recips_kind_value(gui);
+	if (new_value < 2) {
+		gtk_widget_hide (GTK_WIDGET (gui->remove_recips));
+	}
+}
+
+static void
+remove_recips_kind_changed (GtkMenu *menu, MailAccountGui *gui)
+{
+	int new_value = remove_recips_kind_value(gui);
+	if (new_value >= 2) {
+		gtk_widget_show (GTK_WIDGET (gui->remove_recips));
+	} else {
+		gtk_widget_hide (GTK_WIDGET (gui->remove_recips));
+	}
+}
+
 MailAccountGui *
 mail_account_gui_new (MailConfigAccount *account)
 {
 	MailAccountGui *gui;
+	GtkMenu *menu;
+	GList *l;
+	int i;
 	
 	gui = g_new0 (MailAccountGui, 1);
 	gui->account = account;
@@ -1256,6 +1319,9 @@
 			    html_signature_changed, gui);
 	gtk_signal_connect (GTK_OBJECT (gui->edit_signature), "clicked", edit_signature, gui);
 	gtk_signal_connect (GTK_OBJECT (gui->edit_html_signature), "clicked", edit_html_signature, gui);
+
+	gui->alt_addrs = GTK_ENTRY (glade_xml_get_widget (gui->xml, "alternate_addrs"));
+	gui->alt_addrs_is_re = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui->xml, "aa_is_regexp"));
 	
 	if (account->id) {
 		if (account->id->name)
@@ -1275,6 +1341,10 @@
 					    account->id->html_signature);
 		}
 		gtk_toggle_button_set_active (gui->has_html_signature, account->id->has_html_signature);
+		if (account->id->alt_addrs) {
+			gtk_entry_set_text (gui->alt_addrs, account->id->alt_addrs);
+		}
+		gtk_toggle_button_set_active (gui->alt_addrs_is_re, account->id->alt_addrs_is_re);
 	}
 	
 	/* Source */
@@ -1357,6 +1427,25 @@
 	gtk_toggle_button_set_active (gui->always_bcc, account->always_bcc);
 	gui->bcc_addrs = GTK_ENTRY (glade_xml_get_widget (gui->xml, "bcc_addrs"));
 	e_utf8_gtk_entry_set_text (gui->bcc_addrs, account->bcc_addrs);
+
+	/* Remove recips */
+	gui->remove_recips_kind = GTK_OPTION_MENU (glade_xml_get_widget (gui->xml, "remove_recips_kind"));
+	menu = GTK_MENU (gtk_option_menu_get_menu (gui->remove_recips_kind));
+	l = GTK_MENU_SHELL (menu)->children;
+	i = 0;
+	while (l) {
+		gtk_object_set_data (GTK_OBJECT (l->data), "choice", (gpointer)i);
+		l = l->next;
+		i++;
+	}
+	gui->remove_recips = GTK_ENTRY (glade_xml_get_widget (gui->xml, "remove_recips"));
+	e_utf8_gtk_entry_set_text (gui->remove_recips, account->remove_recips);
+	gtk_signal_connect (GTK_OBJECT (gui->remove_recips), "show",
+			    GTK_SIGNAL_FUNC (remove_recips_show), gui);
+	gtk_signal_connect (GTK_OBJECT (menu), "selection-done",
+			    GTK_SIGNAL_FUNC (remove_recips_kind_changed), gui);
+	gtk_option_menu_set_history (gui->remove_recips_kind, account->remove_recips_kind);
+	remove_recips_kind_changed (menu, gui);
 	
 	/* Security */
 	gui->pgp_key = GTK_ENTRY (glade_xml_get_widget (gui->xml, "pgp_key"));
@@ -1646,6 +1735,9 @@
 	CamelURL *source_url = NULL, *url;
 	char *new_name;
 	gboolean old_enabled;
+	char *new_addrs, *new_addrs_re, *new_rrecip, *new_rrecip_re;
+	int regerr, new_addrs_is_re, new_rrecip_is_re;
+	regex_t new_addrs_re_comp, new_rrecip_re_comp;
 	
 	if (!mail_account_gui_identity_complete (gui, NULL) ||
 	    !mail_account_gui_source_complete (gui, NULL) ||
@@ -1669,6 +1761,54 @@
 	g_free (account->name);
 	account->name = new_name;
 	
+	/* Check that the supplied regexps were valid */
+	new_addrs = e_utf8_gtk_entry_get_text (gui->alt_addrs);
+	new_addrs_is_re = gtk_toggle_button_get_active (gui->alt_addrs_is_re);
+	new_addrs_re = mail_config_make_regexp_from_list (new_addrs,
+		new_addrs_is_re);
+	regerr = regcomp (&new_addrs_re_comp, new_addrs_re,
+		REG_EXTENDED|REG_ICASE|REG_NOSUB);
+	if (regerr) {
+		/* It was not. */
+		char re_err_buf[256];
+		char *re_err_str;
+		regerror(regerr, &new_addrs_re_comp, re_err_buf,
+			sizeof(re_err_buf));
+		re_err_str = g_strdup_printf(_("Bad regexp supplied: %s"),
+			re_err_buf);
+		e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, re_err_str);
+		g_free (re_err_str);
+		g_free (new_addrs);
+		g_free (new_addrs_re);
+		regfree (&new_addrs_re_comp);
+		return FALSE;
+	}
+
+	new_rrecip = e_utf8_gtk_entry_get_text (gui->remove_recips);
+	new_rrecip_is_re = (remove_recips_kind_value(gui) == 3);
+	new_rrecip_re = mail_config_make_regexp_from_list (new_rrecip,
+		new_rrecip_is_re);
+	regerr = regcomp (&new_rrecip_re_comp, new_rrecip_re,
+		REG_EXTENDED|REG_ICASE|REG_NOSUB);
+	if (regerr) {
+		/* It was not. */
+		char re_err_buf[256];
+		char *re_err_str;
+		regerror(regerr, &new_rrecip_re_comp, re_err_buf,
+			sizeof(re_err_buf));
+		re_err_str = g_strdup_printf(_("Bad regexp supplied: %s"),
+			re_err_buf);
+		e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, re_err_str);
+		g_free (re_err_str);
+		g_free (new_addrs);
+		g_free (new_addrs_re);
+		regfree (&new_addrs_re_comp);
+		g_free (new_rrecip);
+		g_free (new_rrecip_re);
+		regfree (&new_rrecip_re_comp);
+		return FALSE;
+	}
+
 	/* construct the identity */
 	identity_destroy (account->id);
 	account->id = g_new0 (MailConfigIdentity, 1);
@@ -1678,6 +1818,11 @@
 	account->id->signature = gnome_file_entry_get_full_path (gui->signature, TRUE);
 	account->id->html_signature = gnome_file_entry_get_full_path (gui->html_signature, TRUE);
 	account->id->has_html_signature = gtk_toggle_button_get_active (gui->has_html_signature);
+	account->id->alt_addrs = new_addrs;
+	account->id->alt_addrs_is_re = new_addrs_is_re;
+	account->id->alt_addrs_re = new_addrs_re;
+	memmove (&(account->id->alt_addrs_re_comp), &new_addrs_re_comp,
+		sizeof(new_addrs_re_comp));
 	
 	old_enabled = account->source && account->source->enabled;
 	service_destroy (account->source);
@@ -1743,6 +1888,11 @@
 	account->cc_addrs = e_utf8_gtk_entry_get_text (gui->cc_addrs);
 	account->always_bcc = gtk_toggle_button_get_active (gui->always_bcc);
 	account->bcc_addrs = e_utf8_gtk_entry_get_text (gui->bcc_addrs);
+	account->remove_recips_kind = remove_recips_kind_value (gui);
+	account->remove_recips = e_utf8_gtk_entry_get_text (gui->remove_recips);
+	account->remove_recips_re = new_rrecip_re;
+	memmove (&(account->remove_recips_re_comp), &new_rrecip_re_comp,
+		sizeof(new_rrecip_re_comp));
 	
 	g_free (account->pgp_key);
 	account->pgp_key = e_utf8_gtk_entry_get_text (gui->pgp_key);
Index: mail/mail-account-gui.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-account-gui.h,v
retrieving revision 1.12
diff -u -r1.12 mail-account-gui.h
--- mail/mail-account-gui.h	2001/12/20 00:35:39	1.12
+++ mail/mail-account-gui.h	2002/01/26 14:59:00
@@ -72,6 +72,8 @@
 	GtkToggleButton *has_html_signature;
 	GtkButton *edit_signature;
 	GtkButton *edit_html_signature;
+	GtkEntry *alt_addrs;
+	GtkToggleButton *alt_addrs_is_re;
 	
 	/* incoming mail */
 	MailAccountGuiService source;
@@ -100,6 +102,10 @@
 	GtkEntry *cc_addrs;
 	GtkToggleButton *always_bcc;
 	GtkEntry *bcc_addrs;
+
+	/* Remove recipients */
+	GtkOptionMenu *remove_recips_kind;
+	GtkEntry *remove_recips;
 	
 	/* Security */
 	GtkEntry *pgp_key;
Index: mail/mail-callbacks.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-callbacks.c,v
retrieving revision 1.298
diff -u -r1.298 mail-callbacks.c
--- mail/mail-callbacks.c	2002/01/24 20:09:04	1.298
+++ mail/mail-callbacks.c	2002/01/26 14:59:02
@@ -798,7 +798,7 @@
 
 static GList *
 list_add_addresses (GList *list, const CamelInternetAddress *cia, const GSList *accounts,
-		    GHashTable *rcpt_hash, const MailConfigAccount **me)
+		    GHashTable *rcpt_hash, const MailConfigAccount *me)
 {
 	const MailConfigAccount *account;
 	GHashTable *account_hash;
@@ -815,12 +815,40 @@
 	}
 	
 	for (i = 0; camel_internet_address_get (cia, i, &name, &addr); i++) {
+		/* If we've asked to not Cc: some addresses, then check
+		 * if this is one of them. */
+		int remove_this_address = 0;
+
+		if (me && addr && *addr) {
+			switch (me->remove_recips_kind) {
+				case 1: /* This account's address */
+					/* Check both primary and
+					 * alternate addresses */
+					if (!g_strcasecmp (me->id->address, addr) ||
+							!regexec (&(me->id->alt_addrs_re_comp), addr, 0, NULL, 0)) {
+						remove_this_address = 1;
+					}
+					break;
+				case 2: /* A specified list of addresses */
+					/* We've already turned the list
+					 * into a regexp, so we'll just
+					 * fall through. */
+				case 3: /* A specified regexp */
+					if (!regexec (&(me->remove_recips_re_comp), addr, 0, NULL, 0)) {
+						remove_this_address = 1;
+					}
+					break;
+			}
+		}
+
+		if (remove_this_address) {
+			continue;
+		}
+
 		/* Here I'll check to see if the cc:'d address is the address
 		   of the sender, and if so, don't add it to the cc: list; this
 		   is to fix Bugzilla bug #455. */
 		account = g_hash_table_lookup (account_hash, addr);
-		if (account && me && !*me)
-			*me = account;
 		
 		if (!account && !g_hash_table_lookup (rcpt_hash, addr)) {
 			EDestination *dest;
@@ -877,6 +905,40 @@
 	}
 	
 	account = NULL;
+
+	/* If there was no exact match, look for matches to the
+	 * alternate addresses. */
+	if (to) {
+		for (i = 0; camel_internet_address_get (to, i, NULL, &addr); i++) {
+			l = accounts;
+			while (l) {
+				const MailConfigAccount *acc = l->data;
+				if (addr && *addr && regexec(
+						&(acc->id->alt_addrs_re_comp),
+						addr, 0, NULL, 0) == 0) {
+					account = acc;
+					goto found;
+				}
+				l = l->next;
+			}
+		}
+	}
+	
+	if (cc) {
+		for (i = 0; camel_internet_address_get (cc, i, NULL, &addr); i++) {
+			l = accounts;
+			while (l) {
+				const MailConfigAccount *acc = l->data;
+				if (addr && *addr && regexec(
+						&(acc->id->alt_addrs_re_comp),
+						addr, 0, NULL, 0) == 0) {
+					account = acc;
+					goto found;
+				}
+				l = l->next;
+			}
+		}
+	}
 	
  found:
 	
@@ -998,8 +1060,9 @@
 		}
 		
 		if (mode == REPLY_ALL) {
-			cc = list_add_addresses (cc, to_addrs, accounts, rcpt_hash, &me);
-			cc = list_add_addresses (cc, cc_addrs, accounts, rcpt_hash, me ? NULL : &me);
+			me = guess_me (to_addrs, cc_addrs, accounts);
+			cc = list_add_addresses (cc, to_addrs, accounts, rcpt_hash, me);
+			cc = list_add_addresses (cc, cc_addrs, accounts, rcpt_hash, me);
 		} else {
 			me = guess_me (to_addrs, cc_addrs, accounts);
 		}
Index: mail/mail-config-druid.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config-druid.c,v
retrieving revision 1.68
diff -u -r1.68 mail-config-druid.c
--- mail/mail-config-druid.c	2001/11/05 23:10:12	1.68
+++ mail/mail-config-druid.c	2002/01/26 14:59:02
@@ -705,6 +705,10 @@
                                     "changed", identity_changed, gui);
                 gtk_signal_connect (GTK_OBJECT (gui->gui->email_address),
                                     "changed", identity_changed, gui);
+		gtk_signal_connect (GTK_OBJECT (gui->gui->alt_addrs),
+				    "changed", identity_changed, gui);
+		gtk_signal_connect (GTK_OBJECT (gui->gui->alt_addrs_is_re),
+				    "clicked", identity_changed, gui);
 		gtk_signal_connect (GTK_OBJECT (gui->gui->source.hostname), 
 				    "changed", source_changed, gui);
 		gtk_signal_connect (GTK_OBJECT (gui->gui->source.username),
Index: mail/mail-config.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.c,v
retrieving revision 1.195
diff -u -r1.195 mail-config.c
--- mail/mail-config.c	2002/01/25 19:32:27	1.195
+++ mail/mail-config.c	2002/01/26 14:59:03
@@ -137,6 +137,17 @@
 	new->signature = g_strdup (id->signature);
 	new->html_signature = g_strdup (id->html_signature);
 	new->has_html_signature = id->has_html_signature;
+	new->alt_addrs = g_strdup(id->alt_addrs);
+	new->alt_addrs_is_re = id->alt_addrs_is_re;
+	new->alt_addrs_re = g_strdup(id->alt_addrs_re);
+	if (regcomp (&(new->alt_addrs_re_comp), new->alt_addrs_re,
+		REG_EXTENDED|REG_ICASE|REG_NOSUB)) {
+		/* This shouldn't happen, since we're copying a re
+		 * that should be good, but we'll handle it anyway. */
+		regfree (&(new->alt_addrs_re_comp));
+		regcomp (&(new->alt_addrs_re_comp), "^$",
+			REG_EXTENDED|REG_ICASE|REG_NOSUB);
+	}
 	
 	return new;
 }
@@ -152,10 +163,58 @@
 	g_free (id->organization);
 	g_free (id->signature);
 	g_free (id->html_signature);
+	g_free (id->alt_addrs);
+	g_free (id->alt_addrs_re);
+	regfree (&(id->alt_addrs_re_comp));
 	
 	g_free (id);
 }
 
+/* Turn a list of addresses (or a regexp) into a regexp */
+gchar *
+mail_config_make_regexp_from_list (char *src, gboolean src_is_regexp)
+{
+	gchar *new_re;
+	if (src == NULL) src = "";
+
+	if (src_is_regexp) {
+		new_re = g_strdup (src);
+	} else {
+		int just_did_pipe = 0;
+		gchar *s, *d;
+		/* The regexp should look like:
+		 *   ^(\i\t\e\m\1|\i\t\e\m\2|\i\t\e\m\3)$
+		 * for an input string of:
+		 *   item1, item2, item3
+		 */
+		new_re = g_malloc (strlen(src) * 2 + 5);
+		strcpy(new_re, "^(");
+		d = new_re + 2;
+		s = src;
+		while (*s) {
+			gchar c = *s;
+			if (c == ' ' || c == '\t' || c == '\r' ||
+					c == '\n' || c == ',') {
+				/* Turn whitespace and , into |, but
+				 * only one at a time */
+				if (just_did_pipe == 0) {
+					*(d++) = '|';
+					just_did_pipe = 1;
+				}
+			} else {
+				/* \ escape everything else */
+				*(d++) = '\\';
+				*(d++) = *s;
+				just_did_pipe = 0;
+			}
+			++s;
+		}
+		/* Add the end of the re */
+		strcpy(d, ")$");
+	}
+	return new_re;
+}
+
 /* Service */
 MailConfigService *
 service_copy (const MailConfigService *source) 
@@ -216,6 +275,17 @@
 	new->cc_addrs = g_strdup (account->cc_addrs);
 	new->always_bcc = account->always_bcc;
 	new->bcc_addrs = g_strdup (account->bcc_addrs);
+	new->remove_recips_kind = account->remove_recips_kind;
+	new->remove_recips = g_strdup (account->remove_recips);
+	new->remove_recips_re = g_strdup(account->remove_recips_re);
+	if (regcomp (&(new->remove_recips_re_comp), new->remove_recips_re,
+		REG_EXTENDED|REG_ICASE|REG_NOSUB)) {
+		/* This shouldn't happen, since we're copying a re
+		 * that should be good, but we'll handle it anyway. */
+		regfree (&(new->remove_recips_re_comp));
+		regcomp (&(new->remove_recips_re_comp), "^$",
+			REG_EXTENDED|REG_ICASE|REG_NOSUB);
+	}
 	
 	new->pgp_key = g_strdup (account->pgp_key);
 	new->pgp_encrypt_to_self = account->pgp_encrypt_to_self;
@@ -247,6 +317,9 @@
 	
 	g_free (account->cc_addrs);
 	g_free (account->bcc_addrs);
+	g_free (account->remove_recips);
+	g_free (account->remove_recips_re);
+	regfree (&(account->remove_recips_re_comp));
 	
 	g_free (account->pgp_key);
 	g_free (account->smime_key);
@@ -413,6 +486,44 @@
 		else
 			g_free (val);
 		
+		path = g_strdup_printf ("/Mail/Accounts/account_remove_recips_kind_%d", i);
+		account->remove_recips_kind = bonobo_config_get_long_with_default (
+		        config->db, path, 0, NULL);
+		g_free (path);
+		
+		path = g_strdup_printf ("/Mail/Accounts/account_remove_recips_%d", i);
+		val = bonobo_config_get_string (config->db, path, NULL);
+		g_free (path);
+		if (val && *val)
+			account->remove_recips = val;
+		else
+			g_free (val);
+
+		account->remove_recips_re =
+			mail_config_make_regexp_from_list
+				(account->remove_recips,
+				(account->remove_recips_kind == 3));
+		if (regcomp (&(account->remove_recips_re_comp),
+				account->remove_recips_re,
+				REG_EXTENDED|REG_ICASE|REG_NOSUB)) {
+			/* If the regexp doesn't compile, the user must
+			 * have messed with the config manually, since
+			 * we only store things which compile.  Just
+			 * remove the whole regexp. */
+			regfree (&(account->remove_recips_re_comp));
+			g_free (account->remove_recips);
+			account->remove_recips = g_strdup ("");
+			account->remove_recips_kind = 0;
+			g_free (account->remove_recips_re);
+			account->remove_recips_re =
+				mail_config_make_regexp_from_list
+					(account->remove_recips, 0);
+			regcomp (&(account->remove_recips_re_comp),
+				account->remove_recips_re,
+				REG_EXTENDED|REG_ICASE|REG_NOSUB);
+		}
+		
+		
 		/* get the pgp info */
 		path = g_strdup_printf ("/Mail/Accounts/account_pgp_key_%d", i);
 		val = bonobo_config_get_string (config->db, path, NULL);
@@ -475,6 +586,34 @@
 		id->has_html_signature = bonobo_config_get_boolean_with_default (
 			config->db, path, FALSE, NULL);
 		g_free (path);
+		path = g_strdup_printf ("/Mail/Accounts/identity_alt_addrs_%d", i);
+		id->alt_addrs = bonobo_config_get_string (
+			config->db, path, NULL);
+		g_free (path);
+		path = g_strdup_printf ("/Mail/Accounts/identity_alt_addrs_is_re_%d", i);
+		id->alt_addrs_is_re = bonobo_config_get_boolean_with_default (
+			config->db, path, FALSE, NULL);
+		g_free (path);
+		id->alt_addrs_re =
+			mail_config_make_regexp_from_list (id->alt_addrs,
+				id->alt_addrs_is_re);
+		if (regcomp (&(id->alt_addrs_re_comp), id->alt_addrs_re,
+			REG_EXTENDED|REG_ICASE|REG_NOSUB)) {
+			/* If the regexp doesn't compile, the user must
+			 * have messed with the config manually, since
+			 * we only store things which compile.  Just
+			 * remove the whole regexp. */
+			regfree (&(id->alt_addrs_re_comp));
+			g_free (id->alt_addrs);
+			id->alt_addrs = g_strdup ("");
+			id->alt_addrs_is_re = FALSE;
+			g_free (id->alt_addrs_re);
+			id->alt_addrs_re =
+				mail_config_make_regexp_from_list
+					(id->alt_addrs, id->alt_addrs_is_re);
+			regcomp (&(id->alt_addrs_re_comp), id->alt_addrs_re,
+				REG_EXTENDED|REG_ICASE|REG_NOSUB);
+		}
 		
 		/* get the source */
 		source = g_new0 (MailConfigService, 1);
@@ -752,6 +891,15 @@
 						  account->bcc_addrs, NULL);
 		g_free (path);
 		
+		path = g_strdup_printf ("/Mail/Accounts/account_remove_recips_kind_%d", i);
+		bonobo_config_set_long (config->db, path, account->remove_recips_kind, NULL);
+		g_free (path);
+		
+		path = g_strdup_printf ("/Mail/Accounts/account_remove_recips_%d", i);
+		bonobo_config_set_string_wrapper (config->db, path, 
+						  account->remove_recips, NULL);
+		g_free (path);
+		
 		/* account pgp options */
 		path = g_strdup_printf ("/Mail/Accounts/account_pgp_key_%d", i);
 		bonobo_config_set_string_wrapper (config->db, path, account->pgp_key, NULL);
@@ -803,6 +951,12 @@
 		path = g_strdup_printf ("/Mail/Accounts/identity_has_html_signature_%d", i);
 		bonobo_config_set_boolean (config->db, path, account->id->has_html_signature, NULL);
 		g_free (path);
+		path = g_strdup_printf ("/Mail/Accounts/identity_alt_addrs_%d", i);
+		bonobo_config_set_string_wrapper (config->db, path, account->id->alt_addrs, NULL);
+		g_free (path);
+		path = g_strdup_printf ("/Mail/Accounts/identity_alt_addrs_is_re_%d", i);
+		bonobo_config_set_boolean (config->db, path, account->id->alt_addrs_is_re, NULL);
+		g_free (path);
 		
 		/* source info */
 		path = g_strdup_printf ("/Mail/Accounts/source_url_%d", i);
@@ -2392,6 +2546,16 @@
 	mail_id->signature = g_strdup (id.signature);
 	mail_id->html_signature = g_strdup (id.html_signature);
 	mail_id->has_html_signature = id.has_html_signature;
+
+	/* Use no alternate addresses so that we don't change the IDL
+	 * API */
+	mail_id->alt_addrs = g_strdup ("");
+	mail_id->alt_addrs_is_re = FALSE;
+	mail_id->alt_addrs_re =
+		mail_config_make_regexp_from_list (mail_id->alt_addrs,
+			mail_id->alt_addrs_is_re);
+	regcomp (&(mail_id->alt_addrs_re_comp), mail_id->alt_addrs_re,
+		REG_EXTENDED|REG_ICASE|REG_NOSUB);
 	
 	mail_account->id = mail_id;
 	
Index: mail/mail-config.glade
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.glade,v
retrieving revision 1.70
diff -u -r1.70 mail-config.glade
--- mail/mail-config.glade	2002/01/08 00:48:54	1.70
+++ mail/mail-config.glade	2002/01/26 14:59:04
@@ -460,7 +460,7 @@
 	  <class>GtkTable</class>
 	  <name>table2</name>
 	  <border_width>4</border_width>
-	  <rows>3</rows>
+	  <rows>4</rows>
 	  <columns>3</columns>
 	  <homogeneous>False</homogeneous>
 	  <row_spacing>4</row_spacing>
@@ -680,6 +680,80 @@
 	      <yfill>False</yfill>
 	    </child>
 	  </widget>
+
+	  <widget>
+	    <class>GtkLabel</class>
+	    <name>label58</name>
+	    <label>_Alternate Addrs:</label>
+	    <justify>GTK_JUSTIFY_RIGHT</justify>
+	    <wrap>False</wrap>
+	    <xalign>1</xalign>
+	    <yalign>0.5</yalign>
+	    <xpad>7</xpad>
+	    <ypad>0</ypad>
+	    <focus_target>alternate_addrs</focus_target>
+	    <child>
+	      <left_attach>0</left_attach>
+	      <right_attach>1</right_attach>
+	      <top_attach>3</top_attach>
+	      <bottom_attach>4</bottom_attach>
+	      <xpad>0</xpad>
+	      <ypad>0</ypad>
+	      <xexpand>False</xexpand>
+	      <yexpand>False</yexpand>
+	      <xshrink>False</xshrink>
+	      <yshrink>False</yshrink>
+	      <xfill>True</xfill>
+	      <yfill>False</yfill>
+	    </child>
+	  </widget>
+
+	  <widget>
+	    <class>GtkEntry</class>
+	    <name>alternate_addrs</name>
+	    <can_focus>True</can_focus>
+	    <editable>True</editable>
+	    <text_visible>True</text_visible>
+	    <text_max_length>0</text_max_length>
+	    <text></text>
+	    <child>
+	      <left_attach>1</left_attach>
+	      <right_attach>2</right_attach>
+	      <top_attach>3</top_attach>
+	      <bottom_attach>4</bottom_attach>
+	      <xpad>0</xpad>
+	      <ypad>0</ypad>
+	      <xexpand>True</xexpand>
+	      <yexpand>False</yexpand>
+	      <xshrink>False</xshrink>
+	      <yshrink>False</yshrink>
+	      <xfill>True</xfill>
+	      <yfill>False</yfill>
+	    </child>
+	  </widget>
+
+	  <widget>
+	    <class>GtkCheckButton</class>
+	    <name>aa_is_regexp</name>
+	    <can_focus>True</can_focus>
+	    <label>regexp</label>
+	    <active>False</active>
+	    <draw_indicator>True</draw_indicator>
+	    <child>
+	      <left_attach>2</left_attach>
+	      <right_attach>3</right_attach>
+	      <top_attach>3</top_attach>
+	      <bottom_attach>4</bottom_attach>
+	      <xpad>0</xpad>
+	      <ypad>0</ypad>
+	      <xexpand>False</xexpand>
+	      <yexpand>False</yexpand>
+	      <xshrink>False</xshrink>
+	      <yshrink>False</yshrink>
+	      <xfill>True</xfill>
+	      <yfill>False</yfill>
+	    </child>
+	  </widget>
 	</widget>
       </widget>
     </widget>
@@ -1880,7 +1954,7 @@
 	    <widget>
 	      <class>GtkTable</class>
 	      <name>table8</name>
-	      <rows>2</rows>
+	      <rows>4</rows>
 	      <columns>2</columns>
 	      <homogeneous>False</homogeneous>
 	      <row_spacing>0</row_spacing>
@@ -1984,6 +2058,82 @@
 		  <yfill>False</yfill>
 		</child>
 	      </widget>
+
+	      <widget>
+		<class>GtkOptionMenu</class>
+		<name>remove_recips_kind</name>
+		<can_focus>True</can_focus>
+		<items>No addresses
+This account's addresses
+A list of addresses:
+A regular expression:
+</items>
+		<initial_choice>0</initial_choice>
+		<child>
+		  <left_attach>0</left_attach>
+		  <right_attach>1</right_attach>
+		  <top_attach>3</top_attach>
+		  <bottom_attach>4</bottom_attach>
+		  <xpad>15</xpad>
+		  <ypad>0</ypad>
+		  <xexpand>False</xexpand>
+		  <yexpand>False</yexpand>
+		  <xshrink>False</xshrink>
+		  <yshrink>False</yshrink>
+		  <xfill>True</xfill>
+		  <yfill>False</yfill>
+		</child>
+	      </widget>
+
+	      <widget>
+		<class>GtkEntry</class>
+		<name>remove_recips</name>
+		<can_focus>True</can_focus>
+		<editable>True</editable>
+		<text_visible>True</text_visible>
+		<text_max_length>0</text_max_length>
+		<text></text>
+		<child>
+		  <left_attach>1</left_attach>
+		  <right_attach>2</right_attach>
+		  <top_attach>3</top_attach>
+		  <bottom_attach>4</bottom_attach>
+		  <xpad>0</xpad>
+		  <ypad>0</ypad>
+		  <xexpand>True</xexpand>
+		  <yexpand>False</yexpand>
+		  <xshrink>False</xshrink>
+		  <yshrink>False</yshrink>
+		  <xfill>True</xfill>
+		  <yfill>False</yfill>
+		</child>
+	      </widget>
+
+	      <widget>
+		<class>GtkLabel</class>
+		<name>label59</name>
+		<label>Remove from carbon-copy lists:</label>
+		<justify>GTK_JUSTIFY_LEFT</justify>
+		<wrap>False</wrap>
+		<xalign>0</xalign>
+		<yalign>0.5</yalign>
+		<xpad>17</xpad>
+		<ypad>0</ypad>
+		<child>
+		  <left_attach>0</left_attach>
+		  <right_attach>2</right_attach>
+		  <top_attach>2</top_attach>
+		  <bottom_attach>3</bottom_attach>
+		  <xpad>0</xpad>
+		  <ypad>0</ypad>
+		  <xexpand>False</xexpand>
+		  <yexpand>False</yexpand>
+		  <xshrink>False</xshrink>
+		  <yshrink>False</yshrink>
+		  <xfill>True</xfill>
+		  <yfill>False</yfill>
+		</child>
+	      </widget>
 	    </widget>
 	  </widget>
 	</widget>
Index: mail/mail-config.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.h,v
retrieving revision 1.74
diff -u -r1.74 mail-config.h
--- mail/mail-config.h	2002/01/25 19:32:27	1.74
+++ mail/mail-config.h	2002/01/26 14:59:04
@@ -25,6 +25,7 @@
 
 #include <gtk/gtk.h>
 #include <camel/camel.h>
+#include <regex.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,6 +39,10 @@
 	char *signature;
 	char *html_signature;
 	gboolean has_html_signature;
+	char *alt_addrs;
+	gboolean alt_addrs_is_re;
+	char *alt_addrs_re;
+	regex_t alt_addrs_re_comp;
 } MailConfigIdentity;
 
 typedef struct {
@@ -63,6 +68,11 @@
 	char *cc_addrs;
 	gboolean always_bcc;
 	char *bcc_addrs;
+
+	int remove_recips_kind;
+	char *remove_recips;
+	char *remove_recips_re;
+	regex_t remove_recips_re_comp;
 	
 	char *pgp_key;
 	gboolean pgp_encrypt_to_self;
@@ -102,6 +112,9 @@
 MailConfigIdentity *identity_copy (const MailConfigIdentity *id);
 void                identity_destroy (MailConfigIdentity *id);
 
+/* Turn a list of addresses (or a regexp) into a regexp */
+gchar              *mail_config_make_regexp_from_list (char *src, gboolean src_is_regexp);
+
 /* Services */
 MailConfigService *service_copy (const MailConfigService *source);
 void               service_destroy (MailConfigService *source);
