Skip to content
Snippets Groups Projects
Commit ea84943f authored by Stuart D. Gathman's avatar Stuart D. Gathman
Browse files

Fix StringIO

parent 999a4464
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
from __future__ import print_function from __future__ import print_function
import rfc822 import rfc822
import StringIO try:
from StringIO import StringIO
except:
from io import StringIO
import Milter import Milter
Milter.NOREPLY = Milter.CONTINUE Milter.NOREPLY = Milter.CONTINUE
...@@ -152,14 +155,14 @@ class TestBase(object): ...@@ -152,14 +155,14 @@ class TestBase(object):
rc = self.body(buf) rc = self.body(buf)
if rc != Milter.CONTINUE: return rc if rc != Milter.CONTINUE: return rc
self._msg = msg self._msg = msg
self._body = StringIO.StringIO() self._body = StringIO()
rc = self.eom() rc = self.eom()
if self._bodyreplaced: if self._bodyreplaced:
body = self._body.getvalue() body = self._body.getvalue()
else: else:
msg.rewindbody() msg.rewindbody()
body = msg.fp.read() body = msg.fp.read()
self._body = StringIO.StringIO() self._body = StringIO()
self._body.writelines(msg.headers) self._body.writelines(msg.headers)
self._body.write('\n') self._body.write('\n')
self._body.write(body) self._body.write(body)
......
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
from __future__ import print_function from __future__ import print_function
import Milter import Milter
import StringIO try:
from StringIO import StringIO
except:
from io import StringIO
import time import time
import email import email
import sys import sys
...@@ -75,7 +78,7 @@ class myMilter(Milter.Base): ...@@ -75,7 +78,7 @@ class myMilter(Milter.Base):
# NOTE: self.fp is only an *internal* copy of message data. You # NOTE: self.fp is only an *internal* copy of message data. You
# must use addheader, chgheader, replacebody to change the message # must use addheader, chgheader, replacebody to change the message
# on the MTA. # on the MTA.
self.fp = StringIO.StringIO() self.fp = StringIO()
self.canon_from = '@'.join(parse_addr(mailfrom)) self.canon_from = '@'.join(parse_addr(mailfrom))
self.fp.write('From %s %s\n' % (self.canon_from,time.ctime())) self.fp.write('From %s %s\n' % (self.canon_from,time.ctime()))
return Milter.CONTINUE return Milter.CONTINUE
......
...@@ -94,7 +94,10 @@ ...@@ -94,7 +94,10 @@
# This code is under the GNU General Public License. See COPYING for details. # This code is under the GNU General Public License. See COPYING for details.
from __future__ import print_function from __future__ import print_function
import StringIO try:
from StringIO import StringIO
except:
from io import StringIO
import socket import socket
import Milter import Milter
import zipfile import zipfile
...@@ -113,7 +116,7 @@ from types import ListType,StringType ...@@ -113,7 +116,7 @@ from types import ListType,StringType
## Return a list of filenames in a zip file. ## Return a list of filenames in a zip file.
# Embedded zip files are recursively expanded. # Embedded zip files are recursively expanded.
def zipnames(txt): def zipnames(txt):
fp = StringIO.StringIO(txt) fp = StringIO(txt)
zipf = zipfile.ZipFile(fp,'r') zipf = zipfile.ZipFile(fp,'r')
names = [] names = []
for nm in zipf.namelist(): for nm in zipf.namelist():
...@@ -241,7 +244,7 @@ class MimeMessage(Message): ...@@ -241,7 +244,7 @@ class MimeMessage(Message):
def as_string(self, unixfrom=False): def as_string(self, unixfrom=False):
"Return the entire formatted message as a string." "Return the entire formatted message as a string."
fp = StringIO.StringIO() fp = StringIO()
self.dump(fp,unixfrom=unixfrom) self.dump(fp,unixfrom=unixfrom)
return fp.getvalue() return fp.getvalue()
...@@ -503,7 +506,7 @@ def check_html(msg,savname=None): ...@@ -503,7 +506,7 @@ def check_html(msg,savname=None):
if name and name.lower().endswith(".htm"): if name and name.lower().endswith(".htm"):
msgtype = 'text/html' msgtype = 'text/html'
if msgtype == 'text/html': if msgtype == 'text/html':
out = StringIO.StringIO() out = StringIO()
htmlfilter = HTMLScriptFilter(out) htmlfilter = HTMLScriptFilter(out)
try: try:
htmlfilter.write(msg.get_payload(decode=True)) htmlfilter.write(msg.get_payload(decode=True))
......
...@@ -7,7 +7,10 @@ from __future__ import print_function ...@@ -7,7 +7,10 @@ from __future__ import print_function
import sys import sys
import os import os
import StringIO try:
from StringIO import StringIO
except:
from io import StringIO
import rfc822 import rfc822
import mime import mime
import Milter import Milter
...@@ -39,7 +42,7 @@ class sampleMilter(Milter.Milter): ...@@ -39,7 +42,7 @@ class sampleMilter(Milter.Milter):
def envfrom(self,f,*str): def envfrom(self,f,*str):
"start of MAIL transaction" "start of MAIL transaction"
self.log("mail from",f,str) self.log("mail from",f,str)
self.fp = StringIO.StringIO() self.fp = StringIO()
self.tempname = None self.tempname = None
self.mailfrom = f self.mailfrom = f
self.bodysize = 0 self.bodysize = 0
......
...@@ -30,7 +30,10 @@ from __future__ import print_function ...@@ -30,7 +30,10 @@ from __future__ import print_function
import unittest import unittest
import mime import mime
import socket import socket
import StringIO try:
from StringIO import StringIO
except:
from io import StringIO
import email import email
import sys import sys
import Milter import Milter
...@@ -180,7 +183,7 @@ class MimeTestCase(unittest.TestCase): ...@@ -180,7 +183,7 @@ class MimeTestCase(unittest.TestCase):
self.assertEquals(rc,Milter.CONTINUE) self.assertEquals(rc,Milter.CONTINUE)
def testHTML(self,fname=""): def testHTML(self,fname=""):
result = StringIO.StringIO() result = StringIO()
filter = mime.HTMLScriptFilter(result) filter = mime.HTMLScriptFilter(result)
msg = """<! Illegal declaration used as comment> msg = """<! Illegal declaration used as comment>
<![if conditional]> Optional SGML <![endif]> <![if conditional]> Optional SGML <![endif]>
......
...@@ -3,7 +3,6 @@ import Milter ...@@ -3,7 +3,6 @@ import Milter
import sample import sample
import mime import mime
import rfc822 import rfc822
import StringIO
from Milter.test import TestBase from Milter.test import TestBase
class TestMilter(TestBase,sample.sampleMilter): class TestMilter(TestBase,sample.sampleMilter):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment