1

Topic: Errors with delete mailboxes.

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 1.6.7 MARIADB edition.
- Deployed with iRedMail Easy or the downloadable installer? downloadable installer
- Linux/BSD distribution name and version: Ubuntu 20.04.6 LTS
- Store mail accounts in which backend (LDAP/MySQL/PGSQL):  MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? Yes
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

Hi there,

I'm having issues with the delete_mailboxes.py script.

When we installed our current iRdmail server, the script was not configured in the crontab, so I had to do it manually, but the script does not seem to be removing mailboxes from the server.

This is what I have in a file in the cron/daily folder:
/usr/bin/python3 /opt/www/iredadmin/tools/delete_mailboxes.py

I tried to run the script manually with the --debug parameter to see if I got error messages and this is the output:

* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/bv.ind.br/c/o/m/comercial/), skip.
* <<< WARNING >>> Error message: ValueError("time data '.br/c/o/m/comercial' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/gruporiviera.com.br/f/e/l/felipe/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'com.br/f/e/l/felipe' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/c/o/m/comercial3/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'br/c/o/m/comercial3' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/c/o/m/comercial4/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'br/c/o/m/comercial4' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/c/o/m/comercial5/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'br/c/o/m/comercial5' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/g/l/a/gladis/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'com.br/g/l/a/gladis' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/l/u/a/luan/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'e.com.br/l/u/a/luan' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/a/t/i/ativacao/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'm.br/a/t/i/ativacao' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/s/u/p/suporte/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'om.br/s/u/p/suporte' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/c/o/m/comercial/), skip.
* <<< WARNING >>> Error message: ValueError("time data '.br/c/o/m/comercial' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/yukaline.com.br/t/e/c/tecnico/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'om.br/t/e/c/tecnico' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/gruporiviera.com.br/r/o/m/romulo/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'com.br/r/o/m/romulo' does not match format '%Y.%m.%d.%H.%M.%S'").
* <<< WARNING >>> Invalid or missing timestamp in maildir path (/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/), skip.
* <<< WARNING >>> Error message: ValueError("time data 'om/e/n/g/engenharia' does not match format '%Y.%m.%d.%H.%M.%S'").


The comments within the script say:

#       With default iRedMail settings, maildir path will contain a timestamp
#       like this: <domain.com>/u/s/e/username-2016.08.17.09.53.03/
#       (2016.08.17.09.53.03 is the timestamp), this way all created maildir
#       paths are unique, even if you removed the user and recreate it with
#       same mail address.

But this is not how the maildir folders are created on our server.

Any idea why I'm getting this and how to fix it?

Thanks,

----

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

2

Re: Errors with delete mailboxes.

Any ideas?

3 (edited by Cthulhu 2024-01-11 21:11:03)

Re: Errors with delete mailboxes.

# Usage: Either run this script manually, or run it with a daily cron job.
#
#   # python3 delete_mailboxes.py
#
# Available arguments:
#
#   * --delete-without-timestamp:
#
#       [RISKY] If no timestamp string in maildir path, continue to delete it.
#
#       With default iRedMail settings, maildir path will contain a timestamp
#       like this: <domain.com>/u/s/e/username-2016.08.17.09.53.03/
#       (2016.08.17.09.53.03 is the timestamp), this way all created maildir
#       paths are unique, even if you removed the user and recreate it with
#       same mail address.
#
#       Without timestamp in maildir path (e.g. <domain.com>/u/s/e/username/),
#       if you removed a user and recreate it someday, this user will see old
#       emails in old mailbox (because maildir path is same as old user's). So
#       it becomes RISKY to remove the mailbox if no timestamp in maildir path.

So if you read the comments, why don't you read the full explanation within?

It even says that you need to use --delete-without-timestamp if you don't have a timestamp, instead you ignore this and run it with --debug to confirm that the script is working as intended

4 (edited by grupow 2024-01-11 22:37:28)

Re: Errors with delete mailboxes.

Cthulhu wrote:
# Usage: Either run this script manually, or run it with a daily cron job.
#
#   # python3 delete_mailboxes.py
#
# Available arguments:
#
#   * --delete-without-timestamp:
#
#       [RISKY] If no timestamp string in maildir path, continue to delete it.
#
#       With default iRedMail settings, maildir path will contain a timestamp
#       like this: <domain.com>/u/s/e/username-2016.08.17.09.53.03/
#       (2016.08.17.09.53.03 is the timestamp), this way all created maildir
#       paths are unique, even if you removed the user and recreate it with
#       same mail address.
#
#       Without timestamp in maildir path (e.g. <domain.com>/u/s/e/username/),
#       if you removed a user and recreate it someday, this user will see old
#       emails in old mailbox (because maildir path is same as old user's). So
#       it becomes RISKY to remove the mailbox if no timestamp in maildir path.

So if you read the comments, why don't you read the full explanation within?

It even says that you need to use --delete-without-timestamp if you don't have a timestamp, instead you ignore this and run it with --debug to confirm that the script is working as intended

I've done that before opening this thread, but as the comment also says, it's risky and does not solve the problem completely.

Some mailboxes were indeed deleted, but not all of them.

After running that with the --delete-without-timestamp, I get a different error message:

* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/yukaline.com.br/g/l/a/gladis/) owned by user (gladis@yukaline.com.br), but there is another mailbox (/var/vmail/vmail1/yukaline.com.br/g/l/a/gladis/) stored under this directory. Aborted.
* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/yukaline.com.br/l/u/a/luan/) owned by user (luan@yukaline.com.br), but there is another mailbox (/var/vmail/vmail1/yukaline.com.br/l/u/a/luan/) stored under this directory. Aborted.
* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/yukaline.com.br/a/t/i/ativacao/) owned by user (ativacao@yukaline.com.br), but there is another mailbox (/var/vmail/vmail1/yukaline.com.br/a/t/i/ativacao/) stored under this directory. Aborted.
* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/yukaline.com.br/s/u/p/suporte/) owned by user (suporte@yukaline.com.br), but there is another mailbox (/var/vmail/vmail1/yukaline.com.br/s/u/p/suporte/) stored under this directory. Aborted.
* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/yukaline.com.br/c/o/m/comercial/) owned by user (comercial@yukaline.com.br), but there is another mailbox (/var/vmail/vmail1/yukaline.com.br/c/o/m/comercial/) stored under this directory. Aborted.
* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/yukaline.com.br/t/e/c/tecnico/) owned by user (tecnico@yukaline.com.br), but there is another mailbox (/var/vmail/vmail1/yukaline.com.br/t/e/c/tecnico/) stored under this directory. Aborted.
* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/gruporiviera.com.br/r/o/m/romulo/) owned by user (romulo@gruporiviera.com.br), but there is another mailbox (/var/vmail/vmail1/gruporiviera.com.br/r/o/m/romulo/) stored under this directory. Aborted.
* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/) owned by user (engenharia@ciaplan.com), but there is another mailbox (/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/) stored under this directory. Aborted.
* [teste02@vtrade.com.br] /var/vmail/vmail1/vtrade.com.br/t/e/s/teste02/. Account was deleted at 2024-01-03 14:48:54. Mailbox was scheduled to be removed on 2024-01-10.
* Removing mailbox: /var/vmail/vmail1/vtrade.com.br/t/e/s/teste02/

