From a6bd894f302df904588df739f79f1b17b329a0e4 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 3 May 2012 19:47:20 +0200 Subject: Adding debug messages. --- lib/Fripost/Schema/Type/Alias.pm | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'lib/Fripost/Schema/Type/Alias.pm') diff --git a/lib/Fripost/Schema/Type/Alias.pm b/lib/Fripost/Schema/Type/Alias.pm index 9acab0d..8c0b25e 100644 --- a/lib/Fripost/Schema/Type/Alias.pm +++ b/lib/Fripost/Schema/Type/Alias.pm @@ -11,19 +11,17 @@ our $VERSION = '0.01'; ####################################################################### # Search an alias, and return the corresponding entries if found. If no -# alias is given, returns all aliases. +# alias is given, returns all aliases. # Filters on values of both keys `address' and `goto' (unless they are # undefined). -# An extra key `domain' can be given to scope the search on aliases for -# this domain only. sub search { my $self = shift; my $alias = shift; my ($username, $domain); - $domain = $alias->{domain} if defined $alias->{domain}; ($username, $domain) = split /\@/, $alias->{address}, 2 if defined $alias->{address}; + $domain = $username if (defined $username) and not (defined $domain); my $base = $self->{_options}->{base_dn}; $base = join ',', ( 'dc='.$domain, $base ) @@ -34,12 +32,18 @@ sub search { if defined $username; push @filters, '(mailTarget=' .$alias->{goto}. ')' if defined $alias->{goto}; + my $filter = Fripost::Schema::Utils::mkAndFilter( @filters ); + + if ($self->{_options}->{debug}) { + say STDERR "DEBUG: Search base: " .$base; + say STDERR "DEBUG: Search filter: " .$filter; + } my $res = $self->{_ldap}->search( base => $base, scope => 'subtree', attrs => [ 'mailLocalAddress', 'mailTarget', 'isActive' ], - filter => Fripost::Schema::Utils::mkAndFilter( @filters ) + filter => $filter ); die "Error: " .$res->error. "\n" if $res->code; @@ -60,13 +64,16 @@ sub add { my $base = join ',', ( 'mailTarget='.$alias->{goto} , 'dc='. $domain , $self->{_options}->{base_dn} ); - my @attrs = ( mailLocalAddress => $username ); + + my $res; - if ($self->search({ goto => $alias->{goto}, domain => $domain })->count) { + if ($self->search({ goto => $alias->{goto}, address => $domain })->count) { + say STDERR "DEBUG: Modify base: " .$base if ($self->{_options}->{debug}); $res = $self->{_ldap}->modify( $base, add => [ @attrs ] ); } else { + say STDERR "DEBUG: Add base: " .$base if ($self->{_options}->{debug}); $res = $self->{_ldap}->add( $base, attrs => [ objectClass => [ 'inetLocalMailRecipient', 'virtualAliases' ] @@ -86,7 +93,7 @@ sub add { =head1 NAME -Fripost::Schema::Type::Alias - +Fripost::Schema::Type::Alias - =head1 AUTHOR -- cgit v1.2.3