Bugfixes since the last checkin.
[licom.git] / mutt-licom.pl
index 894bd1e..08c2502 100755 (executable)
@@ -2,15 +2,36 @@
 
 use strict;
 use warnings;
-use lib (qw(lib));
+
+use FindBin (qw($Bin));
+use lib ("$Bin/lib");
 
 use LiCoM::Config (qw(get_config));
 use LiCoM::Person;
 
-our $Config = get_config ();
+our $Config;
 
-die unless (defined ($Config->{'uri'}) and defined ($Config->{'bind_dn'})
-       and defined ($Config->{'password'}));
+if (-e $ENV{'HOME'} . '/.licomrc')
+{
+       $Config = get_config ($ENV{'HOME'} . '/.licomrc');
+}
+elsif (-e '/etc/licom/licom.conf')
+{
+       $Config = get_config ('/etc/licom/licom.conf');
+}
+else
+{
+       $Config = get_config ();
+}
+
+unless (defined ($Config->{'uri'}) and defined ($Config->{'bind_dn'})
+       and defined ($Config->{'password'}))
+{
+       die (<<ERROR);
+The configuration has not been found or is not complete. At least the options
+uri, bind_dn and password are needed.
+ERROR
+}
 
 $Config->{'base_dn'} = $Config->{'bind_dn'} unless (defined ($Config->{'base_dn'}));
 
@@ -28,6 +49,14 @@ for (@ARGV)
 
 die ('No (valid) patterns found.') unless (@Patterns);
 
+LiCoM::Person->connect 
+(
+       uri     => $Config->{'uri'},
+       base_dn => $Config->{'base_dn'},
+       bind_dn => $Config->{'bind_dn'},
+       password => $Config->{'password'}
+) or die;
+
 our @Matches = LiCoM::Person->search (@Patterns, [[mail => '*']]);
 
 print STDOUT scalar (@Matches), ' ', (scalar (@Matches) == 1 ? 'entry' : 'entries'), " found.\n";