From f0956194943e813e6d05d890d55f6fe434e7c800 Mon Sep 17 00:00:00 2001 From: Jigme Datse Yli-Rasku Date: Wed, 29 May 2024 21:37:40 -0700 Subject: [PATCH] Added some logging, and some further documentation Added logging to the code, and documenting what the code is doing, not clear with the current code. --- docs/courier-to-mailman3.md | 5 ++++- source/courier-to-mailman3.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/courier-to-mailman3.md b/docs/courier-to-mailman3.md index f9727a7..50da5ad 100644 --- a/docs/courier-to-mailman3.md +++ b/docs/courier-to-mailman3.md @@ -7,4 +7,7 @@ This is our current version trying to communicate between courier and mailman3. ### 2024 May 29 * First change is changing the name to match what I have on the server. -* Second change is to have the `#!` path hopefully pointing in the right place. \ No newline at end of file +* Second change is to have the `#!` path hopefully pointing in the right place. +* Which I screwed up. I think I was typing in the wrong window. + * It's not failing on command line. +* Still failing, let's get some logging. \ No newline at end of file diff --git a/source/courier-to-mailman3.py b/source/courier-to-mailman3.py index 97a6088..a436577 100644 --- a/source/courier-to-mailman3.py +++ b/source/courier-to-mailman3.py @@ -1,17 +1,37 @@ -#!/opt/mailman/venv/bin/su python3 +#!/opt/mailman/venv/bin/python3 # # Written by Thomas Schneider # This script is placed in public domain. If this is not applicable, consider # it licensed under the CC-0: # +# Command Line Arguments (reverse engineered) +# $1 LMTP Port +# $2 ???? +# $3 LMTP Host +# std_in message text + try: + import logging import os import sys import smtplib + logger = logging.getLogger(__name__) + + logging.basicConfig(filename='~/logs/courier-to-mailman.log', level=logging.INFO) + + FORMAT = '%(asctime)s %(clientip)-15s %(user)-8s %(message)s' + logging.basicConfig(format=FORMAT) + + logger.info('Starting Logging') + + # Setup LTMP connection lmtp_host = sys.argv[3] if len(sys.argv) > 3 else 'localhost' + logger.info('lmtp_host: %s', lmtp_host) + # class smtplib.LMTP(host='', port=LMTP_PORT, local_hostname=None, source_address=None) lmtp = smtplib.LMTP(lmtp_host, int(sys.argv[1])) + logger.info('lmtp_port: %s', sysv.arg[1]) try: # Unfortunately qmail sends to local bare LF for end line, while