adding personalized email header/content in mailman 3
adding personalized email header/content
Hello,
I'm upgrading from mailman 2.1 and need to have personalized email header and content. In 2.1 eventually (couldn't get custom handler work) I had to modify Decorate.py handler. Basically encrypting email and passing it as a parameter in google required One-click unsubscribe email header link (same in the message body).
I tried creating a custom Handler (custom_header.py) in 3.3.19, adding outgoing_pipeline = custom_header in config [mta] section but it doesn't seem to be activating.
Thanks
On 10/16/24 08:42, Alex I wrote:
I tried creating a custom Handler (custom_header.py) in 3.3.19, adding outgoing_pipeline = custom_header in config [mta] section but it doesn't seem to be activating.
First, can you accomplish what you want with a custom list:member:regular:header template? See https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/rest/docs/t...
If not and you need a custom handler, you have a couple of choices.
You can patch the default_posting_pipeline at mailman/pipelines/builtin.py to add your handler to the _default_handlers after installing it in mailman/handlers/. This will require you to reapply the patch after any upgrade.
You can create a plugin which defines a new pipeline which includes your new handler and set the posting_pipeline attribute of your list(s) to the name of your new pipeline. See https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/plugins/doc... for some documentation and https://gitlab.com/mailman/example-mailman-plugin/-/tree/master 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, but no luck. Trying option 1, added custom_header.py file:
from mailman.interfaces.handler import IHandler from zope.interface import implementer
@implementer(IHandler) class AddCustomHeader: def process(self, mlist, message, msgdata): """Add a custom email header.""" message['X-Custom-Header-1'] = 'ABCD' logger.info('Custom header added to message for list: %s', mlist.fqdn_listname)
to /opt/mailman/venv/lib/python3.9/site-packages/mailman/handlers/
and modified /opt/mailman/venv/lib/python3.9/site-packages/mailman/pipelines/builtin.py:
class PostingPipeline(BasePipeline): """The built-in posting pipeline."""
name = 'default-posting-pipeline'
description = _('The built-in posting pipeline.')
_default_handlers = (
'validate-authenticity',
'mime-delete',
'tagger',
'member-recipients',
'avoid-duplicates',
'cleanse',
'cleanse-dkim',
'cook-headers',
'subject-prefix',
'rfc-2369',
'to-archive',
'to-digest',
'to-usenet',
'after-delivery',
'acknowledge',
# All decoration is now done in delivery.
# 'decorate',
'dmarc',
# Message decoration in delivery can break an arc signature, so sign
# in delivery after decorating.
# 'arc-sign',
'custom_header',
'to-outgoing',
)
Upon service restart got KeyError: 'custom_header':
Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/click/core.py", line 1077, in main Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: with self.make_context(prog_name, args, **extra) as ctx: Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/click/core.py", line 943, in make_context Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: self.parse_args(ctx, args) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/click/core.py", line 1644, in parse_args Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: rest = super().parse_args(ctx, args) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/click/core.py", line 1408, in parse_args Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: value, args = param.handle_parse_result(ctx, opts, args) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/click/core.py", line 2400, in handle_parse_result Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: value = self.process_value(ctx, value) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/click/core.py", line 2362, in process_value Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: value = self.callback(ctx, self, value) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/mailman/bin/mailman.py", line 95, in initialize_config Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: initialize(value) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/mailman/core/initialize.py", line 229, in initialize Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: initialize_2(propagate_logs=propagate_logs) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/mailman/core/initialize.py", line 198, in initialize_2 Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: initialize_pipelines() Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/mailman/core/pipelines.py", line 75, in initialize Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: add_components('pipelines', IPipeline, config.pipelines) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/mailman/utilities/modules.py", line 219, in add_components Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: component = component_class() Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: File "/opt/mailman/venv/lib64/python3.9/site-packages/mailman/pipelines/base.py", line 38, in __init__ Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: self._handlers.append(config.handlers[handler_name]) Oct 17 15:42:22 news.ivolatility.com mailman[1986181]: KeyError: 'custom_header' Oct 17 15:42:22 news.ivolatility.com systemd[1]: mailman3.service: Control process exited, code=exited, status=1/FAILURE
On 10/17/24 12:47, Alex I wrote:
Thanks, but no luck. Trying option 1, added custom_header.py file:
The below is incomplete. Additions inline.
import logging
from mailman.interfaces.handler import IHandler from public import public from zope.interface import implementer
logger = logging.getLogger('mailman.smtp') # or some other @public
@implementer(IHandler) class AddCustomHeader: """A doc string is nice"
name = 'custom-header'
description = 'Some description'
def process(self, mlist, message, msgdata): """Add a custom email header.""" message['X-Custom-Header-1'] = 'ABCD' logger.info('Custom header added to message for list: %s', mlist.fqdn_listname)
to /opt/mailman/venv/lib/python3.9/site-packages/mailman/handlers/
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Thanks, but still get the same KeyError: 'customheader'. I don't know python so it seems like waste of time trying to make it work without understanding much.
Still, I've managed it all to work to my needs directly modifying Decorate.py as I did in Mailman 2 (simply copying existing code didn't work as it seems like multipart message parts are now binary objects so had to add extra str conversion, but in the end it seems to be working fine).
Thanks for your help anyway!
On 10/17/24 15:46, Alex I wrote:
Thanks, but still get the same KeyError: 'customheader'. I don't know python so it seems like waste of time trying to make it work without understanding much.
The name
defined in the module needs to be the same as the name of the
file in the handlers directory without the .py extension and with any
_
changed to -
.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
yes, I did that. In my last version I got rid of underscore and dash entirely - just one word customheader as a name definition and filename (with a .py), same difference. Maybe some other type somewhere, but I've had enough )
participants (2)
-
Alex I
-
Mark Sapiro