[Tutor] email stuff in python

Kirk Bailey idiot1@netzero.net
Thu Jul 3 23:17:05 2003


well, by now you know that python email is what I like to do. Recently, having dealt 
with a lot of spam, I decided to create an alias to trap and save spam for later 
examination by our coven of dread legal vampires- simple, an alias feeds it to a file 
where it is appended, and a ssi include in a web page lets us inspect the contents any 
time I like. This looks like:
<!--#include file="./cgi-bin/(filename)" -->
More on this later on.

Then I realized, this is what a local delivery program does. So I wrote a simple program 
to absorb the input from an alias, and write it out to a file for later access. With 
more work, such a program could listen to an incoming port and receive email, extract 
the TO: field data, and send the message to a pop3 mailbox, or to an alternate 
destination were one defined, or just eat it. I may just write one as a giggle later on 
this weekend.

Anyroad, it's useless, but is a working example of using stdin to accept email from an 
alias and do something intresting with it. Possible useless python candidate?

OK, it's later. An intresting challenge is to get the browser to preserve paragraphing 
and composition and still word wrap the display to fit the screen. See, simple html 
wordwraps, but ignores newlines, obliterating the spacing of paragraphs and ending lines 
where you want them to. As some email transmission clients depend on the recipient to 
wrap to fit space, they tend to send on one line  until you click the [return] key, 
which looks terrible in a <pre></pre> zone.

My quick and dirty solution is to use a textarea, and until I find a simple and powerful 
alternate, that's how I will address such issues in the future.

Anyonw who wants to see this thing click here:
http://www.tinylist.org/mailbox.shtml

To email something to it and see the result, email:
mailto:mailbox@tinylist.org

Here is the actual script:

#!/usr/local/bin/python
import sys, string
#
def gangstrip(thing):                   # ok, everybody STRIP!
         index=0                         # This strips out whitespace chars
         while index < len(thing):       # define exit
                 thing[index]=string.rstrip(thing[index])
                 index=index+1           # increase the counter
#
filename=sys.argv[1]    # the idea is the alias has a command line arguement
pwd='/www/www.tinylist.org/cgi-bin/'
print pwd
msg=sys.stdin.readlines() #and standard_in receives the entire message.
gangstrip(msg)
f1=open(pwd+filename,'a')
for line in msg:
         f1.write(line+'\n')
f1.close()


-- 

end

Cheers!
         Kirk D Bailey
                               think
http://www.howlermonkey.net/ +-----+ http://www.tinylist.org/
http://www.listville.net/    | BOX | http://www.sacredelectron.org/
                              +-----+
"Thou art free"-ERIS          think    'Got a light?'-Promethieus

.