Mark,

That's where this gets a little odd.

On 2026-06-23 23:32, Mark Sapiro wrote:
On 6/23/26 9:29 AM, Thomas Ward via Mailman-Developers wrote:
In debugging and diagnosing issues with an archiver I wrote for a client of mine, I need to see the message as it's seen by Mailman, in its own Message class.  However, I only have the *base* email message in .eml format. While I know it's derived from the standard email.message.Message class, is there a function that I can do that will 'load' that existing email message into a mailman.emaiil.Message object so I can do some work on it and properly look at the object I'm working with in the archiver?

Pleasae be more specific as to what you are doing to get the message to be archived.
The 'message' in question is processed by an archiver class that is already written. However, to debug an issue we were encountering, I wanted to see the object as it was a Message object as internally the archiver process sees it.

What I wanted to do was see the object *exactly* as Mailman3 sees it internally.

If as I suspect, you are getting messages to be archived by subscribing your archiver to the list, you could convert that to a mailman.email.message.Message object with something like
```
import sys
import email

sys.path.insert('/path/to/mailman')
from mailman.email.message import Message
# If the message is in a file
with open('path/to/file', 'rb') as fp:
    msg = email.message_from_binary_file(fp, Message)
# Or if the message is piped in
msg = email.message_from_string(sys.stdin, Message)
```
but this won't be the same as Mailman's Message object because of additional headers added by MTAs and transformations done by Mailman's out runner.

Yeah, that's what I was wondering and was looking to convert an existing email file (.eml) to the Message object that reflects the object as the archiver class / plugin I already rote sees it.

In lieu of this as it won't be the same due to transformations and items added by the MTA, I did a slightly different approach in the custom archiver class (which has to preprocess the message into a specific format for the home-grown environment's expected formats for it to populate into that archive). During the process, I take the message as it is from the Message class and wrap it into an email.message.EmailMessage with email.message_from_bytes(MessageObject.as_bytes(), policy=email.policy.default).  From there, it was easy to simply manipulate the data as a traditional Python EmailMessage class (which has extra functions beyond the base Message class which it seems is preferred by Python upstream for message manipulation compared to the traditional Message class) which lets us iterate over all parts of the message and properly process attachments in the way that this home-grown archiver that the custom archiver class hands the data off to can parse.

Non-trivial by any nature, but at least I have a workaround and thus a workable EmailMessage object.



Thomas
_______________________________________________
Mailman-Developers mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/mailman-developers.python.org/
Mailman FAQ: https://wiki.list.org/x/AgA3

Security Policy: https://wiki.list.org/x/QIA9

Reply via email to