By the way, none of these mailboxes was actually marked to be deleted, and the ones that were supposed to be deleted are still on the server.

So I'm stuck. Our Maildir does not contain a timestamp and I get the critical message now.

Any thoughts?

5

Re: Errors with delete mailboxes.

Then just delete them manually and ensure that mailboxes use timestamp format

6 (edited by grupow 2024-01-12 18:42:18)

Re: Errors with delete mailboxes.

Cthulhu wrote:

Then just delete them manually and ensure that mailboxes use timestamp format

How does this help with anything? Those Maildirs are from real users that are not supposed to be deleted. So, this is also part of the problem.

The script is not working as intended.

If you don't have anything constructive to add, it's best to refrain from making unhelpful comments.

7

Re: Errors with delete mailboxes.

But this is not how the maildir folders are created on our server.

Your problem is related to this, you modified this and made the script inoperable, so i suggested to ensure that the maildirs use timestamp format, aswell as deleting the mailboxes you wan't to delete manually

8

Re: Errors with delete mailboxes.

grupow wrote:

* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/) owned by user (engenharia@ciaplan.com), but there is another mailbox (/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/) stored under this directory. Aborted.

The warning message is quite clear IMO: Mailbox "/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/" is marked to be deleted, but it's still used by some active user right now, hence we can not delete it.

You have to either remove this scheduled removal from SQL table "vmail.deleted_mailboxes", or delete this active user.

9

Re: Errors with delete mailboxes.

ZhangHuangbin wrote:
grupow wrote:

* <<< ABORT, CRITICAL >>> Trying to remove mailbox (/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/) owned by user (engenharia@ciaplan.com), but there is another mailbox (/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/) stored under this directory. Aborted.

The warning message is quite clear IMO: Mailbox "/var/vmail/vmail1/ciaplan.com/e/n/g/engenharia/" is marked to be deleted, but it's still used by some active user right now, hence we can not delete it.

You have to either remove this scheduled removal from SQL table "vmail.deleted_mailboxes", or delete this active user.

The problem is that we never deleted or marked that user to be deleted.

As an example, the user engenharia is an active user that sends and receives emails regularly. I do not know why the system is flagging that as a user as a mailbox that is marked to be deleted.

On the other hand, all test emails I created a week ago and deleted with instructions to be completely removed from the server after a day are still in the system.

Any ideas of what could be causing this or where I should look to find a few answers?

10

Re: Errors with delete mailboxes.

grupow wrote:

The problem is that we never deleted or marked that user to be deleted.
As an example, the user engenharia is an active user that sends and receives emails regularly. I do not know why the system is flagging that as a user as a mailbox that is marked to be deleted.

MAYBE, this account was removed and re-created shortly? hence iRedAdmin(-Pro) left a record in sql table for scheduled removal.

11

Re: Errors with delete mailboxes.

ZhangHuangbin wrote:
grupow wrote:

The problem is that we never deleted or marked that user to be deleted.
As an example, the user engenharia is an active user that sends and receives emails regularly. I do not know why the system is flagging that as a user as a mailbox that is marked to be deleted.

MAYBE, this account was removed and re-created shortly? hence iRedAdmin(-Pro) left a record in sql table for scheduled removal.

I don't think so. It's happening with several other emails and domains as well. They all seem to be active users.

Also, it does not explain the fact that emails. that have been marked to be deleted are still on the server.

12

Re: Errors with delete mailboxes.

I'm afraid that you didn't read replies carefully.

- iRedAdmin(-Pro) created a record in SQL table "vmail.deleted_mailboxes" while removing this user or its domain.
- delete_mailboxes.py cannot remove the mailbox because this mailbox is STILL USED by some user (if it removes the mailbox now, this user will lose all his/her emails).

According to your SQL data, it's indeed there's a user use this maildir path as mailbox. It's very possible that some admin re-created this user after removed it.

Possible solutions are:

1) Append timestamp to maildir path, by appending this line to file /opt/www/iredadmin/settings.py, then restart "iredadmin" service:

MAILDIR_APPEND_TIMESTAMP = True

I believe you already have this parameter in settings.py but set to `False`.

2) Remove SQL records in table "vmail.deleted_mailboxes" of warned user accounts.