Skip to content

Commit ebbc16d

Browse files
committed
update
1 parent bc51497 commit ebbc16d

4 files changed

Lines changed: 100 additions & 43 deletions

File tree

Mailman/Queue/CommandRunner.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,37 @@ def indent(lines):
244244
class CommandRunner(Runner):
245245
QDIR = mm_cfg.CMDQUEUE_DIR
246246

247+
def _validate_message(self, msg, msgdata):
248+
"""Validate a command message.
249+
250+
Args:
251+
msg: The message to validate
252+
msgdata: Additional message metadata
253+
254+
Returns:
255+
tuple: (msg, success) where success is True if validation passed
256+
"""
257+
try:
258+
# Check for required headers
259+
if not msg.get('message-id'):
260+
syslog('error', 'CommandRunner._validate_message: Missing Message-ID header')
261+
return msg, False
262+
263+
if not msg.get('from'):
264+
syslog('error', 'CommandRunner._validate_message: Missing From header')
265+
return msg, False
266+
267+
# Check for command in msgdata
268+
if not msgdata.get('command'):
269+
syslog('error', 'CommandRunner._validate_message: No command in msgdata')
270+
return msg, False
271+
272+
return msg, True
273+
274+
except Exception as e:
275+
syslog('error', 'CommandRunner._validate_message: Error validating message: %s', str(e))
276+
return msg, False
277+
247278
def _dispose(self, mlist, msg, msgdata):
248279
# Validate message type first
249280
msg, success = self._validate_message(msg, msgdata)

Mailman/Queue/NewsRunner.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,24 @@ def _connect(self):
102102
self._nntp = None
103103

104104
def _validate_message(self, msg, msgdata):
105-
"""Validate the message for news posting."""
105+
"""Validate the message for news posting.
106+
107+
Args:
108+
msg: The message to validate
109+
msgdata: Additional message metadata
110+
111+
Returns:
112+
tuple: (msg, success) where success is True if validation passed
113+
"""
106114
try:
107115
# Check if the message has a Message-ID
108116
if not msg.get('message-id'):
109117
syslog('error', 'Message validation failed for news message')
110-
return False
111-
return True
118+
return msg, False
119+
return msg, True
112120
except Exception as e:
113121
syslog('error', 'Error validating news message: %s', str(e))
114-
return False
122+
return msg, False
115123

116124
def _dispose(self, mlist, msg, msgdata):
117125
"""Post the message to the newsgroup."""
@@ -140,7 +148,8 @@ def _onefile(self, msg, msgdata):
140148
"""
141149
try:
142150
# Validate the message
143-
if not self._validate_message(msg, msgdata):
151+
msg, success = self._validate_message(msg, msgdata)
152+
if not success:
144153
syslog('error', 'NewsRunner._onefile: Message validation failed')
145154
self._shunt.enqueue(msg, msgdata)
146155
return

Mailman/Queue/OutgoingRunner.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,39 @@ def _convert_message(self, msg):
216216
return mailman_msg
217217
return msg
218218

219-
def _validate_message(self, msg):
220-
"""Validate the message before processing.
219+
def _validate_message(self, msg, msgdata):
220+
"""Validate the message for outgoing delivery.
221221
222-
This method is called before _dispose() to validate the message.
223-
Returns a tuple of (msg, success) where success is a boolean indicating
224-
if validation was successful.
222+
Args:
223+
msg: The message to validate
224+
msgdata: Additional message metadata
225+
226+
Returns:
227+
tuple: (msg, success) where success is a boolean indicating if validation was successful
225228
"""
226-
# No validation needed - this check was not in the original code
227-
return msg, True
229+
try:
230+
# Convert message if needed
231+
if not isinstance(msg, Message.Message):
232+
msg = self._convert_message(msg)
233+
234+
# Check required headers
235+
if not msg.get('message-id'):
236+
mailman_log('error', 'OutgoingRunner._validate_message: Message missing Message-ID header')
237+
return msg, False
238+
239+
if not msg.get('from'):
240+
mailman_log('error', 'OutgoingRunner._validate_message: Message missing From header')
241+
return msg, False
242+
243+
if not msg.get('to') and not msg.get('recipients'):
244+
mailman_log('error', 'OutgoingRunner._validate_message: Message missing To/Recipients')
245+
return msg, False
246+
247+
return msg, True
248+
249+
except Exception as e:
250+
mailman_log('error', 'OutgoingRunner._validate_message: Error validating message: %s', str(e))
251+
return msg, False
228252

