Trying to save a new style
Dear Mailman-users list,
I have embarked on project to stand up a Mailman3 instance for general staff email announcements and a small number of adhoc lists.
I have a fair amount up and working using Docker and Postfix, with generally emails to/from lists working well, as well as the web interface.
One of the reasons I've used Mailman3 is the API and mailman shell options which I'm slowly trying to wrap my head around, but having some progress.
I have a question for the moment on something which has stumped me, and whilst I may have more questions as I continue on this implementation, I am hopeful someone can point out where I am going wrong on this.
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 zope.component import getUtility from mailman.interfaces.styles import IStyleManager manager = getUtility(IStyleManager)
for style in manager.styles: ... print(style.name) ... legacy-announce legacy-default private-default
from zope.interface import implementer from mailman.interfaces.styles import IStyle @implementer(IStyle) ... class TestStyle: ... name = 'AB-Announce-Style' ... description = 'AB Announce mailing list style.' ... def apply(self, mailing_list): ... mailing_list.admin_immed_notify = true ... mailing_list.admin_notify_mchanges = true ... mailing_list.advertised = false ... mailing_list.allow_list_posts = false ... mailing_list.anonymous_list = false ... mailing_list.archive_policy = "private" ... mailing_list.archive_rendering_mode = "markdown" ... mailing_list.collapse_alternatives = false ... mailing_list.convert_html_to_plaintext = false ... mailing_list.default_member_action = "defer" ... mailing_list.default_nonmember_action = "hold" ... mailing_list.digest_send_periodic = false ... mailing_list.digests_enabled = false ... mailing_list.emergency = false ... mailing_list.include_rfc2369_headers = true ... mailing_list.max_message_size = 40000 ... mailing_list.max_num_recipients = 30 ... mailing_list.member_roster_visibility = "moderators" ... mailing_list.send_goodbye_message = true ... mailing_list.send_welcome_message = true ... mailing_list.subscription_policy = "moderate" ... mailing_list.unsubscription_policy = "moderate" ... manager.register(TestStyle())
commit()
for style in manager.styles: ... print(style.name) ... AB-Announce-Style legacy-announce legacy-default private-default
So at this point the style has been registered, however it doesn't look to save this permanently.
When I quit the shell and log back in, it only shows the original 3 styles. Nor can I see the style from the web interface.
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 zope.component import getUtility from mailman.interfaces.styles import IStyleManager manager = getUtility(IStyleManager)
for style in manager.styles: ... print(style.name) ... legacy-announce legacy-default private-default
Is there a way to save this style permanently ?
Thank you for any assistance you can provide.
Regards, PerryK
On 5/13/24 22:21, Perry Kollmorgen wrote:
Is there a way to save this style permanently ?
What you are doing is fine, but to make it persist you have to create a plugin to do it each time. See https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/plugins/doc... for info and https://gitlab.com/mailman/example-mailman-plugin/-/blob/master/example_mail... for an example.
-- 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 create a python module and install it which sets up 2 new styles, and I have one of those now set as the default list style in Postorius.
I needed to include a few more interfaces but otherwise kept to the example plugin file (just made another file for the other list).
from public import public
from mailman.interfaces.styles import IStyle
from mailman.styles.default import LegacyDefaultStyle
from zope.interface import implementer
from mailman.interfaces.action import Action, FilterAction
from mailman.interfaces.archiver import ArchivePolicy
from mailman.interfaces.autorespond import ResponseAction
from mailman.interfaces.bounce import UnrecognizedBounceDisposition
from mailman.interfaces.digests import DigestFrequency
from mailman.interfaces.mailinglist import (
DMARCMitigateAction, Personalization, ReplyToMunging, SubscriptionPolicy, ArchiveRenderingMode)
from mailman.interfaces.nntp import NewsgroupModeration
from mailman.model.roster import RosterVisibility
# Documentation on List styles
# https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/styles/docs/styles.html
# also some was worked out from src/mailman/styles/base.py
@public
@implementer(IStyle)
class MyPrivateStyle(LegacyDefaultStyle):
# Provide a unique name to this style so it doesn't clash with the ones
# defined by default.
name = 'my-announce-style'
# Provide a usable description that will be shown to the users in Web
# Interface.
description = 'My Announce mailing list style.'
def apply(self, mailing_list):
"""See `IStyle`."""
# Set settings from super class.
super().apply(mailing_list)
# Make modifications on top.
mailing_list.admin_immed_notify = True
mailing_list.admin_notify_mchanges = True
mailing_list.advertised = True
mailing_list.allow_list_posts = False
mailing_list.anonymous_list = False
mailing_list.archive_policy = ArchivePolicy.private
mailing_list.archive_rendering_mode = ArchiveRenderingMode.markdown
mailing_list.collapse_alternatives = False
mailing_list.convert_html_to_plaintext = False
mailing_list.default_member_action = Action.defer
mailing_list.default_nonmember_action = Action.hold
mailing_list.digest_send_periodic = False
mailing_list.digests_enabled = False
mailing_list.include_rfc2369_headers = True
mailing_list.max_message_size = "40000"
mailing_list.max_num_recipients = "30"
mailing_list.member_roster_visibility = RosterVisibility.moderators
mailing_list.send_goodbye_message = True
mailing_list.send_welcome_message = True
mailing_list.subscription_policy = SubscriptionPolicy.moderate
mailing_list.unsubscription_policy = SubscriptionPolicy.moderate
Having a docker-mailman setup means needing to install this any time that the mailmail-core container is rebuilt (not all that often), however the source code for the module can live in a host volume such as /opt/mailman/core/var/plugins , it is simply an execution of the install which is need after a container is rebuilt.
eg: docker exec mailman-core pip install -E /opt/mailman/var/plugins/yourplugin
I currently need to pip install django-allauth[saml] and apk add openldap-dev (this one should be in a new version of the container) on any new mailman-core container anyway so I'm not too worried.
participants (3)
-
Mark Sapiro
-
pcjkollmorgen@hotmail.com
-
Perry Kollmorgen