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 ยท -- https://mail.python.org/mailman/listinfo/python-list