As I want to use PgSQL backend, the task is not so trivial and any existing tool I can start with is welcome.
Check scripts used to create mail accounts shipped in iRedMail: iRedMail-0.8.4/tools/create_mail_user_*.
Also there seems to be potential incompatibility in password format - in my LDAP I have mostly MD5 hashed passwords, but there are several old crypt passwords - is there a way how to deal with them? (eg. convert them after successful login?). From what I found on this forum, iRedMail supports only MD5 and SHA256?
*) For MD5 hashed passwords, you can copy it directly. For example, "$1$WjyyDmty$u1C6fhMKFF0m9ncoNqafj1", store it in column `mailbox.password`.
*) For crypt passwords, if it already has prefix '{CRYPT}' (without quotes), then copy it directly (same as above one). If it doesn't, prepend '{CRYPT}' (without quotes) then store it.
This should work. Let me know whether it works for you or not. if it doesn't work for you, please paste one or two sample passwords here, so that we can help troubleshoot. (Of course you MUST mess up the original password before pasting here, for example, replace several characters.)