Esempio n. 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)
Esempio n. 2
0
def fetch():
    """
    Fetches some e-mail to test mailtools package 'mailFetcher' module
    :return: None
    """

    # Fetch an e-mail
    fetcher = MailFetcherConsole()

    hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status)

    # load header
    for num, hdr in enumerate(hdrs[:2]):
        print(hdr)

        # if requested then e-mail.
        if input('load mail?') in ['y', 'Y']:
            print(fetcher.downloadMessage(num + 1).rstrip(), '\n', '-' * 70)
Esempio n. 3
0
sender.sendMessage(From=mailconfig.myaddress,
                   To=[mailconfig.recevieaddr],
                   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):
    # 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)
Esempio n. 4
0
if not mailconfig.smtpuser:
    sender = MailSender(tracesize=5000)
else:
    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)