Patch: Handle distribution lists on alias expansion



Attached to this message is my first attempt at introducing distribution
list support for the address book alias expansion.

Remaining work:
1. Insert full name according to RFC-822 for each address when a
distribution list is found - refer to notes on code.
2. Display the name of the matching entry somehow, as it is not necessarily
included in the (address list) output.

Comments?
-- 
Toralf Lund <toralf@kscanners.com>  +47 66 85 51 22
Kongsberg Scanners AS               +47 66 85 51 00 (switchboard)
http://www.kscanners.no/~toralf     +47 66 85 51 01 (fax)
Index: src/expand-alias.c
===================================================================
RCS file: /cvs/gnome/balsa/src/expand-alias.c,v
retrieving revision 1.22
diff -d -u -r1.22 expand-alias.c
--- src/expand-alias.c	2001/09/06 08:59:38	1.22
+++ src/expand-alias.c	2001/09/20 15:30:10
@@ -61,6 +61,32 @@
 	new_str = g_strdup_printf("%s <%s>", full_name, address);
     return new_str;
 }
+
+static gboolean is_mailing_list(const LibBalsaAddress *addr)
+{
+    /**** HACK: The following is valid for LDIF address books: */
+
+    return (!addr || !*addr->first_name && !*addr->last_name);
+}
+
+
+
+static LibBalsaAddress *find_address(const gchar *addr_str, 
+				     LibBalsaAddress *match_addr)
+{
+    GList *ab_list;             /* To iterate address books   */
+    LibBalsaAddressBook *ab;
+    
+    if(is_mailing_list(match_addr)) {
+	/* *** TODO: Search all address books or just the one match_addr 
+	             belongs for entries containing addr_str in address list.
+		     Return first one where !is_mailin_list(<entry>) is true */
+	return NULL;
+    }
+    
+    return match_addr;
+}
+
 	
 /*
  * expand_alias_find_match()
@@ -162,6 +188,8 @@
      * find the one we want.
      */
     if (match) {
+	GList *addr_entry;
+
 	i = tab;
 	if ((i == 0) && (strlen(prefix) > strlen(input))) {
 	    addr = LIBBALSA_ADDRESS(match->data);
@@ -176,8 +204,28 @@
 	    }
 	    addr = LIBBALSA_ADDRESS(search->data);
 	}
-	output = make_rfc822(addr->full_name,
-			     (gchar *) addr->address_list->data);
+	for(addr_entry=addr->address_list; addr_entry;
+	    addr_entry=g_list_next(addr_entry)) {
+	    gchar *addr_str=(gchar *) addr_entry->data;
+	    LibBalsaAddress *p_addr=find_address(addr_str, addr);
+	    gchar *rfc_addr;
+
+	    if(p_addr) 
+		rfc_addr=make_rfc822((p_addr?p_addr->full_name:addr_str), 
+				     addr_str);
+	    else
+		rfc_addr=g_strdup(addr_str);
+	    
+	    if(output) {
+		gchar *old_output=output;
+
+		output = g_strjoin(", ", output, rfc_addr, NULL);
+		g_free(old_output);
+		g_free(rfc_addr);
+	    } else
+		output = rfc_addr;
+	}
+	
 	g_message("expand_alias_find_match(): Found [%s]", addr->full_name);
 	g_list_foreach(match, (GFunc)gtk_object_unref, NULL);
 	
@@ -191,5 +239,4 @@
     if (addy->match)
 	g_message("expand_alias_find_match(): Setting to [%s]", addy->match);
 }
-
 


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