if input('load mail?') in ['y', 'Y']:
print(fetcher.downloadMessage(num+1).rstrip(), '\n', '-'*70)
last5 = len(hdrs)-4
msgs, sizes, loadedall = fetcher.downloadAllMessages(status, loadfrom=last5)
for msg in msgs:
print(msg[:200], '\n', '-'*70)
parser = MailParser()
for i in [0]: # try [0 , len(msgs)]
fulltext = msgs[i]
message = parser.parseMessage(fulltext)
ctype, maintext = parser.findMainText(message)
print('Parsed:', message['Subject'])
print(maintext)
input('Press Enter to exit') # pause if clicked on Windows
Running the self-test
Here’s a run of the self-test script; it generates a lot of output, most of which has been
deleted here for presentation in this book—as usual, run this on your own for further
details:
C:\...\PP4E\Internet\Email\mailtools> selftest.py
config: ..\mailconfig.py
user: [email protected]
Adding text/x-python
Sending to...['[email protected]']
Content-Type: multipart/mixed; boundary="===============0085314748=="
MIME-Version: 1.0
From: [email protected]
To: [email protected]
Subject: testing mailtools package
Date: Sat, 08 May 2010 19:26:22 −0000
X-Mailer: mailtools
A multi-part MIME format message.
--===============0085314748==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Here is my source code
--===============0085314748==
Content-Type: text/x-python; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="selftest.py"
"""
###############################################################################
self-test when this file is run as a program
###############################################################################
984 | Chapter 13: Client-Side Scripting