[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

matching is necessary to be robust. See the discussion of mailtools in Chapter 13 for
more details.


Alternative: Server-side files for headers


The main limitation of the prior section’s technique is that it addressed only deletions
of already fetched emails. To catch other kinds of inbox synchronization errors, we
would have to also record headers fetched when the index list page was constructed.


Since the index list page uses URL query parameters to record state, adding large header
texts as an additional parameter on the URLs is not likely a viable option. In principle,
the header text of all mails in the list could be embedded in the index page as a single
hidden field, but this might add prohibitive size and transmission overheads.


As a perhaps more complete approach, each time the mail index list page is generated
in onViewPswdSubmit.py, fetched headers of all messages could be saved in a flat file on
the server, with a generated unique name (possibly from time, process ID, and user-
name). That file’s name could be passed along with message numbers in pages as an
extra hidden field or query parameter.


On deletions, the header’s filename could be used by onViewPageAction.py to load the
saved headers from the flat file, to be passed to the safe delete call in mailtools. On
fetches, the header file could also be used for general synchronization tests to avoid
loading and displaying the wrong mail. Some sort of aging scheme would be required
to delete the header save files eventually (the index page script might clean up old files),
and we might also have to consider multiuser issues.


This scheme essentially uses server-side files to emulate PyMailGUI’s in-process mem-
ory, though it is complicated by the fact that users may back up in their browser—
deleting from view pages fetched with earlier list pages, attempting to refetch from an
earlier list page and so on. In general, it may be necessary to analyze all possible forward
and backward flows through pages (it is essentially a state machine). Header save files
might also be used to detect synchronization errors on fetches and may be removed on
deletions to effectively disable actions in prior page states, though header matching
may suffice to ensure deletion accuracy.


Alternative: Delete on load


As a final alternative, mail clients could delete all email off the server as soon as it is
downloaded, such that deletions wouldn’t impact POP identifiers (Microsoft Outlook
may use this scheme by default, for instance). However, this requires additional mech-
anisms for storing deleted email persistently for later access, and it means you can view
fetched mail only on the machine to which it was downloaded. Since both PyMailGUI
and PyMailCGI are intended to be used on a variety of machines, mail is kept on the
POP server by default.


Processing Fetched Mail| 1275
Free download pdf