894bd1eb8bedd01072a1917f086716d666ffa2be
[licom.git] / mutt-licom.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use lib (qw(lib));
6
7 use LiCoM::Config (qw(get_config));
8 use LiCoM::Person;
9
10 our $Config = get_config ();
11
12 die unless (defined ($Config->{'uri'}) and defined ($Config->{'bind_dn'})
13         and defined ($Config->{'password'}));
14
15 $Config->{'base_dn'} = $Config->{'bind_dn'} unless (defined ($Config->{'base_dn'}));
16
17 our @Patterns = ();
18 for (@ARGV)
19 {
20         my $temp = $_;
21         $temp =~ s/[^\.\*\w\s]//g;
22
23         next unless ($temp);
24
25         $temp =~ s/\**$/*/;
26         push (@Patterns, [[lastname => $temp], [firstname => $temp], [mail => $temp]]);
27 }
28
29 die ('No (valid) patterns found.') unless (@Patterns);
30
31 our @Matches = LiCoM::Person->search (@Patterns, [[mail => '*']]);
32
33 print STDOUT scalar (@Matches), ' ', (scalar (@Matches) == 1 ? 'entry' : 'entries'), " found.\n";
34
35 for (@Matches)
36 {
37         my $person = $_;
38         my $cn = $person->name ();
39         my @mail = $person->get ('mail');
40
41         for (@mail)
42         {
43                 print "$_\t$cn\tFound by LiCoM\n";
44         }
45 }
46
47 LiCoM::Person->disconnect ();
48
49 exit (0);