Quite common usage scenario is a Postfix mail server with a Mailman instance for groups. Even more often the accounts for the mail are stored in an LDAP tree. And in this case a problem appears, because Mailman doesn’t have a native connection to LDAP. That’s why I needed to have an LDAP 2 Mailman script that would synchronise mailman groups with the LDAP tree. This Perl script is meant to be run from cron.
What this script does is the following:
it binds to the LDAP server with the credentials provided at the beginning of the script
it searches for objects of class mailGroup in the organizationalUnit ou=lists
gets commonName (cn) of the object
checks if the list of that name exists in mailman already
gets all mail attributes values and all memberdn’s mail attributes values and updates the mailing list’s members with them
If the list does not exist, and $create_nonexistent is true, then a new list will be automatically created with the admin/password defined in the variables at the beginning of the script.
For security reasons, this version of the script DOES NOT delete lists, so if you delete a mailGroup from LDAP, you have to do a rmlist -a by yourself. On request, I can give somebody the version which deletes the lists also.
The script relies on a mailGroup objectClass which is defined in the schema that you can download from here.