Skip to content

Commit 7f9ba76

Browse files
committed
Ensure all scripts and inject logic enqueue Mailman.Message.Message objects, not strings or plain email.message.Message
1 parent 5e67c01 commit 7f9ba76

4 files changed

Lines changed: 52 additions & 8 deletions

File tree

Mailman/Post.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
from Mailman import mm_cfg
2222
from Mailman.Queue.sbcache import get_switchboard
23+
from Mailman.Message import Message
24+
from email import message_from_string
2325

2426

2527

@@ -33,7 +35,19 @@ def inject(listname, msg, recips=None, qdir=None):
3335
}
3436
if recips:
3537
kws['recips'] = recips
36-
queue.enqueue(msg, msgdata=kws)
38+
# Ensure msg is a Mailman.Message.Message
39+
if isinstance(msg, str):
40+
emsg = message_from_string(msg)
41+
else:
42+
emsg = msg
43+
if not isinstance(emsg, Message):
44+
mmsg = Message()
45+
for k, v in emsg.items():
46+
mmsg[k] = v
47+
mmsg.set_payload(emsg.get_payload())
48+
else:
49+
mmsg = emsg
50+
queue.enqueue(mmsg, msgdata=kws)
3751

3852

3953

scripts/bounces

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ from Mailman import Utils
3333
from Mailman.i18n import _
3434
from Mailman.Queue.sbcache import get_switchboard
3535
from Mailman.Logging.Utils import LogStdErr
36+
from Mailman.Message import Message
37+
from email import message_from_string
3638

3739
LogStdErr('error', 'bounces')
3840

@@ -53,8 +55,17 @@ def main():
5355
# some MTAs have a hard limit to the time a filter prog can run. Postfix
5456
# is a good example; if the limit is hit, the proc is SIGKILL'd giving us
5557
# no chance to save the message.
58+
msgtext = sys.stdin.read()
59+
emsg = message_from_string(msgtext)
60+
if not isinstance(emsg, Message):
61+
mmsg = Message()
62+
for k, v in emsg.items():
63+
mmsg[k] = v
64+
mmsg.set_payload(emsg.get_payload())
65+
else:
66+
mmsg = emsg
5667
bounceq = get_switchboard(mm_cfg.BOUNCEQUEUE_DIR)
57-
bounceq.enqueue(sys.stdin.read(), msgdata={'listname': listname, '_plaintext': 1})
68+
bounceq.enqueue(mmsg, msgdata={'listname': listname, '_plaintext': 1})
5869

5970

6071

scripts/owner

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ from Mailman import Utils
3434
from Mailman.i18n import _
3535
from Mailman.Queue.sbcache import get_switchboard
3636
from Mailman.Logging.Utils import LogStdErr
37+
from Mailman.Message import Message
38+
from email import message_from_string
3739

3840
LogStdErr('error', 'mailowner')
3941

@@ -54,8 +56,17 @@ def main():
5456
# incoming queue because we need some processing done on the message. The
5557
# processing is minimal though, so craft our own pipeline, expressly for
5658
# the purpose of delivering to the list owners.
59+
msgtext = sys.stdin.read()
60+
emsg = message_from_string(msgtext)
61+
if not isinstance(emsg, Message):
62+
mmsg = Message()
63+
for k, v in emsg.items():
64+
mmsg[k] = v
65+
mmsg.set_payload(emsg.get_payload())
66+
else:
67+
mmsg = emsg
5768
inq = get_switchboard(mm_cfg.INQUEUE_DIR)
58-
inq.enqueue(sys.stdin.read(),
69+
inq.enqueue(mmsg,
5970
msgdata={
6071
'listname': listname,
6172
'_plaintext': 1,

scripts/post

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ from Mailman.i18n import _
3939
from Mailman.Queue.sbcache import get_switchboard
4040
from Mailman.Logging.Utils import LogStdErr
4141
from Mailman.Logging.Syslog import mailman_log
42+
from Mailman.Message import Message
4243

4344
LogStdErr("error", "post")
4445

@@ -60,19 +61,26 @@ def main():
6061
# Read the message from stdin
6162
msgtext = sys.stdin.read()
6263
# Parse the message to get headers for logging
63-
msg = message_from_string(msgtext)
64+
emsg = message_from_string(msgtext)
65+
if not isinstance(emsg, Message):
66+
mmsg = Message()
67+
for k, v in emsg.items():
68+
mmsg[k] = v
69+
mmsg.set_payload(emsg.get_payload())
70+
else:
71+
mmsg = emsg
6472
# Log the inbound message
6573
mailman_log('post', 'inbound message to %s from %s, subject: %s, message-id: %s',
66-
listname, msg.get('from', 'unknown'),
67-
msg.get('subject', '(no subject)'),
68-
msg.get('message-id', 'n/a'))
74+
listname, mmsg.get('from', 'unknown'),
75+
mmsg.get('subject', '(no subject)'),
76+
mmsg.get('message-id', 'n/a'))
6977
# Immediately queue the message for the incoming qrunner to process. The
7078
# advantage to this approach is that messages should never get lost --
7179
# some MTAs have a hard limit to the time a filter prog can run. Postfix
7280
# is a good example; if the limit is hit, the proc is SIGKILL'd giving us
7381
# no chance to save the message.
7482
inq = get_switchboard(mm_cfg.INQUEUE_DIR)
75-
qfile = inq.enqueue(msgtext,
83+
qfile = inq.enqueue(mmsg,
7684
msgdata={'listname': listname,
7785
'tolist': 1,
7886
'_plaintext': 1})

0 commit comments

Comments
 (0)