be the only one deleted. A working but tentative implementation of this scheme is
implemented in the following directory of the book’s examples distribution:
PP4E\Internet\Web\dev\PyMailCGI_2.1
When developed, it worked under the Firefox web browser and it requires just more
than 10 lines of code changes among three source files, listed here (search for
“#EXPERIMENTAL” to find the changes made in the source files yourself):
# onViewListLink.py
...
hdrstext = fulltext.split('\n\n')[0] # use blank line
commonhtml.viewpage( # encodes passwd
msgnum, message, content, form, hdrstext, parts)
# commonhtml.py
...
def viewpage(msgnum, headers, text, form, hdrstext, parts=[]):
...
delete needs hdrs text for inbox sync tests: can be multi-K large
hdrstext = cgi.escape(hdrstext, quote=True) # escape '"' too
print('' % hdrstext)
# onViewPageAction.py
...
fetcher = mailtools.SilentMailFetcher(site, user, pswd)
#fetcher.deleteMessages([msgnum])
hdrstext = getfield(form, 'Hdrstext') + '\n'
hdrstext = hdrstext.replace('\r\n', '\n') # get \n from top
dummyhdrslist = [None] * msgnum # only one msg hdr
dummyhdrslist[msgnum-1] = hdrstext # in hidden field
fetcher.deleteMessagesSafely([msgnum], dummyhdrslist) # exc on sync err
commonhtml.confirmationpage('Delete')
To run this version locally, run the webserver script from Example 15-1 (in Chap-
ter 15) with the dev subdirectory name, and a unique port number if you want to run
both the original and the experimental versions. For instance:
C:\...\PP4E\Internet\Web> webserver.py dev\PyMailCGI_2.1 9000 command line
http://localhost:9000/pymailcgi.html web browser URL
Although this version works on browsers tested, it is considered tentative (and was not
used for this chapter, and not updated for Python 3.X in this edition) because it is an
incomplete solution. In those rare cases where the server’s inbox changes in ways that
invalidate message numbers after server fetches, this version avoids inaccurate dele-
tions, but index lists may still become out of sync. Messages fetches may still be inac-
curate, and addressing this likely entails more sophisticated state retention options.
Note that in most cases, the message-id header would be sufficient for matching against
mails to be deleted in the inbox, and it might be all that is required to pass from page
to page. However, because this field is optional and can be forged to have any value,
this might not always be a reliable way to identify matched messages; full header
1274 | Chapter 16: The PyMailCGI Server