229253
def _dispose(self, mlist, msg, msgdata):
230254
"""Process an outgoing message."""
@@ -268,7 +292,7 @@ def _dispose(self, mlist, msg, msgdata):
268292
return False
269293

270294
# Validate message type first
271-
msg, success = self._validate_message(msg)
295+
msg, success = self._validate_message(msg, msgdata)
272296
if not success:
273297
mailman_log('error', 'OutgoingRunner._dispose: Message validation failed for message %s', msgid)
274298
self._unmark_message_processed(msgid)

Mailman/Queue/RetryRunner.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,6 @@ def _oneloop(self):
323323
files = self._switchboard.files()
324324
filecnt = len(files)
325325

326-
# Only log at debug level if we found files to process
327-
if filecnt > 0:
328-
mailman_log('debug', 'RetryRunner._oneloop: Found %d files to process', filecnt)
329-
330326
# Process each file
331327
for filebase in files:
332328
try:
@@ -335,41 +331,38 @@ def _oneloop(self):
335331
if msg is None:
336332
continue
337333

338-
mailman_log('info', 'RetryRunner._oneloop: Successfully dequeued file %s', filebase)
339-
340-
# Process the message
341-
try:
342-
# Get the list name from the message data
343-
listname = msgdata.get('listname', mm_cfg.MAILMAN_SITE_LIST)
334+
# Get the list name from the message data
335+
listname = msgdata.get('listname')
336+
if not listname:
337+
syslog('error', 'RetryRunner._oneloop: No listname in message data for file %s', filebase)
338+
self._shunt.enqueue(msg, msgdata)
339+
continue
344340

345-
# Process the message
346-
result = self._dispose(listname, msg, msgdata)
341+
# Open the list
342+
try:
343+
mlist = self._open_list(listname)
344+
except Exception as e:
345+
self.log_error('list_open_error', str(e), listname=listname)
346+
self._shunt.enqueue(msg, msgdata)
347+
continue
347348

348-
# If the message should be kept in the queue, requeue it
349+
# Process the message
350+
try:
351+
result = self._dispose(mlist, msg, msgdata)
349352
if result:
350353
self._switchboard.enqueue(msg, msgdata)
351-
mailman_log('info', 'RetryRunner._oneloop: Message requeued for later processing: %s', filebase)
352-
else:
353-
mailman_log('info', 'RetryRunner._oneloop: Message processing complete, moving to shunt queue %s (msgid: %s)',
354-
filebase, msg.get('message-id', 'n/a'))
355-
356354
except Exception as e:
357-
mailman_log('error', 'RetryRunner._oneloop: Error processing message: %s\n%s',
358-
str(e), traceback.format_exc())
359-
# Move to shunt queue on error
360-
self._shunt.enqueue(msg, msgdata)
355+
self._handle_error(e, msg=msg, mlist=mlist)
361356

362357
except Exception as e:
363-
mailman_log('error', 'RetryRunner._oneloop: Error dequeuing file %s: %s\n%s',
364-
filebase, str(e), traceback.format_exc())
358+
syslog('error', 'RetryRunner._oneloop: Error dequeuing file %s: %s', filebase, str(e))
359+
continue
365360

366-
# Only log completion at debug level if we processed files
367-
if filecnt > 0:
368-
mailman_log('debug', 'RetryRunner._oneloop: Loop complete, processed %d files', filecnt)
369-
370361
except Exception as e:
371-
mailman_log('error', 'RetryRunner._oneloop: Unexpected error in main loop: %s\n%s',
372-
str(e), traceback.format_exc())
362+
syslog('error', 'RetryRunner._oneloop: Error in main loop: %s', str(e))
363+
return 0
364+
365+
return filecnt
373366

374367
def _snooze(self, filecnt):
375368
# We always want to snooze, but check for stop flag periodically

0 commit comments

Comments
 (0)