Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Exchange to Squirrelmail Global Address Book

by BravoTwoZero (Scribe)
on Sep 01, 2004 at 15:17 UTC ( [id://387557]=sourcecode: print w/replies, xml ) Need Help??
Category: E-Mail Programs
Author/Contact Info BravoTwoZero
Description:

We replaced Outlook Web Access with Squirrelmail. To make use of Squirrelmail's global address book option, we could have done LDAP lookups or put this in a local MySQL database. But, just a plain old boring text list was equally useful.

Adjust the $ldapsrv variable, change the "yourdomain.com" in "(mail=*yourdomain.com) to reflect your local mail domain, pipe it to global.abook and scp it to your system running Squirrelmail (On Debian Woody, it's in /var/lib/squirrelmail/data).

The only caveats are that:

  1. We just dupe the full name for the name and nickname categories. Our users get confused by the nicknames, so this makes it easier for them. It includes all distribution lists as well.
  2. We split the "cn" returned at the first white space. The abook wants a first and last name, but DLs have more than two words. So, The first word becomes the given name and the rest becomes the surname.

#!perl
#
# makeaddrbook for squirrelmail
#
# change the ldapsrv variable, pipe it to global.abook and
# copy it to where your global.abook lives. And, change
# the other occurance of yourdomain.com in the 
# (mail=*yourdomain.com) search string to match
# your mocal mail domain.
# 

use Net::LDAP;

$ldapsrv = "exchange.yourdomain.com";

$ldap = Net::LDAP->new($ldapsrv) or die "$@";

$mesg = $ldap->bind;

$mesg = $ldap->search(
    base   => "c=US",
    filter => "(& (mail=*yourdomain.com)(objectclass=person))",
    attrs => ['cn', 'mail']
    );

$mesg->code && die $mesg->error;

foreach $entry ($mesg->entries) { 
    #print "DN: ", $entry->dn, "\n";
    #$entry->dump; 
    my $attr;
        my $line;
    my @results;
        foreach $attr ( $entry->attributes ) {
        next if ( $attr =~ /;binary$/ );
        $val = $entry->get_value ( $attr );
        next if ( $val =~ /^SMEX/ );
        push @results, $val;
        #print "  $attr : ", $entry->get_value ( $attr ) ,"\n";
    }
        my ($gn,$sn) = split(/\s/,$results[0],2);
    $line = join ("|", $results[0], $gn, $sn, $results[1]);
    unless ($line =~ /\|\|\|/) { push @addresses, $line; }
}

$mesg = $ldap->unbind;

@addresses = sort @addresses;

foreach $line (@addresses) { print "$line\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://387557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-18 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found