#!/usr/bin/python
from sys import argv
def scanner(name, function):
file = open(name, ’r’)
line = file.readline()
while line:
function(line)
line = file.readline()
file.close()
def processLine(line):
print line
filename = ’ftplog.data’
scanner(filename, processLine)
#!/usr/bin/python
import getpass, imaplib, string
m = imaplib.IMAP4_SSL(’moppsy.comp.glam.ac.uk’)
m.login(getpass.getuser(), getpass.getpass())
m.select()
typ, data = m.search(None, ’ALL’)
print "typ = ", typ
print "data = ", data
for num in string.split(data[0]):
typ, data = m.fetch(num, ’(RFC822)’)
print ’Message %s\n%s\n’ % (num, data[0][1])
m.logout()

ssh moppsy.comp.glam.ac.uk Login: u012345678 Password: $ mail -s "this is a test" u012345678@localhost this is the body of the message . $ exit
#
# isSpam - returns 1 if the message looks like spam
# returns 0 if the message looks ok
#
def isSpam(message):
total = 0
htmlFound = 0
for line in StringIO(getBody(message)).readlines():
print line
# incomplete
#
# postEmail - sends message to the smtp port
#
def postEmail(message):
print "message from", getField(message, "From:")
print "subject is", getField(message, "Subject:")
# incomplete
#
# handleEmail - tests whether the message is spam or not.
# If spam then it adds it to a file
# otherwise post it to the smtp port
#
def handleEmail(message):
if (isSpam(message)):
print "message is spam"
else:
print "message is good"
postEmail(message)
# incomplete
#
# collectEmail - retrieves the email from the imap server
#
def collectEmail():
m = imaplib.IMAP4_SSL(’moppsy.comp.glam.ac.uk’)
m.login(getpass.getuser(), ’yourpasswordgoeshere’)
m.select()
typ, data = m.search(None, ’ALL’)
print data
for num in string.split(data[0]):
print num
typ, data = m.fetch(num, ’(RFC822)’)
handleEmail(data[0][1])
m.logout()
collectEmail()
$ ssh moppsy.comp.glam.ac.uk login: u012345678 Password: $ mail -s "this is a test" u012345678@localhost this is the body of the message . CC: press the enter key here $ exit
ssh moppsy.comp.glam.ac.uk login: u012345678 Password: $ mail Mail version 8.1.2 01/15/2001. Type ? for help. "/var/mail/u012345678": 1 message 1 new N 1 u012345678@localhost Wed Nov 15 13:30 this is a test & x $ exit
#!/usr/bin/python
import getpass, imaplib, string
m = imaplib.IMAP4_SSL(’moppsy.comp.glam.ac.uk’)
m.login(getpass.getuser(), getpass.getpass())
m.select()
typ, data = m.search(None, ’ALL’)
print "typ = ", typ
print "data = ", data
for num in string.split(data[0]):
typ, data = m.fetch(num, ’(RFC822)’)
print ’Message %s\n%s\n’ % (num, data[0][1])
m.logout()
This document was produced using groff-1.19.