[Tutor] Newbie simple question
Valone, Toren W.
TValone at DMV.CA.gov
Fri Feb 25 23:14:59 CET 2005
I need to know how to read the next line while in the "for line in" loop.
Readline does not read the next line (I watched it in debug) I think it has
something to do with the for line loop but I have not found any
documentation in the doc's or tutor for any functions for line..
Thanks, please forgive the sloppy code.
#This Python App will simply remail emails that cannot be remailed from the
MF
import smtplib
from string import *
from Email import *
#def main(): #define function or class main
# Email the results
# Email('Tvalone at dmv.ca.gov',
# R emailTo,
# sub,
# results)
remailfile = open('remail2.txt', 'r') #future address/file from outlook
resendfile = open('resend.txt', 'w') #currently these files are in Python24
EmailReport = open('erprt.txt', 'w') #Report of bad emails etc
fromaddr='Tvalone at dmv.ca.gov'
for line in remailfile: #loops thru all emails,
#print "test"
if line.startswith("Subject: Undeliverable Mail"):
EmailReport.write(line)
elif line.startswith("MVSSY4.TEALE.CA.GOV unable to deliver
following"):
#line.readline()
remailfile.readline()
toaddr = line[4:80] #Set line to
email
#toaddr = lstrip("<") #Strip less than
#toaddr = rstrip(">") #Strip greater
than
print len(toaddr)
elif line.startswith("TO:"):
#if toaddr != '':
#toaddr = line[4:25]
#toaddr = lstrip(toaddr)
#resendfile.write(line)
remailfile.readline() #read the next line to get subject
#print RemailTo
elif line.startswith("SUBJECT:"):
subj = line[9:30] #Strip out Subject
#print sub
resendfile.write(line)
remailfile.readline() #need to read line
elif line.startswith("At"):
remailfile.readline()
elif line.startswith("Date:"):
remailfile.readline()
elif line.startswith("From:"):
remailfile.readline()
elif not line:
remailfile.readline()
elif line.startswith("We"):
body = line
resendfile.write(line)
elif line.startswith("File"):
body = line
remailfile.readline()
resendfile.write(line)
elif line.startswith("with"):
body = body + line
resendfile.write(line)
#print results
#print len(fromaddr)
#print len(toaddr)
#print len(subj)
#print len(body)
Email(fromaddr,toaddr,subj,body)
remailfile.close()
resendfile.close()
More information about the Tutor
mailing list