1

Topic: Remove mailboxes when deleting user

Even though this request has been posted (and answered) more than once, I will insist in getting some solution:
I need the filesystem mailbox folder automatically deleted while removing a user from iRedAdmin-Pro LDAP UI. Maybe this is about to be addressed in the near(?) future, but some kind of help is needed meanwhile.

Can I modify iRedAdmin-Pro LDAP code to access filesystem and remove folders?
Please, point out which file/files should be modified. I'm not a Python geek, but understand MVC architecture and can code...

Regards, Martin.

2

Re: Remove mailboxes when deleting user

maltamirano wrote:

Can I modify iRedAdmin-Pro LDAP code to access filesystem and remove folders?
Please, point out which file/files should be modified. I'm not a Python geek, but understand MVC architecture and can code...

Alright, here we go:

*) WARNING: Please test your code on a testing machine first, don't do it on production server directly. Removed mailboxes CAN NOT be restored.
*) We're taking the latest iRedAdmin-Pro-LDAP-1.6.3 for example. If you haven't upgraded to 1.6.3, please upgrade it as soon as possible.
*) Open file libs/ldaplib/user.py, find function 'deleteSingleUser()', about line 328:

    # Delete single user.
    def deleteSingleUser(self, mail, deleteFromGroups=True,):
        ...

        try:
            ...
            # Delete object and its subtree.
            deltree.DelTree(self.conn, self.dnUser, ldap.SCOPE_SUBTREE)
        ...

What you need to do are:

*) Query LDAP server to get maildir path of this mail user.
*) Delete the whole maildir directory. Note: It will execute command as user 'iredadmin' and group 'iredadmin' by default, so please make sure this user/group can access mailbox directory (/var/vmail by default).

All your code MUST be placed ABOVE line 'deltree.DelTree()' i paste above.
To delete whole mailbox directory, you can use Python module 'os'. For example:

import os
os.removedirs('/tmp/test_dir/')

3

Re: Remove mailboxes when deleting user

Thanks for you quick reply!
Will folow your directions ASAP and post back results.

Regards,
Martin.

4

Re: Remove mailboxes when deleting user

maltamirano wrote:

Thanks for you quick reply!
Will folow your directions ASAP and post back results.

Regards,
Martin.

Did you ever get this working?

I completely agree that iredadmin does not delete the user files straight away when a user gets deleted.
But I also see how this can become a big issue on small filesystems. So I would suggest a compromise using a daily cron job which delete user email directory if it no longer exists in the databae.
- For security this would save the users email directory for 30 days by:
1. When it first notices that the user no longer exists in the DB write a file with the current date or using a counter which gets decremented each day.
2. For each "deleted user" this date is then compared to the CURRENT_DATE and if it is more then 30 days delete the directory.

This keeps everybody happy :-)