Identity on reply/forward/continue




This is a patch against current cvs to improve the identity selection code.  
With the patch, Reply and Forward will search the To: list, then the Cc: list 
to find an address matching a configured identity.  For Continued messages, 
it uses the To: address to search for an identity, and copies the From: and 
Reply-To: headers from the continued message, rather than from the Identity.  
Actually, the From header can only be different if it was hand-edited, and 
the guess_identity() function can't find an ident to go with it, and uses the 
default identity.


--
Steve Wall

Index: src/sendmsg-window.c
===================================================================
RCS file: /cvs/gnome/balsa/src/sendmsg-window.c,v
retrieving revision 1.325
diff -u -p -r1.325 sendmsg-window.c
--- src/sendmsg-window.c	2001/11/04 21:50:32	1.325
+++ src/sendmsg-window.c	2001/11/06 13:43:53
@@ -2042,33 +2042,70 @@ guess_identity(BalsaSendmsg* msg)
     gboolean done = FALSE;
     GList *alist;
     LibBalsaMessage *message = msg->orig_message;
-    if( !message || !message->to_list || !balsa_app.identities)
+    SendType type;
+
+    if( !message || !balsa_app.identities)
         return FALSE; /* use default */
 
-    /*
-     * Loop through all the addresses in the message's To:
-     * field, and look for an identity that matches one of them.
-     */
-    for (alist = message->to_list;!done && alist;alist = alist->next) {
-        LibBalsaAddress *addy;
-        GList *nth_address, *ilist;
-        gchar *address_string;
-        
-        addy = alist->data;
-        nth_address = g_list_nth(addy->address_list, 0);
-        address_string = (gchar*)nth_address->data;
-        for (ilist = balsa_app.identities;
-             !done && ilist;
-             ilist = g_list_next(ilist)) {
-            LibBalsaIdentity* ident;
-            
-            ident = LIBBALSA_IDENTITY(ilist->data);
-            if (!g_strcasecmp(address_string,
-                              (gchar*)(ident->address->address_list->data))) {
-                msg->ident = ident;
-                done = TRUE;
+    type = msg->type;
+    if (type == SEND_REPLY || type == SEND_REPLY_ALL || type == SEND_REPLY_GROUP ||
+	type == SEND_FORWARD_ATTACH || type == SEND_FORWARD_INLINE) {
+	/*
+	* Loop through all the addresses in the message's To:
+	* field, and look for an identity that matches one of them.
+	*/
+	alist = message->to_list;
+	for (; !done && alist; alist = g_list_next(alist)) {
+	    GList *ilist = balsa_app.identities;
+	    const gchar *address_string = libbalsa_address_get_mailbox(alist->data, 0);
+
+	    for (; !done && ilist; ilist = g_list_next(ilist)) {
+		LibBalsaIdentity *ident = LIBBALSA_IDENTITY(ilist->data);
+
+		if (!g_strcasecmp(address_string,
+			    (gchar*)(ident->address->address_list->data))) {
+		    msg->ident = ident;
+		    done = TRUE;
 		}
-        }
+	    }
+	}
+	if (!done) {
+	    /* No match in the to_list, try the cc_list */
+	    alist = message->cc_list;
+	    done = FALSE;
+	    for (;!done && alist; alist = g_list_next(alist)) {
+		GList *ilist = balsa_app.identities;
+		const gchar *address_string = libbalsa_address_get_mailbox(alist->data, 0);
+
+		for (; !done && ilist; ilist = g_list_next(ilist)) {
+		    LibBalsaIdentity *ident = LIBBALSA_IDENTITY(ilist->data);
+
+		    if (!g_strcasecmp(address_string,
+				(gchar*)(ident->address->address_list->data))) {
+			msg->ident = ident;
+			done = TRUE;
+		    }
+		}
+	    }
+	}
+    } else if (type == SEND_CONTINUE) {
+	if (message->from) {
+	    GList *ilist = balsa_app.identities;
+	    const gchar *address_string = libbalsa_address_get_mailbox(message->from, 0);
+
+	    /*
+	    * Look for an identity that matches the From: address.
+	    */
+	    for (; !done && ilist; ilist = g_list_next(ilist)) {
+		LibBalsaIdentity *ident = LIBBALSA_IDENTITY(ilist->data);
+
+		if (!g_strcasecmp(address_string, (gchar*)
+				  (ident->address->address_list->data))) {
+		    msg->ident = ident;
+		    done = TRUE;
+		}
+	    }
+	}
     }
     return done;
 }
@@ -2263,9 +2300,19 @@ sendmsg_window_new(GtkWidget * widget, L
     /* Subject: */
     set_entry_to_subject(GTK_ENTRY(msg->subject[1]), message, type, msg->ident);
 
-    if (type == SEND_CONTINUE)
+    if (type == SEND_CONTINUE) {
 	setup_headers_from_message(msg, message);
 
+	/* replace values from the Identity for Continued messages -
+	 * they may have been hand edited. */
+	if (message->from != NULL)
+	    gtk_entry_set_text(GTK_ENTRY(msg->from[1]),
+			       libbalsa_address_to_gchar(message->from, 0));
+	if (message->reply_to != NULL)
+	    gtk_entry_set_text(GTK_ENTRY(msg->reply_to[1]),
+			       libbalsa_address_to_gchar(message->reply_to, 0));
+    }
+
     if (type == SEND_REPLY_ALL) {
 	tmp = libbalsa_make_string_from_list(message->to_list);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]