I was wondering how to get MIME message graph structure in Python (for example, as an adjacency matrix).
According to the official Python3 documentation there is an email.walk()
method that iterates through all message parts:
for part in email.walk():
print(part.get_content_type())
However the output does not show the hierarchical structure of a message. For example, the following output:
multipart/report
text/plain
message/delivery-status
text/plain
text/plain
message/rfc822
text/plain
It can represent any one of these two tree structures:
multipart/report
text/plain
message/rfc822
text/plain
text/plain
message/rfc822
text/plain
or
multipart/report
text/plain
message/rfc822
text/plain
text/plain
message/rfc822
text/plain
Is there any method in python that could help determine the exact hierarchical (graph) structure if an MIME message?