mutt-licom.pl is working now.
[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 LiCoM::Person->connect 
32 (
33         uri     => $Config->{'uri'},
34         base_dn => $Config->{'base_dn'},
35         bind_dn => $Config->{'bind_dn'},
36         password => $Config->{'password'}
37 ) or die;
38
39 our @Matches = LiCoM::Person->search (@Patterns, [[mail => '*']]);
40
41 print STDOUT scalar (@Matches), ' ', (scalar (@Matches) == 1 ? 'entry' : 'entries'), " found.\n";
42
43 for (@Matches)
44 {
45         my $person = $_;
46         my $cn = $person->name ();
47         my @mail = $person->get ('mail');
48
49         for (@mail)
50         {
51                 print "$_\t$cn\tFound by LiCoM\n";
52         }
53 }
54
55 LiCoM::Person->disconnect ();
56
57 exit (0);