Home arrow Python arrow Page 4 - The PyMailGUI Client

Running PyMailGUI - Python

PyMailGUI is a Python program that sends, receives, composes, and parses Internet email messages. This article, the first of six parts, introduces the PyMailGUI client. It 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.

TABLE OF CONTENTS:
  1. The PyMailGUI Client
  2. Source Code Modules
  3. Why PyMailGUI?
  4. Running PyMailGUI
By: O'Reilly Media
Rating: starstarstarstarstar / 3
July 12, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Of course, to script PyMailGUI on your own, you’ll need to be able to run it. PyMailGUI requires only a computer with some sort of Internet connectivity (a PC with a broadband or dial-up account will do) and an installed Python with the Tkinter extension enabled. The Windows port of Python has this capability, so Windows PC users should be able to run this program immediately by clicking its icon.

Two notes on running the system: first, you’ll want to change the file mailconfig.py in the program’s source directory to reflect your account’s parameters, if you wish to send or receive mail from a live server; more on this as we interact with the system.

Second, you can still experiment with the system without a live Internet connection—for a quick look at message view windows, use the main window’s Open buttons to open saved-mail files stored in the program’s SavedMail directory. In fact, the PyDemos launcher script at the top of the book’s examples directory forces PyMailGUI to open saved-mail files by passing filenames on the command line.

Presentation Strategy

PyMailGUI is easily the largest program in this book, but it doesn’t introduce many library interfaces that we haven’t already seen in this book. For instance:

  1. The PyMailGUI interface is built with Python’s Tkinter, using the familiar list-boxes, buttons, and text widgets we met earlier.
  2. Python’semailpackage is applied to pull-out headers, text, and attachments of messages, and to compose the same.
  3. Python’s POP and SMTP library modules are used to fetch, send, and delete mail over sockets.
  4. Python threads, if installed in your Python interpreter, are put to work to avoid blocking during potentially overlapping, long-running mail operations.

We’re also going to reuse theTextEditorobject we wrote in Chapter 12 to view and compose messages, themailtools package’s tools we wrote in Chapter 14 to load and delete mail from the server, and themailconfigmodule strategy introduced in Chapter 14 to support end-user settings. PyMailGUI is largely an exercise in combining existing tools.

On the other hand, because this program is so long, we won’t exhaustively document all of its code. Instead, we’ll begin by describing how PyMailGUI works from an end user’s perspective—a brief demo of its windows in action. After that, we’ll list the system’s new source code modules without many additional comments, for further study.

Like most of the longer case studies in this book, this section assumes that you already know enough Python to make sense of the code on your own. If you’ve been reading this book linearly, you should also know enough about Tkinter, threads, and mail interfaces to understand the library tools applied here. If you get stuck, you may wish to brush up on the presentation of these topics earlier in the book.

New in This Edition

The 2.1 version of PyMailGUI presented in this third edition of the book is a complete rewrite of the 1.0 version of the prior edition. The main script in the second edition’s version was only some 500 lines long, and was really something of a toy or prototype, written mostly to serve as a book example. In this edition, PyMailGUI is a much more realistic and full-featured program that can be used for day-to-day email processing. It has grown to 2,200 source lines (3,800 including related modules that are reused). Among its new weapons are these:

  1. MIME multipart mails with attachments may be both viewed and composed.
  2. Mail transfers are no longer blocking, and may overlap in time.
  3. Mail may be saved and processed offline from a local file.
  4. Message parts may now be opened automatically within the GUI.
  5. Multiple messages may be selected for processing in list windows.
  6. Initial downloads fetch mail headers only; full mails are fetched on request.
  7. View window headers and list window columns are configurable.
  8. Deletions are performed immediately, not delayed until program exit.
  9. Most server transfers report their progress in the GUI.
  10. Long lines are intelligently wrapped in viewed and quoted text.
  11. Fonts and colors in list and view windows may be configured by the user.
  12. Authenticating SMTP mail-send servers that require login are supported.
  13. Sent messages are saved in a local file, which may be opened in the GUI.
  14. View windows intelligently pick a main text part to be displayed.
  15. Already fetched mail headers and full mails are cached for speed.
  16. Date strings and addresses in composed mails are formatted properly.
  17. View windows now have quick-access buttons for attachments/parts (2.1).
  18. Inbox out-of-sync errors are detected on deletes, and on index and mail loads (2.1).
  19. Save-mail file loads and deletes are threaded, to avoid pauses for large files (2.1).

The last three items on this list were added in version 2.1; the rest were part of the 2.0 rewrite. Some of these changes were made simple by growth in standard library tools (e.g., support for attachments is straightforward with the newemailpackage), but most represent changes in PyMailGUI itself. There have also been a few genuine fixes: addresses are parsed more accurately, and date and time formats in sent mails are now standards conforming, because these tasks use new tools in theemail package.

Although there is still room for improvement (see the list at the end of this chapter), the program provides a full-featured interface, represents the most substantial example in this book, and serves to demonstrate a realistic application of the Python language. As its users often attest, Python may be fun to work with, but it’s also useful for writing practical and nontrivial software.

Please check back next week for the continuation of this article.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- 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: