O'Reilly logo

Programming Python, 3rd Edition by Mark Lutz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Processing Fetched Mail

At this point in our PyMailCGI web interaction, we are viewing an email message (Figure 17-12) that was chosen from the selection list page. On the message view page, selecting an action from the pull-down list and clicking the Next button invokes the script in Example 17-9 on the server to perform a reply, forward, or delete operation for the selected message.

Example 17-9. PP3E\Internet\Web\PyMailCgi\cgi-bin\onViewPageAction.py

#!/usr/bin/python ####################################################################### # On submit in mail view window, action selected=(fwd, reply, delete) # in 2.0, we reuse the mailtools delete logic orig coded for PyMailGUI ####################################################################### import cgi, commonhtml, secret from externs import mailtools, mailconfig from commonhtml import getfield def quotetext(form): """ note that headers come from the prior page's form here, not from parsing the mail message again; that means that commonhtml.viewpage must pass along date as a hidden field """ quoted = '\n-----Original Message-----\n' for hdr in ('From', 'To', 'Date'): quoted = quoted + '%s: %s\n' % (hdr, getfield(form, hdr)) quoted = quoted + '\n' + getfield(form, 'text') quoted = '\n' + quoted.replace('\n', '\n> ') return quoted form = cgi.FieldStorage( ) # parse form or URL data user, pswd, site = commonhtml.getstandardpopfields(form) pswd = secret.decode(pswd) try: if form['action'].value == 'Reply': headers = {'From': ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required