File: pyedit-products/unzipped/PP4E/Internet/Email/mailtools/sentmail.txt
================================================================================PY
Content-Type: multipart/mixed; boundary="===============1879158757=="
MIME-Version: 1.0
From: PP4E@learning-python.com
To: PP4E@learning-python.com
Subject: testing mailtools package
Date: Sun, 30 May 2010 17:55:25 -0000
X-Mailer: mailtools
A multi-part MIME format message.
--===============1879158757==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Here is my source code
--===============1879158757==
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
###############################################################################
"""
#
# mailconfig normally comes from the client's source directory or
# sys.path; for testing, get it from Email directory one level up
#
import sys
sys.path.append('..')
import mailconfig
print('config:', mailconfig.__file__)
# get these from __init__
from mailtools import (MailFetcherConsole,
MailSender, MailSenderAuthConsole,
MailParser)
if not mailconfig.smtpuser:
sender = MailSender(tracesize=5000)
else:
sender = MailSenderAuthConsole(tracesize=5000)
sender.sendMessage(From = mailconfig.myaddress,
To = [mailconfig.myaddress],
Subj = 'testing mailtools package',
extrahdrs = [('X-Mailer', 'mailtools')],
bodytext = 'Here is my source code\n',
attaches = ['selftest.py'],
)
# bodytextEncoding='utf-8', # other tests to try
# attachesEncodings=['latin-1'], # inspect text headers
# attaches=['monkeys.jpg']) # verify Base64 encoded
# to='i18n adddr list...', # test mime/unicode headers
# change mailconfig to test fetchlimit
fetcher = MailFetcherConsole()
def status(*args): print(args)
hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status)
for num, hdr in enumerate(hdrs[:5]):
print(hdr)
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
--===============1879158757==--
================================================================================PY
Content-Type: multipart/mixed; boundary="===============0283582533=="
MIME-Version: 1.0
From: PP4E@learning-python.com
To: PP4E@learning-python.com
Subject: testing mailtools package
Date: Wed, 02 Jun 2010 19:14:37 -0000
X-Mailer: mailtools
A multi-part MIME format message.
--===============0283582533==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Here is my source code
--===============0283582533==
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
###############################################################################
"""
#
# mailconfig normally comes from the client's source directory or
# sys.path; for testing, get it from Email directory one level up
#
import sys
sys.path.append('..')
import mailconfig
print('config:', mailconfig.__file__)
# get these from __init__
from mailtools import (MailFetcherConsole,
MailSender, MailSenderAuthConsole,
MailParser)
if not mailconfig.smtpuser:
sender = MailSender(tracesize=5000)
else:
sender = MailSenderAuthConsole(tracesize=5000)
sender.sendMessage(From = mailconfig.myaddress,
To = [mailconfig.myaddress],
Subj = 'testing mailtools package',
extrahdrs = [('X-Mailer', 'mailtools')],
bodytext = 'Here is my source code\n',
attaches = ['selftest.py'],
)
# bodytextEncoding='utf-8', # other tests to try
# attachesEncodings=['latin-1'], # inspect text headers
# attaches=['monkeys.jpg']) # verify Base64 encoded
# to='i18n adddr list...', # test mime/unicode headers
# change mailconfig to test fetchlimit
fetcher = MailFetcherConsole()
def status(*args): print(args)
hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status)
for num, hdr in enumerate(hdrs[:5]):
print(hdr)
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
--===============0283582533==--