Index: mail/Mail.idl
===================================================================
RCS file: /cvs/gnome/evolution/mail/Mail.idl,v
retrieving revision 1.8
diff -u -r1.8 Mail.idl
--- mail/Mail.idl	2001/07/19 01:25:09	1.8
+++ mail/Mail.idl	2002/01/24 01:47:35
@@ -48,6 +48,8 @@
 			string signature;
 			string html_signature;
 			boolean has_html_signature;
+			string alt_addrs;
+			boolean alt_addrs_is_re;
 		};
 
 		struct Service {
Index: mail/mail-account-gui.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-account-gui.c,v
retrieving revision 1.61
diff -u -r1.61 mail-account-gui.c
--- mail/mail-account-gui.c	2002/01/08 20:32:54	1.61
+++ mail/mail-account-gui.c	2002/01/24 01:47:36
@@ -1257,6 +1257,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)
@@ -1276,6 +1279,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 */
@@ -1679,6 +1686,19 @@
 	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 = e_utf8_gtk_entry_get_text (gui->alt_addrs);
+	account->id->alt_addrs_is_re = gtk_toggle_button_get_active (gui->alt_addrs_is_re);
+	account->id->alt_addrs_re = mail_config_alt_addrs_make_re
+		(account->id->alt_addrs, account->id->alt_addrs_is_re);
+	if (regcomp (&(account->id->alt_addrs_re_comp),
+		    account->id->alt_addrs_re,
+		    REG_EXTENDED|REG_ICASE|REG_NOSUB)) {
+		regcomp (&(account->id->alt_addrs_re_comp), "^$",
+			REG_EXTENDED|REG_ICASE|REG_NOSUB);
+		e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
+			  _("Bad regexp."));
+		return FALSE;
+	}
 	
 	old_enabled = account->source && account->source->enabled;
 	service_destroy (account->source);
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/24 01:47:36
@@ -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;
Index: mail/mail-callbacks.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-callbacks.c,v
retrieving revision 1.297
diff -u -r1.297 mail-callbacks.c
--- mail/mail-callbacks.c	2002/01/22 20:52:16	1.297
+++ mail/mail-callbacks.c	2002/01/24 01:47:38
@@ -877,6 +877,38 @@
 	}
 	
 	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 (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 (regexec(&(acc->id->alt_addrs_re_comp),
+				    addr, 0, NULL, 0) == 0) {
+			    account = acc;
+			    goto found;
+			}
+			l = l->next;
+		    }
+		}
+	}
 	
  found:
 	
Index: mail/mail-config.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.c,v
retrieving revision 1.194
diff -u -r1.194 mail-config.c
--- mail/mail-config.c	2002/01/08 00:48:54	1.194
+++ mail/mail-config.c	2002/01/24 01:47:38
@@ -135,6 +135,14 @@
 	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)) {
+		regcomp (&(new->alt_addrs_re_comp), "^$",
+			REG_EXTENDED|REG_ICASE|REG_NOSUB);
+	}
 	
 	return new;
 }
@@ -150,10 +158,51 @@
 	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);
 }
 
+/* Alternate addresses */
+gchar *
+mail_config_alt_addrs_make_re (char *alt_addrs, gboolean alt_addrs_is_re)
+{
+    gchar *new_re;
+    if (alt_addrs == NULL) alt_addrs = "";
+
+    if (alt_addrs_is_re) {
+	new_re = g_strdup (alt_addrs);
+    } else {
+	int just_did_pipe = 0;
+	gchar *s, *d;
+	new_re = g_malloc (strlen(alt_addrs) * 2 + 10);
+	strcpy(new_re, "^(");
+	d = new_re + 2;
+	s = alt_addrs;
+	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) 
@@ -458,6 +507,23 @@
 		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_alt_addrs_make_re (id->alt_addrs,
+			    id->alt_addrs_is_re);
+		/* FIXME: What should we do if the regexp doesn't compile? */
+		if (regcomp (&(id->alt_addrs_re_comp), id->alt_addrs_re,
+			REG_EXTENDED|REG_ICASE|REG_NOSUB)) {
+			regcomp (&(id->alt_addrs_re_comp), "^$",
+				REG_EXTENDED|REG_ICASE|REG_NOSUB);
+		}
 		
 		/* get the source */
 		source = g_new0 (MailConfigService, 1);
@@ -782,6 +848,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);
@@ -2351,6 +2423,17 @@
 	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;
+	mail_id->alt_addrs = g_strdup (id.alt_addrs);
+	mail_id->alt_addrs_is_re = id.alt_addrs_is_re;
+	mail_id->alt_addrs_re =
+	    mail_config_alt_addrs_make_re (id.alt_addrs, id.alt_addrs_is_re);
+	if (regcomp (&(mail_id->alt_addrs_re_comp), mail_id->alt_addrs_re,
+		REG_EXTENDED|REG_ICASE|REG_NOSUB)) {
+		regcomp (&(mail_id->alt_addrs_re_comp), "^$",
+			REG_EXTENDED|REG_ICASE|REG_NOSUB);
+		/* FIXME: we need an exception. */
+		return;
+	}
 	
 	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/24 01:47:40
@@ -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>
Index: mail/mail-config.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.h,v
retrieving revision 1.73
diff -u -r1.73 mail-config.h
--- mail/mail-config.h	2002/01/08 00:48:54	1.73
+++ mail/mail-config.h	2002/01/24 01:47:40
@@ -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 {
@@ -102,6 +107,9 @@
 MailConfigIdentity *identity_copy (const MailConfigIdentity *id);
 void                identity_destroy (MailConfigIdentity *id);
 
+/* Alternate Addresses */
+gchar              *mail_config_alt_addrs_make_re (char *alt_addrs, gboolean alt_addrs_is_re);
+
 /* Services */
 MailConfigService *service_copy (const MailConfigService *source);
 void               service_destroy (MailConfigService *source);
