Mail::Addressbook::Convert::Ldif - convert to and from Ldif formatted addressbooks


use strict;

use Mail::Addressbook::Convert::Ldif;

my $LDIF = new Mail::Addressbook::Convert::Ldif();

my $LdifInFile ="ldifSample.txt"; # name of the file containing the Ldif data

# Convert Ldif to Standard Intermediate format

# see documentation for details on format.

my $raIntermediate = $LDIF->scan(\$LdifInFile);

# This will also work

#my @LdifInArray = @arrayContainingTheLdifData;

#my $raIntermediate = $LDIF->scan(\@LdifInArray);

# Convert back to Ldif

my $raLdifOut = $LDIF->output($raIntermediate);

print join "", @$raIntermediate;

print "\n\n\n\n";

print join "", @$raLdifOut;


Perl, version 5.001 or higher



This module is meant to be used as part of the Mail::Addressbook::Convert distribution.

It can convert a Ldif addressbook to a Standard Intermediate format(STF) and a STF to Ldif As part of the larger distribution, it will allow conversion between Ldif and many other formats.

To use to convert between Ldif and Eudora as an example, you would do the following

use Mail::Addressbook::Convert::Ldif;

use Mail::Addressbook::Convert::Eudora;

my $Ldif = new Mail::Addressbook::Convert::Ldif();

my $Eudora = new Mail::Addressbook::Convert::Eudora();

my $LdifInFile ="ldifSample.txt"; # name of the file containing the Ldif data

my $raIntermediate = $Ldif->scan(\$LdifInFile);

my $raEudora = $Eudora->output($raIntermediate); # reference to an array containing a Eudora addressbook


Standard Intermediate Format(STF) :

                        The addressbook format that is used as an intermediate
                        between conversions.  It is rfc822 compliant and can
                        be used directly as a Eudora addressbook.  Do not use
                        a Eudora addressbook as an STF. Some versions of 
                        Eudora use a format, that while RFC822 compliant, will
                        not work as an STF. Run the Eudora addressbook
                        through $Eudora->scan()

Ldif addressbook: A ldif addressbook. (LDAP Data Interchange Format) This module works on ldif files ouputted by the Netscape Client and Netscape Server. You can find information on various formats by searching for ldif on .



no arguments needed.


Input : a reference to an array containing a ldif file or a reference to a scalar containing the file name with the ldif data.

Returns: a reference to a STF ( see above).


Input: a reference to a STF ( see above). Returns : a reference to an array containing a ldif file.


This only converts email address, aliases, and mailing lists. Phone numbers, postal addresses and other such data are not converted.

This has only been tested on Ldif files produced by Netscape Communicator and the Netscape Server.


You can find information on the ldif format by searching for "ldif" on .

I derived the format by visually inspecting examples, not by reading a document.


This code is derived from the code used on . The site has been up since 1996 ( but ldif was only included on 1997, when Netscape 3 started using it.) The site gets about 8000 unique visitors a month, many of whom make addressbook conversions. The code has been well tested.


Maybe use Net::LDAP::LDIF for the scan method.





Original Version 2001-Sept-09


Copyright (c) 2001 Joe Davidson. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License (see or the GPL copyleft license (


Mail::Addressbook::Convert was written by Joe Davidson <> in 2001.