Current status and issue deleting Archives in Mailman3
So just want to make sure I have the latest information after searching this list and googling or have I missed something? It appears there is no way in mailman3 to delete archives. There has been discussion on implementing this, but it has not been developed? is that correct?
I saw references to:
from hyperkitty.models import MailingList ml = MailingList.objects.get(name="test2@freeculture.org") ml.delete()
But how do I run this? I believe it is run in mailman-core (I am in a docker environment but that should not matter). I can get into the mailman shell, but that command does not work
I did the following: bash-5.0# mailman shell Welcome to the GNU Mailman shell Use commit() to commit changes. Use abort() to discard changes since the last commit. Exit with ctrl+D does an implicit commit() but exit() does not.
from hyperkitty.models import MailingList Traceback (most recent call last): File "<console>", line 1, in <module> ModuleNotFoundError: No module named 'hyperkitty'
What am I missing?
************** Question 2
What about pruning archives? I use to run a script for mailman2 to prune archives of messages older than X days for a list, Is that possible in mailman3
So I am teaching myself to fish, and see that it is actually django-admin, so that is in mailman-web? (in docker)
But i get this:
$ docker exec -it mailman-web /bin/bash bash-5.0# django-admin shell Python 3.8.10 (default, May 6 2021, 06:30:44) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole)
from hyperkitty.models import MailingList Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/lib/python3.8/site-packages/hyperkitty/models/__init__.py", line 25, in <module> from .category import ThreadCategory File "/usr/lib/python3.8/site-packages/hyperkitty/models/category.py", line 61, in <module> class ThreadCategory(models.Model): File "/usr/lib/python3.8/site-packages/django/db/models/base.py", line 103, in __new__ app_config = apps.get_containing_app_config(module) File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 252, in get_containing_app_config self.check_apps_ready() File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 134, in check_apps_ready settings.INSTALLED_APPS File "/usr/lib/python3.8/site-packages/django/conf/__init__.py", line 79, in __getattr__ self._setup(name) File "/usr/lib/python3.8/site-packages/django/conf/__init__.py", line 60, in _setup raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
On Nov 2, 2021, at 2:50 PM, bob B <bader@cchmc.org> wrote:
$ docker exec -it mailman-web /bin/bash
I always use "-u mailman" to keep file permissions correct:
docker exec -it -u mailman mailman-web bash
That may or may not be your problem, but it might keep you from having permission issues down the road. -Seth
On 11/2/21 11:59 AM, Seth Seeger wrote:
On Nov 2, 2021, at 2:50 PM, bob B <bader@cchmc.org> wrote:
$ docker exec -it mailman-web /bin/bash
I always use "-u mailman" to keep file permissions correct:
docker exec -it -u mailman mailman-web bash
That may or may not be your problem, but it might keep you from having permission issues down the road.
That is excellent advice. Always run Mailman and Django commands as the Mailman user.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
On 11/2/21 11:50 AM, bob B wrote:
So I am teaching myself to fish, and see that it is actually django-admin, so that is in mailman-web? (in docker)
But i get this:
$ docker exec -it mailman-web /bin/bash bash-5.0# django-admin shell Python 3.8.10 (default, May 6 2021, 06:30:44) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole)
from hyperkitty.models import MailingList Traceback (most recent call last): ... raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Do what it says. I.e. run
DJANGO_SETTINGS_MODULE=path/to/settings; django-admin shell
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
On Nov 2, 2021, at 12:51 PM, Mark Sapiro <mark@msapiro.net> wrote:
On 11/2/21 11:50 AM, bob B wrote:
So I am teaching myself to fish, and see that it is actually django-admin, so that is in mailman-web? (in docker) But i get this: $ docker exec -it mailman-web /bin/bash bash-5.0# django-admin shell Python 3.8.10 (default, May 6 2021, 06:30:44) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole)
from hyperkitty.models import MailingList Traceback (most recent call last): ... raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Do what it says. I.e. run
DJANGO_SETTINGS_MODULE=path/to/settings; django-admin shell
DJANGO_SETTINGS_MODULE expects a Python import path, instead of a filesystem path.
The docker has documentation on running management commands, which in this case is “shell” 1
$ docker exec -it mailman-web python3 manage.py shell
I know there are plethora of ways to run Django management commands, but this is the easiest one for docker.
django-admin will work too, but you have to be in the right working directory for the import path to work and it get weird. I’ve always disliked how Django management commands work unfortunately and in trying to “fix” that with “mailman-web” (which isn’t adopted by container images), i feel I might have re-invented a third option.
-- thanks, Abhilash Raj (maxking)
On 11/2/21 9:30 AM, bob B wrote:
So just want to make sure I have the latest information after searching this list and googling or have I missed something? It appears there is no way in mailman3 to delete archives. There has been discussion on implementing this, but it has not been developed? is that correct?
I'm not sure when it first appeared, but current Hyperkitty has Delete Archive button on the list overview page, but it is only available to Django superusers, not to list owners.
I saw references to:
from hyperkitty.models import MailingList ml = MailingList.objects.get(name="test2@freeculture.org") ml.delete()
But how do I run this? I believe it is run in mailman-core (I am in a docker environment but that should not matter). I can get into the mailman shell, but that command does not work
It is run in a Django management shell, not mailman shell.
************** Question 2
What about pruning archives? I use to run a script for mailman2 to prune archives of messages older than X days for a list, Is that possible in mailman3
There are a few ways to do this. You can export the archive for a list as an mbox and edit the mbox to delete the messages you want to prune. Then delete the archive for this list and finally run hyperkitty_import to import the pruned mbox.
Alternatively, in a django management shell, you could try something like
import datetime
from hyperkitty.models import Email
for msg in Email.objects.filter(mailinglist_id=X):
if msg.date < datetime.datetime(Y, M, D,
tzinfo=datetime.timezone.utc):
msg.delete()
where X is the id of the mailing list you want to prune, or if you wanted to do all lists, just use Email.objects.all() instead of filtering on mailinglist_id.
And, Y, M and D are integer Year, Month and Day for the cutoff.
Note that something like
from hyperkitty.models import MailingList
for ml in MailingList.objects.all():
print('{}: {}'.format(ml.name, ml.id))
will print all the list names and their ids.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Thanks, I was able to log into the Hyperkitty interface with the mailman admin account (which is different that the django super user I believe) and i could delete the archives.
https://[Domain]/admin/hyperkitty/mailinglist/
Also thanks for the info on pruning archives. I hope that this feature gets built in one day or becomes easier to implement.
participants (4)
-
Abhilash Raj
-
bob B
-
Mark Sapiro
-
Seth Seeger