Home arrow Python arrow Page 2 - Deleting Email and More with the PyMailGUI Client

POP Message Numbers and Synchronization - Python

Continuing our tour through PyMailGUI, this week we show you how to delete email, explain POP message numbers and synchronization, and finally begin talking about the code. This article, the fourth of six parts, is excerpted from chapter 15 of the book Programming Python, Third Edition, written by Mark Lutz (O'Reilly, 2006; ISBN: 0596009259). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

  1. Deleting Email and More with the PyMailGUI Client
  2. POP Message Numbers and Synchronization
  3. Multiple Windows and Status Messages
  4. PyMailGUI Implementation
By: O'Reilly Media
Rating: starstarstarstarstar / 1
August 02, 2007

print this article



Deletions are complicated by POP’s message-numbering scheme. We learned about the potential for synchronization errors between the server’s inbox and the fetched email list in Chapter 14, when studying the mailtools package PyMailGUI uses (near Example 14-21). In brief, POP assigns each message a relative sequential number, starting from one, and these numbers are passed to the server to fetch and delete messages. The server’s inbox is normally locked while a connection is held so that a series of deletions can be run as an atomic operation; no other inbox changes occur until the connection is closed.

However, message number changes also have some implications for the GUI itself. It’s all right if new mail arrives while we’re displaying the result of a prior download—the new mail is assigned higher numbers, beyond what is displayed on the client. But if we delete a message in the middle of a mailbox after the index has been loaded from the mail server, the numbers of all messages after the one deleted change (they are decremented by one). As a result, some message numbers might no longer be valid if deletions are made while viewing previously loaded email.

To work around this, PyMailGUI adjusts all the displayed numbers after a Delete by simply removing the entries for deleted mails from its index list and mail cache. However, this adjustment is not enough to keep the GUI in sync with the server’s inbox if the inbox is modified at a time other than after the end, by deletions in another email client (even in another PyMailGUI session) or by deletions performed by the mail server itself (e.g., messages determined to be undeliverable and automatically removed from the inbox).

To handle these cases, PyMailGUI uses the safe deletion and synchronization tests inmailtools. That module uses mail header matching to detect mail list and server inbox synchronization errors. For instance, if another email client has deleted a message prior to the one to be deleted by PyMailGUI,mailtoolscatches the problem and cancels the deletion, and an error popup like the one in Figure 15-34 is displayed.

Figure 15-34.  Safe deletion test detection of inbox difference

Similarly, index loads and message fetches run a synchronization test inmailtools, as well. Figure 15-35 captures the error generated if a message has been deleted in another client since we last loaded the server index window.

Figure 15-35.  Synchronization error on after delete in another client

In both error cases, the inbox is automatically reloaded by PyMailGUI immediately after the error popup is dismissed. This scheme ensures that PyMailGUI won’t delete or display the wrong message, in the rare case that the server’s inbox is changed without its knowledge. Seemailtoolsin Chapter 14 for more on synchronization tests.

>>> More Python Articles          >>> More By O'Reilly Media

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: