Re: Patch: Handle distribution lists on alias expansion



On 2001.09.21 09:49 Toralf Lund wrote:
> On 2001.09.20 16:40 Brian Stafford wrote:
> > On Thu, 20 September 15:36 Toralf Lund wrote:
> > 
> > > 1. Insert full name according to RFC-822 for each address when a
> > > distribution list is found - refer to notes on code.
> > 
> > RFC 822 is obsolete.  The correct reference is RFC 2822.
> I see.
> 
> I actually read some of the RFC now ;-) Based on the information there, I
> think we can do [see attached patch] [ ... ]
>
> 
> Also, I've now introduced an inconsistency in the formatting between
> addresses found by alias expansion and the ones selected in the address
> book, obviously the address list code ought to be shared between the two
> lookup methods (it's not my fault that it isn't, of course...)
I fixed that, too; another patch is attached (it replaces the other two.)
Question: Why didn't expand_alias_find_match() call
libbalsa_address_to_gchar() all along?

- Toralf
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/21 08:44:57
@@ -38,29 +38,18 @@
 
 #define CASE_INSENSITIVE_NAME
 
-/*
- * FIXME:  Should this come here?
- * 
- *         By putting it here, we slow it down, because we need to scan
- *         the match for ',' every time.
- *
- *         By putting it in the address books, its faster, but the user
- *         must type '"' to match relevant addresses...
- */
-static gchar *
-make_rfc822(gchar *full_name, gchar *address)
+
+gboolean is_mailing_list(const LibBalsaAddress *addr)
 {
-    gchar *new_str;
-    gint i;
+    /**** HACK: Below is valid for LDIF address books. For others we should 
+	        do (<address book for addr>->dist_list_mode && 
+	           g_list_length(address->address_list)>1), but how do we find
+                the address book?*/
 
-    for (i=0; full_name[i] && (full_name[i] != ','); i++);
-    if (full_name[i]) {
-	new_str = g_strdup_printf("\042%s\042 <%s>", full_name, address);
-	g_message("make_rfc822(): New str [%s]", new_str);
-    } else
-	new_str = g_strdup_printf("%s <%s>", full_name, address);
-    return new_str;
+    return (!addr || !*addr->first_name && !*addr->last_name);
+
 }
+
 	
 /*
  * expand_alias_find_match()
@@ -176,8 +165,8 @@
 	    }
 	    addr = LIBBALSA_ADDRESS(search->data);
 	}
-	output = make_rfc822(addr->full_name,
-			     (gchar *) addr->address_list->data);
+	output=libbalsa_address_to_gchar(addr, (is_mailing_list(addr)?-1:0));
+	
 	g_message("expand_alias_find_match(): Found [%s]", addr->full_name);
 	g_list_foreach(match, (GFunc)gtk_object_unref, NULL);
 	
@@ -191,5 +180,4 @@
     if (addy->match)
 	g_message("expand_alias_find_match(): Setting to [%s]", addy->match);
 }
-
 
Index: libbalsa/address.c
===================================================================
RCS file: /cvs/gnome/balsa/libbalsa/address.c,v
retrieving revision 1.12
diff -d -u -r1.12 address.c
--- libbalsa/address.c	2001/08/15 11:30:02	1.12
+++ libbalsa/address.c	2001/09/21 08:44:57
@@ -164,6 +164,65 @@
     return address;
 }
 
+
+/*
+ * FIXME:  Should this come here?
+ * 
+ *         By putting it here, we slow it down, because we need to scan
+ *         the match for ',' every time.
+ *
+ *         By putting it in the address books, its faster, but the user
+ *         must type '"' to match relevant addresses...
+ */
+static gchar *
+make_rfc822(gchar *full_name, gchar *address)
+{
+    gchar *new_str;
+    gint i;
+
+    if (full_name) {
+	for (i=0; full_name[i] && (full_name[i] != ','); i++);
+	if (full_name[i]) {
+	    new_str = g_strdup_printf("\042%s\042 <%s>", full_name, address);
+	    g_message("make_rfc822(): New str [%s]", new_str);
+	} else
+	    new_str = g_strdup_printf("%s <%s>", full_name, address);
+    } else
+	new_str = g_strdup(address);
+
+    return new_str;
+}
+
+
+static gchar *
+make_rfc2822_list(gchar *full_name, gchar *address)
+{
+    if(full_name)		/* Create "group" entry - empty list allowed */
+	return g_strdup_printf("%s : %s;", full_name, (address?address:""));
+    else if(address)
+	return g_strdup(address);
+    
+    return NULL;
+}
+
+
+
+
+
+
+static LibBalsaAddress *find_address(const gchar *addr_str, 
+				     LibBalsaAddress *match_addr)
+{
+    GList *ab_list;             /* To iterate address books   */
+    LibBalsaAddressBook *ab;
+    
+    /* *** 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;
+}
+
+
 /* 
    Get a string version of this address.
 
@@ -174,29 +233,40 @@
 libbalsa_address_to_gchar(LibBalsaAddress * address, gint n)
 {
     gchar *retc = NULL;
-    gchar *address_string;
+    gchar *address_string, *address_string_rfc;
     GList *nth_address;
 
     g_return_val_if_fail(LIBBALSA_IS_ADDRESS(address), NULL);
 
     if ( n == -1 ) {
 	GString *str = NULL;
+	LibBalsaAddress *p_addr;
 
 	nth_address = address->address_list;
 	while ( nth_address ) {
 	    address_string = (gchar *)nth_address->data;
+	    p_addr=find_address(address_string, address);
+
+	    if(p_addr) 
+		address_string_rfc=make_rfc822((p_addr?p_addr->full_name:NULL), 
+						address_string);
+	    else
+		address_string_rfc=g_strdup(address_string);
+
+
 	    if ( str )
-		g_string_sprintfa(str, ", %s", address_string);
+		g_string_sprintfa(str, ", %s", address_string_rfc);
 	    else
-		str = g_string_new(address_string);
+		str = g_string_new(address_string_rfc);
 	    nth_address = g_list_next(nth_address);
+	    g_free(address_string_rfc);
 	}
 
 	if ( str ) {
-	    retc = str->str;
-	    g_string_free(str, FALSE);
-	} else { 
-	    retc = NULL;
+	    retc = make_rfc2822_list(address->full_name, str->str);
+	    g_string_free(str, TRUE);
+	} else {		/* Empty RFC 2822 group if full name exists! */
+	    retc = g_strdup_printf(address->full_name, NULL);
 	}
     } else {
 	nth_address = g_list_nth(address->address_list, n);
@@ -204,11 +274,7 @@
 
 	address_string = (gchar*)nth_address->data;
 
-	if (address->full_name) {
-	    retc = g_strdup_printf("%s <%s>", address->full_name, address_string);
-	} else {
-	    retc = g_strdup(address_string);
-	}
+	retc = make_rfc822(address->full_name, address_string);
     }
     
     return retc;


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