Introduction

I want to import my GMX addressbook to my local OpenLDAP server so that i can share my addressbook on all my clients. GMX has no LDAP service.

I export my GMX addressbook as LDIF file for thunderbird.

OpenLDAP configuration

/etc/ldap/schema/mozilla_op20.schema
include         /etc/ldap/schema/mozilla_op20.schema
# Indexing options for database #1
index           objectClass     eq,pres 
index           ou,cn,mail,surname,givenname      eq,pres,sub

Import addressbook to OpenLDAP

The thunderbird ldif format has to be fixed for the OpenLDAP server. There are some scripts to do this: * http://wiki.fupps.com/tbldif2ldap * http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/476224

Customize the script to your needs.

I'm using a customized python script:

#!/usr/bin/env python

import sys,getpass
from ldif import LDIFParser #, LDIFWriter
import ldap

basedn = 'ou=Contacts,dc=local'
ldaphost = 'ubuntu-server.local'
login_dn = 'cn=admin,dc=local'
login_pw = getpass.getpass("Password for %s: " % login_dn)

ignore_attribute = [
    'modifytimestamp',
    'facsimileTelephoneNumber',
    #'telephoneNumber',
    #'homeurl',
    #'workurl',
    'homeStreet',
    ]

copy_attribute = [
    #['sn', 'cn'],
    ]

ignore_objectclass = [
    #'person',
    ]

class ImportLDIFAddressBook(LDIFParser):
    def __init__(self, input):
        LDIFParser.__init__(self, input)
        #self.writer = LDIFWriter(output)
        self.ldap = ldap.open(ldaphost)
        self.ldap.simple_bind_s(login_dn, login_pw)
    def handle(self, dn, entry):
        dn = self.fix_dn(dn)
        self.fix_entry(entry)
        self.fix_objectclass(entry['objectclass'])
        #self.writer.unparse(dn, entry)
        self.update_dn(dn, entry)
    def fix_dn(self, dn):
        head = dn.split(',', 1)[0]
        return head + ',' + basedn
    def fix_entry(self, entry):
        for value in ignore_attribute:
            if value in entry:
                del entry[value]
        for target, source in copy_attribute:
            entry[target] = entry[source]
    def fix_objectclass(self, objectclass):
        for value in ignore_objectclass:
            if value in objectclass:
                objectclass.remove(value)
    def update_dn(self,dn,entry):
        print "Updating",repr(dn)
        #delete old entry it it exists
        try:
                self.ldap.delete_s(dn)
        except:
                pass
        # add new or updated entry
        self.ldap.add_s(dn,entry.items())

    def cleanup(self):
        self.ldap.unbind()

if len(sys.argv) != 2:
    print sys.argv[0], 'input.ldif'#, 'output.ldif'
    sys.exit()

input = open(sys.argv[1], 'r')
#output = open(sys.argv[2], 'w')
parser = ImportLDIFAddressBook(input)
parser.parse()
parser.cleanup()

Maybe you have to convert your ldif from dos to unix format. Install package tofrodos and run fromdos.

$ ldapadd -x -W -D cn=admin,dc=local -f thunderbird.ldif

Other addressbook schema

$ wget http://www.wains.be/pub/thunderbird.schema

* mozilla schema v 0.6 * schema for outlook