Skip to content

Commit ddb1bcc

Browse files
committed
update
1 parent 275c324 commit ddb1bcc

1 file changed

Lines changed: 34 additions & 33 deletions

File tree

Mailman/Queue/IncomingRunner.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,55 +148,56 @@ def __init__(self, slice=None, numslices=1):
148148
str(e), traceback.format_exc())
149149
raise
150150

151+
def _convert_message(self, msg):
152+
"""Convert email.message.Message to Mailman.Message with proper handling of nested messages."""
153+
if isinstance(msg, email.message.Message):
154+
mailman_msg = Message()
155+
for key, value in msg.items():
156+
mailman_msg[key] = value
157+
if msg.is_multipart():
158+
for part in msg.get_payload():
159+
mailman_msg.attach(self._convert_message(part))
160+
else:
161+
mailman_msg.set_payload(msg.get_payload())
162+
return mailman_msg
163+
return msg
164+
151165
def _dispose(self, mlist, msg, msgdata):
152166
"""Process an incoming message."""
153167
msgid = msg.get('message-id', 'n/a')
154168
filebase = msgdata.get('_filebase', 'unknown')
155169

156-
# Ensure we have a MailList object
157-
if isinstance(mlist, str):
158-
try:
159-
mlist = MailList.MailList(mlist, lock=0)
160-
should_unlock = True
161-
except Errors.MMUnknownListError:
162-
mailman_log('error', 'IncomingRunner: Unknown list %s', mlist)
163-
self._shunt.enqueue(msg, msgdata)
164-
return True
165-
else:
166-
should_unlock = False
167-
168170
try:
169-
# Try to get the list lock with timeout
170-
try:
171-
mlist.Lock(timeout=mm_cfg.LIST_LOCK_TIMEOUT)
172-
except LockFile.TimeOutError:
173-
mailman_log('error', 'IncomingRunner: List lock timeout for %s', mlist.internal_name())
174-
return True # Try again later
171+
mailman_log('debug', 'IncomingRunner._dispose: Starting to process incoming message %s (file: %s)',
172+
msgid, filebase)
175173

176-
mailman_log('debug', 'IncomingRunner._dispose: Starting to process incoming message %s (file: %s) for list %s',
177-
msgid, filebase, mlist.internal_name())
174+
# Convert Python's Message to Mailman's Message if needed
175+
msg = self._convert_message(msg)
178176

179-
# Get the pipeline for processing
177+
# Get the pipeline
180178
pipeline = self._get_pipeline(mlist, msg, msgdata)
181-
msgdata['pipeline'] = pipeline
179+
if not pipeline:
180+
mailman_log('error', 'IncomingRunner._dispose: No pipeline found for message %s', msgid)
181+
return False
182182

183-
# Process through pipeline
184-
more = self._dopipeline(mlist, msg, msgdata, pipeline)
185-
186-
if not more:
187-
del msgdata['pipeline']
183+
# Process the message through the pipeline
184+
try:
185+
more = self._dopipeline(mlist, msg, msgdata, pipeline)
186+
if more:
187+
mailman_log('debug', 'IncomingRunner._dispose: Message %s needs more processing', msgid)
188+
return True
189+
except Exception as e:
190+
mailman_log('error', 'IncomingRunner._dispose: Error processing message %s: %s\nTraceback:\n%s',
191+
msgid, str(e), traceback.format_exc())
192+
return False
188193

189-
mlist.Save()
190-
return more
194+
mailman_log('debug', 'IncomingRunner._dispose: Successfully processed message %s', msgid)
195+
return True
191196

192197
except Exception as e:
193198
mailman_log('error', 'IncomingRunner._dispose: Error processing message %s: %s\nTraceback:\n%s',
194199
msgid, str(e), traceback.format_exc())
195-
self._unmark_message_processed(msgid)
196200
return False
197-
finally:
198-
if should_unlock:
199-
mlist.Unlock()
200201

201202
def _get_pipeline(self, mlist, msg, msgdata):
202203
"""Get the pipeline for processing the message."""

0 commit comments

Comments
 (0)