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.

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

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 :-)

5

Re: Remove mailboxes when deleting user

Hi guys,

Just want to let you know, upcoming iRedAdmin-Pro release will log maildir path of deleted user in SQL table, so you can delete mailboxes with a script manually or with a cron job.

You can check the SQL table structure here (table name: deleted_mailboxes), let me know if you want to store more info in this table:
https://bitbucket.org/zhb/iredmail/src/ … ult#cl-283

6

Re: Remove mailboxes when deleting user

Excellent!

I was just about to revive my thread to inquire about the status of this.
We launch live this Sunday!

Is there any chance I can get a quick how to so I can implement the change prior to the launch?

If not we can wait, however It would of great use to us so that we can implement the changes while the server is dormant and inactive.

Either way, the support is phenomenal. It is very much appreciated.

7

Re: Remove mailboxes when deleting user

quick note...We're using the Mysql-pro version

8

Re: Remove mailboxes when deleting user

Hi amora,

Since you have a valid iRedAdmin-Pro-MySQL license, I can send you development version of iRedAdmin-Pro-MySQL if you want.

WARNING: It requires the upcoming iRedMail release, you have to upgrade iRedMail-0.8.4 (or earlier) first. Mail me (zhb@) if you want to get some more details.