<<< Date Index >>>     <<< Thread Index >>>

Re: Online Address book



On Tue, Feb 12, 2008 at 01:43:25AM +0100, Nathan Huesken wrote:
> Hi,
> 
> I am using mutt from different computers (like my laptop and the desktop PC 
> at home) and I am wondering if there is some way to always keep my address 
> book synchronized between the two computers.
> The coolest solution would be, if I could install some sort of database on my 
> vServer and make mutt query it everytime I need the address book (and also 
> add new addresses to it).
> 
> Is there some sort if solution for this kind of think?
> 
> Thanks!
> Nathan


Hello, I currently use ldap for an address book with mutt, 

I thought I would send you the scripts I use todo with what you will.

I have added the following lines to my .muttrc ...

## ldap search
set query_command="~/mutt-ldap-search.pl '%s'"

## adding addresses to ldap
macro index,pager a '<shell-escape>/home/matt/bin/add2ldap<enter>'

Allowing me to search and also add addresses by pressing a

The mutt search perl script I found online somewhere, I did make a change to it 
allowing me to have entries without surnames, I just put surnames as '.' in 
this case.

and the add2ldap is a bash script I just chucked together, there prob a better 
way of writing it but it works :)

hth,

Matt.

-- 
Matt Richards
#!/bin/bash

echo Adding a new address to the LDAP database ...

if [ -z $1 ]; then
 echo I need an email address:
 read email
else
 email=$1
fi

if [ -z $email ]; then
 echo I really do need an email address!
 exit
fi

if [ -z $2 ]; then
 echo I need a First Name:
 read fname
else
 fname=$2
fi

if [ -z $3 ]; then
 echo I need a Second Name:
 read sname

 if [ -z $sname ]; then
  echo Using . for second name
  sname=.
 fi

else
 sname=$3
fi


echo "dn: mail=$email,ou=Contacts,o=mattstone
cn: $fname $sname
sn: $sname
givenName: $fname
mail: $email
objectClass: top
objectClass: person
objectClass: inetOrgPerson
objectClass: organizationalPerson" | ldapadd -h 192.168.4.6 -D 
"uid=matt,ou=People,o=mattstone" -x -w "--PASSWD--"

#!/usr/bin/perl

# use strict;
use Net::LDAP;

use constant HOST => '192.168.4.6';
use constant BASE => 'ou=Contacts, o=mattstone';
use constant VERSION => 3;
use constant SCOPE => 'sub';

my $name;
my @attributes = qw( dn givenName sn mail );
{
    print "Searching directory... ";
    $name = shift || die;
    my $filter = "(|(sn=$name*)(givenName=$name*))";
    my $ldap = Net::LDAP->new( HOST, onerror => 'die' )
            || die "Cannot connect: $@";

#    $ldap->bind(version => VERSION) or die "Cannot bind: $@";
     $ldap->bind( "uid=matt,ou=People,o=mattstone", password => "--PASSWD--" ) 
or die "Cannot bind: $@";

    my $result = $ldap->search( base => BASE,
                            scope => SCOPE,
                            attrs => \@attributes,
                            filter => $filter
                            );

    my @entries = $result->entries;

    $ldap->unbind();

    print scalar @entries, " entries found.\n";

    foreach my $entry ( @entries ) {
        my @emailAddr = $entry->get_value('mail');
        foreach my $addr (@emailAddr) {
            print $addr , "\t";

            if ($entry->get_value('sn') eq '.') {
             print $entry->get_value('givenName'), "\n";
            } else {
             print $entry->get_value('givenName'), " ";
             print $entry->get_value('sn'), "\n";
            }

        }
    }
}

Attachment: signature.asc
Description: Digital signature