]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/mailer.py
- fixed mail encoding errors
[tld-builder.git] / TLD_Builder / mailer.py
index 7725a60710f76576f3fff2b1022c2b0004c1a012..a43eb9e7347982560f8fdf2249d69ac43dfdc2bf 100644 (file)
@@ -3,20 +3,11 @@
 import time
 import os
 import sys
-if sys.version_info[0] == 2:
-    import StringIO
-else:
-    from io import StringIO
-
+from io import StringIO
 from config import config
-import util
+import shutil
 import log
-
-def recode(s):
-    if s.__class__ == ''.__class__:
-        return s.encode('iso-8859-1', 'replace').decode('us-ascii', 'replace')
-    else:
-        return s.decode('us-ascii', 'replace')
+import util
 
 class Message:
     def __init__(self):
@@ -40,10 +31,10 @@ class Message:
             del self.headers[n]
 
     def write_line(self, l):
-        self.body.write(recode("%s\n" % l))
+        self.body.write(util.to_str("%s\n" % l))
 
     def write(self, s):
-        self.body.write(recode(s))
+        self.body.write(util.to_str(s))
 
     def append_log(self, log):
         s = os.stat(log)
@@ -57,12 +48,12 @@ class Message:
             line = 0
             for l in f:
                 if line < 100 or line > line_cnt - 100:
-                    self.body.write(recode(l))
+                    self.body.write(util.to_str(l))
                 if line == line_cnt - 100:
                     self.body.write("\n\n[...]\n\n")
                 line += 1
         else:
-            util.sendfile(open(log), self.body)
+            shutil.copyfileobj(open(log), self.body)
 
     def set_std_headers(self):
         self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
@@ -77,7 +68,7 @@ class Message:
             f.write("%s: %s\n" % (k, v))
         f.write("\n")
         self.body.seek(0)
-        util.sendfile(self.body, f)
+        shutil.copyfileobj(self.body, f)
 
     def send(self):
         if not os.path.exists("/usr/lib/sendmail"):