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