This version of PyMailCGI has its own local copy of the mailconfig module we coded
in Chapter 13 and expanded in Chapter 14, but it simply loads all attributes from the
version we wrote in Chapter 13 to avoid redundancy, and customizes as desired; the
local version is listed in Example 16-11.
Example 16-11. PP4E\Internet\Email\PyMailCgi\cgi-bin\mailconfig.py
"""
user configuration settings for various email programs (PyMailCGI version);
email scripts get their server names and other email config options from
this module: change me to reflect your machine names, sig, and preferences;
"""
from PP4E.Internet.Email.mailconfig import * # reuse ch13 configs
fetchlimit = 50 # 4E: maximum number headers/emails to fetch on loads (dflt=25)
POP Mail Interface
Our next utility module, the loadmail file in Example 16-12, depends on external files
and encapsulates access to mail on the remote POP server machine. It currently exports
one function, loadmailhdrs, which returns a list of the header text (only) of all mail in
the specified POP account; callers are unaware of whether this mail is fetched over the
Net, lives in memory, or is loaded from a persistent storage medium on the CGI server
machine. That is by design—because loadmail changes won’t impact its clients, it is
mostly a hook for future expansion.
Example 16-12. PP4E\Internet\Web\PyMailCgi\cgi-bin\loadmail.py
"""
mail list loader; future--change me to save mail list between CGI script runs,
to avoid reloading all mail each time; this won't impact clients that use the
interfaces here if done well; for now, to keep this simple, reloads all mail
for each list page; 2.0+: we now only load message headers (via TOP), not full
msg, but still fetch all hdrs for each index list--in-memory caches don't work
in a stateless CGI script, and require a real (likely server-side) database;
"""
from commonhtml import runsilent # suppress prints (no verbose flag)
from externs import mailtools # shared with PyMailGUI
load all mail from number 1 up
this may trigger an exception
import sys
def progress(*args): # not used
sys.stderr.write(str(args) + '\n')
def loadmailhdrs(mailserver, mailuser, mailpswd):
fetcher = mailtools.SilentMailFetcher(mailserver, mailuser, mailpswd)
hdrs, sizes, full = fetcher.downloadAllHeaders() # get list of hdr text
return hdrs
Utility Modules | 1277