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': mailconfig.myaddress, # 3.0: commonhtml decodes
'To': getfield(form, 'From'),
'Cc': mailconfig.myaddress,
'Subject': 'Re: ' + getfield(form, 'Subject')}
commonhtml.editpage('Reply', headers, quotetext(form))
elif form['action'].value == 'Forward':
headers = {'From': mailconfig.myaddress, # 3.0: commonhtml decodes
'To': '',
'Cc': mailconfig.myaddress,
'Subject': 'Fwd: ' + getfield(form, 'Subject')}
commonhtml.editpage('Forward', headers, quotetext(form))
elif form['action'].value == 'Delete': # mnum field is required here
msgnum = int(form['mnum'].value) # but not eval(): may be code
fetcher = mailtools.SilentMailFetcher(site, user, pswd)
fetcher.deleteMessages([msgnum])
commonhtml.confirmationpage('Delete')
else:
assert False, 'Invalid view action requested'
except:
commonhtml.errorpage('Cannot process view action')
This script receives all information about the selected message as form input field data
(some hidden and possibly encrypted, some not) along with the selected action’s name.
The next step in the interaction depends upon the action selected:
Reply and Forward actions
Generate a message edit page with the original message’s lines automatically quo-
ted with a leading >.
Delete actions
Trigger immediate deletion of the email being viewed, using a tool imported from
the mailtools module package from Chapter 13.
All these actions use data passed in from the prior page’s form, but only the Delete
action cares about the POP username and password and must decode the password
received (it arrives here from hidden form input fields generated in the prior page’s
HTML).
Reply and Forward
If you select Reply as the next action, the message edit page in Figure 16-16 is generated
by the script. Text on this page is editable, and pressing this page’s Send button again
triggers the send mail script we saw in Example 16-4. If all goes well, we’ll receive the
Processing Fetched Mail| 1267