From 72a182f851703954afd534a9e4623103b8efdab2 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 4 Oct 2016 14:01:54 +0200 Subject: [PATCH] unroll multiple e-mail addresses into mail, mail_1, mail_2 ... --- bin/ldap-rewrite.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/ldap-rewrite.pl b/bin/ldap-rewrite.pl index 0a3acfa..e9be738 100755 --- a/bin/ldap-rewrite.pl +++ b/bin/ldap-rewrite.pl @@ -157,6 +157,20 @@ sub log_response { foreach my $i ( 0 .. $#{ $attr->{vals} } ) { $attr->{vals}->[$i] =~ s/^u2010/p2010/gs && warn "FIXME group"; } + } elsif ( $attr->{type} eq 'mail' ) { + my @emails; + foreach my $i ( 0 .. $#{ $attr->{vals} } ) { + my $e = $attr->{vals}->[$i]; + if ( $e =~ m/\s+/ ) { + push @emails, split(/\s+/, $e); + } else { + push @emails, $e; + } + } + $attr->{vals} = [ shift @emails ]; + foreach my $i ( 0 .. $#emails ) { + push @attrs, { type => $attr->{type} . '_' . ( $i + 1 ) , vals => [ $emails[$i] ] }; + } } } -- 2.20.1