Skip to content

Commit 5e67c01

Browse files
committed
update
1 parent 3e8ccf5 commit 5e67c01

1 file changed

Lines changed: 64 additions & 1 deletion

File tree

Mailman/Queue/Switchboard.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,25 @@ def _enqueue(self, filename, msg, msgdata, _plaintext):
455455
dirname, os.path.abspath(dirname), str(e), traceback.format_exc())
456456
raise
457457

458+
# Convert message to Mailman.Message if needed
459+
if isinstance(msg, email.message.Message) and not isinstance(msg, Message):
460+
mailman_msg = Message()
461+
# Copy all attributes from the original message
462+
for key, value in msg.items():
463+
mailman_msg[key] = value
464+
# Copy the payload with proper MIME handling
465+
if msg.is_multipart():
466+
for part in msg.get_payload():
467+
if isinstance(part, email.message.Message):
468+
mailman_msg.attach(part)
469+
else:
470+
newpart = Message()
471+
newpart.set_payload(part)
472+
mailman_msg.attach(newpart)
473+
else:
474+
mailman_msg.set_payload(msg.get_payload())
475+
msg = mailman_msg
476+
458477
# Write to temporary file first
459478
try:
460479
with open(tmpfile, 'wb') as fp:
@@ -473,6 +492,9 @@ def _enqueue(self, filename, msg, msgdata, _plaintext):
473492
test_data = pickle.load(fp, fix_imports=True, encoding='latin1')
474493
if not isinstance(test_data, tuple) or len(test_data) != 2:
475494
raise TypeError('Loaded data is not a valid tuple')
495+
# Verify message type
496+
if not isinstance(test_data[0], Message):
497+
raise TypeError('Message is not a Mailman.Message instance')
476498
except Exception as e:
477499
mailman_log('error', 'Validation of temporary file failed: %s\nTraceback:\n%s',
478500
str(e), traceback.format_exc())
@@ -531,14 +553,55 @@ def _dequeue(self, filename):
531553
if not isinstance(data, tuple) or len(data) != 2:
532554
raise TypeError('Invalid data format in queue file')
533555
msgsave, metadata = data
556+
557+
# Ensure we have a Mailman.Message
558+
if isinstance(msgsave, email.message.Message) and not isinstance(msgsave, Message):
559+
mailman_msg = Message()
560+
# Copy all attributes from the original message
561+
for key, value in msgsave.items():
562+
mailman_msg[key] = value
563+
# Copy the payload with proper MIME handling
564+
if msgsave.is_multipart():
565+
for part in msgsave.get_payload():
566+
if isinstance(part, email.message.Message):
567+
mailman_msg.attach(part)
568+
else:
569+
newpart = Message()
570+
newpart.set_payload(part)
571+
mailman_msg.attach(newpart)
572+
else:
573+
mailman_msg.set_payload(msgsave.get_payload())
574+
msgsave = mailman_msg
575+
576+
return msgsave, metadata
534577
except (UnicodeDecodeError, pickle.UnpicklingError):
535578
# Fall back to latin1 for older files
536579
fp.seek(0)
537580
data = pickle.load(fp, fix_imports=True, encoding='latin1')
538581
if not isinstance(data, tuple) or len(data) != 2:
539582
raise TypeError('Invalid data format in queue file')
540583
msgsave, metadata = data
541-
return msgsave, metadata
584+
585+
# Ensure we have a Mailman.Message
586+
if isinstance(msgsave, email.message.Message) and not isinstance(msgsave, Message):
587+
mailman_msg = Message()
588+
# Copy all attributes from the original message
589+
for key, value in msgsave.items():
590+
mailman_msg[key] = value
591+
# Copy the payload with proper MIME handling
592+
if msgsave.is_multipart():
593+
for part in msgsave.get_payload():
594+
if isinstance(part, email.message.Message):
595+
mailman_msg.attach(part)
596+
else:
597+
newpart = Message()
598+
newpart.set_payload(part)
599+
mailman_msg.attach(newpart)
600+
else:
601+
mailman_msg.set_payload(msgsave.get_payload())
602+
msgsave = mailman_msg
603+
604+
return msgsave, metadata
542605
except (IOError, OSError) as e:
543606
mailman_log('error', 'Error dequeuing message from %s: %s', filename, str(e))
544607
return None, None

0 commit comments

Comments
 (0)