Skip to Content.
Sympa Menu

en - Re: [sympa-users] include_ldap_query

Subject: The mailing list for listmasters using Sympa

List archive

Chronological Thread  
  • From: Tornóci László <address@concealed>
  • To: address@concealed
  • Subject: Re: [sympa-users] include_ldap_query
  • Date: Tue, 03 Sep 2013 19:53:11 +0200

On 09/03/2013 06:11 PM, Rance Hall wrote:

I have a sympa list that has its subscriber base generated from an ldap
query.

The dialog in sympa that lets me set up the details seems to work as far
as it goes.

I would like to have this ldap query return both the users NAME from
ldap *and* the EMAIL address where it now only returns email.

We now have a need to use a template to send out email that includes the
users name and their email.

I'm confused at the sympa interface for this because I would need to map
our ldap field names to names sympa would like.

I looked at include_ldap_2level_query but this looks to be not what I
want. It looks to be two separate ldap queries when one ldap query can
provide multiple fields in its reply.

Anybody have any ideas about how to do this correctly?

Rance


Hi,

as far as I know, the current version (6.1.17) doesn't support what you want. However, there are some patches that you can use to do that. I use the include_ldap_2level_query successfully to provide me with names as well. I have attached the patch against List.pm 6.1.17 (hopefully the attachment gets through).

Yours: Laszlo
--- bin/List.pm	2012-08-01 17:26:27.000000000 +0200
+++ bin/List.pm.patched	2012-08-01 20:22:56.000000000 +0200
@@ -914,8 +914,8 @@
 							       'gettext_id' => "second-level filter template",
 							       'order' => 14
 							       },
-						  'attrs2' => {'format' => '\w+',
-							      'length' => 15,
+						  'attrs2' => {'format' => '.+',
+							      'length' => 50,
 							      'default' => 'mail',
 							      'gettext_id' => "second-level extracted attribute",
 							      'order' => 15
@@ -8387,7 +8387,7 @@
     ## returns a reference to a HASH where the keys are the DNs
     ##  the second level hash's hold the attributes
 
-    my (@attrs, @emails);
+    my (@attrs, @emails, @names);
  
     while (my $e = $fetch->shift_entry) {
 	my $entry = $e->get_value($ldap_attrs1, asref => 1);
@@ -8411,10 +8411,15 @@
 	($suffix2 = $ldap_suffix2) =~ s/\[attrs1\]/$attr/g;
 	($filter2 = $ldap_filter2) =~ s/\[attrs1\]/$attr/g;
 
+	# The first attribute is the email and the second (if defined) is the name
+	my @search_attrs = split(/,/, $ldap_attrs2);
+	my $mail_attr = $search_attrs[0];
+	my $name_attr = $search_attrs[1] if defined $search_attrs[1];
+
 	do_log('debug2', 'Searching on server %s ; suffix %s ; filter %s ; attrs: %s', $param->{'host'}, $suffix2, $filter2, $ldap_attrs2);
 	$fetch = $ldaph->search ( base => "$suffix2",
 				  filter => "$filter2",
-				  attrs => [ "$ldap_attrs2" ],
+				  attrs => [ @search_attrs ], 
 				  scope => "$ldap_scope2");
 	if ($fetch->code()) {
 	    do_log('err','LDAP search (2nd level) failed : %s. Node: %s (searching on server %s ; suffix %s ; filter %s ; attrs: %s)', 
@@ -8426,9 +8431,10 @@
 	##  the second level hash's hold the attributes
 	
 	while (my $e = $fetch->shift_entry) {
-	    my $entry = $e->get_value($ldap_attrs2, asref => 1);
+	    my $entry = $e->get_value($mail_attr, asref => 1);
+	    my $flag = 0;
 
-	    ## Multiple values
+	    ## Multiple values for email address
 	    if (ref($entry) eq 'ARRAY') {
 		foreach my $email (@{$entry}) {
 		    my $cleanmail = &tools::clean_email($email);
@@ -8436,6 +8442,7 @@
 		    next if ($emailsViewed{$cleanmail});
 		    push @emails, $cleanmail;
 		    $emailsViewed{$cleanmail} = 1;
+		    $flag = 1;
 		    last if ($ldap_select2 eq 'first');
 		}
 	    }else {
@@ -8443,8 +8450,21 @@
 		unless( (($ldap_select2 eq 'regex') && ($cleanmail !~ /$ldap_regex2/))||$emailsViewed{$cleanmail}) {
 		    push @emails, $cleanmail;
 		    $emailsViewed{$cleanmail} = 1;
+		    $flag = 1;
 		}
 	    }
+	    
+	    my $entry2 = $e->get_value($name_attr, asref => 1);
+		
+	    ## Multiple values for name (get always the first one)
+	    if (ref($entry2) eq 'ARRAY') {
+			foreach my $nome (@{$entry2}) {
+				push @names, $nome if $flag;
+				last;
+			}
+		} else {
+			push @names, $entry2 if $flag;
+		}
 	}
     }
     
@@ -8453,7 +8473,9 @@
 	return undef;
     }
     
+    my $i = -1;
     foreach my $email (@emails) {
+	$i++;
 	next if ($email =~ /^\s*$/);
 
 	$email = &tools::clean_email($email);
@@ -8470,6 +8492,7 @@
 	    $total++;
 	}
 
+	$u{'gecos'} = $names[$i];
 	$u{'email'} = $email;
 	$u{'date'} = time;
 	$u{'update_date'} = time;



Archive powered by MHonArc 2.6.19+.

Top of Page