Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why is there no get_body() in mailbox.Maildir?

14 views
Skip to first unread message

Chris Green

unread,
Nov 28, 2021, 9:33:22 AM11/28/21
to
I have the following error:-

chris@esprimo$ ./showmail.py boating/Odin/moorings/angers "01 Oct 2009 18:03:00"
Traceback (most recent call last):
File "/home/chris/dev/cgi-bin/./showmail.py", line 24, in <module>
print(msg.get_body('plain',))
AttributeError: 'MaildirMessage' object has no attribute 'get_body'


It's being returned by the following (rather trivial) Python program:-

#!/usr/bin/python3
#
#
# replacement for complex Zend/PHP E-Mail message extraction
#
import mailbox
import email
import sys
import os

mbroot = "/home/chris/mail/folder"

mbname = os.path.join(mbroot, sys.argv[1])

mb = mailbox.Maildir(mbname)
#
#
# run through the messages in the mailbox looking for date/time match
#
for msg in mb:
# print(msg.get("Subject"))
# print(msg.get("Date"))
if sys.argv[2] in msg.get("Date"):
print(msg.get_body('plain',))
exit(0)
exit(1)

I thought MaildirMessage inherited from email.message, it has inherited the
get() method so why not the get_body() method? I'm running Python 3.9.7
on xubuntu Linux 21.10.

Is there another way of doing this or do I have to sort through the message
parts and stuff? It sounded like get_body() would make things easier.


--
Chris Green
·

Chris Green

unread,
Nov 28, 2021, 12:03:23 PM11/28/21
to
Stefan Ram <r...@zedat.fu-berlin.de> wrote:
> Chris Green <c...@isbd.net> writes:
> >I thought MaildirMessage inherited from email.message,
>
> It inherits from mailbox.Message which inherits from
> email.message.Message which has no "get_body" method.
>
So the documentation at:-
https://docs.python.org/3/library/email.message.html

is very confusing then. It has a get_body method listed in the
email.message.EmailMessage class.

Where is email.message.Message documented?


> email.message.MIMEPart has a get_body method.
>
> Also check out: get_payload.
>
>
--
Chris Green
·
0 new messages