Deletions and POP Message Numbers
Note that you probably should click the “Back to root page” link in Figure 16-19 after
a successful deletion—don’t use your browser’s Back button to return to the message
selection list at this point because the delete has changed the relative numbers of some
messages in the list. The PyMailGUI client program worked around this problem by
automatically updating its in-memory message cache and refreshing the index list on
deletions, but PyMailCGI doesn’t currently have a way to mark older pages as obsolete.
If your browser reruns server-side scripts as you press your Back button, you’ll regen-
erate and hence refresh the list anyhow. If your browser displays cached pages as you
go back, though, you might see the deleted message still present in the list. Worse,
clicking on a view link in an old selection list page may not bring up the message you
think it should, if it appears in the list after a message that was deleted.
This is a property of POP email in general, which we have discussed before in this book:
incoming mail simply adds to the mail list with higher message numbers, but deletions
remove mail from arbitrary locations in the list and hence change message numbers for
all mail following the ones deleted.
Inbox synchronization error potential
As we saw in Chapter 14, even the PyMailGUI client has the potential to get some
message numbers wrong if mail is deleted by another program while the GUI is open—
in a second PyMailGUI instance, for example, or in a simultaneously running
PyMailCGI server session. This can also occur if the email server automatically deletes
a message after the mail list has been loaded—for instance, moving it from inbox to
undeliverable on errors.
This is why PyMailGUI went out of its way to detect server inbox synchronization errors
on loads and deletes, using mailtools package utilities. Its deletions, for instance, match
saved email headers with those for the corresponding message number in the server’s
inbox, to ensure accuracy. A similar test is performed on loads. On mismatches, the
mail index is automatically reloaded and updated. Unfortunately, without additional
state information, PyMailCGI cannot detect such errors: it has no email list to compare
against when messages are viewed or deleted, only the message number in a link or
hidden form field.
In the worst case, PyMailCGI cannot guarantee that deletes remove the intended mail—
it’s unlikely but not impossible that a mail earlier in the list may have been deleted
between the time message numbers were fetched and a mail is deleted at the server.
Without extra state information on the server, PyMailCGI cannot use the safe deletion
or synchronization error checks in the mailtools modules to check whether subject
message numbers are still valid.
To guarantee safe deletes, PyMailCGI would require state retention, which maps mes-
sage numbers passed in pages to saved mail headers fetched when the numbers were
1272 | Chapter 16: The PyMailCGI Server