Exemple #1
0
def parse():
    """
    Parse some e-mail to test mailtools package 'mailParse' module
    :return: None
    """
    # parsing e-mail
    # first fetch the e-mails

    fetcher = MailFetcherConsole()
    hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status)
    # load recent 2 e-mails
    last2 = len(hdrs)-2
    msgs, sizes, loadedall = fetcher.downloadAllMessages(status,
                                                         loadfrom=last2)
    for msg in msgs:
        print(msg[:200], '\n', '-'*70)

    parser = MailParser()

    for i in [0]:  # or [0, len(msgs)] for all messages
        fulltext = msgs[i]
        message = parser.parseMessage(fulltext)
        ctype, maintext = parser.findMainText(message)
        print('Parsed:', message['Subject'])
        print(maintext)
Exemple #2
0

def status(*args):
    print(args)


hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status)
for num, hdr in enumerate(hdrs):
    # print('header is:',hdr)
    if input('load mail?') in ['y', 'Y']:
        print(fetcher.downloadMessage(num + 1).rstrip(), '\n', '-' * 70)

totalmail = len(hdrs)
if totalmail < 5:
    last5 = 1
else:
    last5 = totalmail - 4

msgs, sizes, loadedall = fetcher.downloadAllMessages(status, loadfrom=last5)
# for msg in msgs:
# 	print(msg[:200], '\n', '-'*70)

parser = MailParser()
# print('\nparser messages, tottal messages is %d\n' % len(msgs))
for msg in msgs:
    fulltext = msg
    print('=' * 80, 'msg is:', fulltext, '=' * 80, sep='\n')
    message = parser.parseMessage(fulltext)
    ctype, maintext = parser.findMainText(message)
    print('Parsed:', message['Subject'])
    print(maintext)
Exemple #3
0
    sender = MailSenderAuthConsole()

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'])

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]:
    fulltext = msgs[i]
    message = parser.parseMessage(fulltext)
    ctype, maintext = parser.findMainText(message)
    print('Parsed:', message['Subject'])
    print(maintext)
input('Enter to exit')