Section 17.3. The Root Page


17.3. The Root Page

Let's start off by implementing a main page for this example. The file shown in Example 17-2 is primarily used to publish links to the Send and View functions' pages. It is coded as a static HTML file, because there is nothing to generate on the fly here.

Example 17-2. PP3E\Internet\Web\PyMailCgi\pymailcgi.html

 <HTML> <TITLE>PyMailCGI Main Page</TITLE> <BODY> <H1 align=center>PyMailCGI</H1> <H2 align=center>A POP/SMTP Web Email Interface</H2> <P align=center><I>Version 2.0, January 2006</I></P> <table> <tr><td><hr> <h2>Actions</h2> <P> <UL> <LI><a href="cgi-bin/onRootViewLink.py">View, Reply, Forward, Delete POP mail</a> <LI><a href="cgi-bin/onRootSendLink.py">Send a new email message by SMTP</a> </UL></P> <tr><td><hr> <h2>Overview</h2> <P> <A href="http://rmi.net/~lutz/about-pp.html"> <IMG src="/books/2/726/1/html/2/ppsmall.gif" align=left alt="[Book Cover]" border=1 hspace=10></A> This site implements a simple web-browser interface to POP/SMTP email accounts.  Anyone can send email with this interface, but for security reasons, you cannot view email unless you install the scripts with your own email account information, in your own server account directory. PyMailCgi is implemented as a number of Python-coded CGI scripts that run on a server machine (not your local computer), and generate HTML to interact with the client/browser.  See the book <I>Programming Python, 3rd Edition</I> for more details.</P> <tr><td><hr> <h2>Notes</h2> <P>Caveats: PyMailCgi 1.0 was initially written during a 2-hour layover at Chicago's O'Hare airport.  This release is not nearly as fast or complete as PyMailGUI (e.g., each click requires an Internet transaction, there is no save operation or multithreading, and there is no caching of email headers or already-viewed messages).  On the other hand, PyMailCgi runs on any web broswer, whether you have Python (and Tk) installed on your machine or not. <P>Also note that if you use these scripts to read your own email, PyMailCgi does not guarantee security for your account password. See the notes in the View action page as well as the book for more information on security policies. <p><I><U>New in Version 2</U></I>: PyMailCGI now supports viewing and sending Email attachments for a single user, and avoids some of the prior version's exhaustive mail downloads. It only fetches message headers for the list page, and only downloads the full text of the single message selected for viewing. <p>Also see: <UL> <li>The <I>PyMailGUI</I> program in the Internet directory, which         implements a more complete client-side Python+Tk email GUI <li>The <I>pymail.py</I> program in the Email directory, which         provides a simple console command-line email interface <li>The Python imaplib module which supports the IMAP email protocol         instead of POP </UL></P> </table><hr> <A href="http://www.python.org"> <IMG src="/books/2/726/1/html/2/PythonPoweredSmall.gif" ALIGN=left ALT="[Python Logo]" border=0 hspace=15></A> <A href="http://www.rmi.net/~lutz/about-pp.html">[Book]</a> <A href="http://www.oreilly.com">[O'Reilly]</a> </BODY></HTML> 

The file pymailcgi.html is the system's root page and lives in a PyMailCgi subdirectory dedicated to this application (and helps keep its files separate from other examples). To access this system, start your locally running web server described earlier in this chapter and point your browser to the following URL (or do the right thing for whatever other web server you may be using):

 http://localhost:8000/pymailcgi.html 

If you do, the server will ship back a page such as that shown in Figure 17-2, shown rendered in the open source Firefox web browser client.

Figure 17-2. PyMailCGI main page


17.3.1. Configuring PyMailCGI

Now, before you click on the "View . . . " link in Figure 17-2, expecting to read your own email, I should point out that by default, PyMailCGI allows anybody to send email from this page with the Send link (as we learned earlier, there are no passwords in SMTP). It does not, however, allow arbitrary users on the Web to read their email accounts without typing an explicit and unsafe URL or doing a bit of installation and configuration.

This is on purpose, and it has to do with security constraints; as we'll see later, PyMailCGI is written such that it never associates your email username and password together without encryption. This isn't an issue if your web server is running locally, of course, but this policy is in place in case you ever run this system remotely across the Web.

By default, then, this page is set up to read the email account shown in this bookaddress pp3e@earthlink.netand requires that account's POP password to do so. Since you probably can't guess the password (and wouldn't find its email helpful if you could), PyMailCGI is not incredibly useful as shipped. To use it to read your email instead, you'll want to change its mailconfig.py mail configuration file to reflect your mail account's details. We'll see this file later; for now, the examples here will use the book's POP email account; it works the same way, regardless of which account it accesses.




Programming Python
Programming Python
ISBN: 0596009259
EAN: 2147483647
Year: 2004
Pages: 270
Authors: Mark Lutz

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net