Fix lots of py3isms. Email package is borked in py3, however.

This commit is contained in:
Stuart D. Gathman
2016-09-21 17:24:37 -04:00
parent 70fa47dac6
commit bae79a4f1c
10 changed files with 62 additions and 83 deletions
+4 -8
View File
@@ -11,7 +11,6 @@ try:
from StringIO import StringIO
except:
from io import StringIO
import rfc822
import mime
import Milter
import tempfile
@@ -141,19 +140,16 @@ class sampleMilter(Milter.Milter):
self.log("Temp file:",self.tempname)
self.tempname = None # prevent removal of original message copy
# copy defanged message to a temp file
out = tempfile.TemporaryFile()
try:
with tempfile.TemporaryFile() as out:
msg.dump(out)
out.seek(0)
msg = rfc822.Message(out)
msg.rewindbody()
msg = mime.message_from_file(out)
fp = StringIO(msg.as_bytes().split(b'\n\n',1)[1])
while 1:
buf = out.read(8192)
buf = fp.read(8192)
if len(buf) == 0: break
self.replacebody(buf) # feed modified message to sendmail
return Milter.ACCEPT # ACCEPT modified message
finally:
out.close()
return Milter.TEMPFAIL
def close(self):