]> git.pld-linux.org Git - projects/pld-builder.new.git/blobdiff - PLD_Builder/mailer.py
Switch to https for client/request handler server and between builders communication...
[projects/pld-builder.new.git] / PLD_Builder / mailer.py
index 31584b055e107b640fbaaa00ead392429b0bdce8..c7d87335f9bbd4bd7207b5b3c0784d5a72dfe80e 100644 (file)
@@ -7,6 +7,13 @@ import StringIO
 
 from config import config
 import util
+import log
+
+def recode(s):
+    if s.__class__ == ''.__class__:
+        return s.decode('iso-8859-1', 'replace').encode('us-ascii', 'replace')
+    else:
+        return s.encode('us-ascii', 'replace')
 
 class Message:
     def __init__(self):
@@ -25,11 +32,15 @@ class Message:
         if subject != None:
             self.set_header("Subject", subject)
 
+    def remove_header(self, n):
+        if n in self.headers:
+          del self.headers[n]
+
     def write_line(self, l):
-        self.body.write("%s\n" % l)
+        self.body.write(recode("%s\n" % l))
 
     def write(self, s):
-        self.body.write(s)
+        self.body.write(recode(s))
 
     def append_log(self, log):
         s = os.stat(log)
@@ -43,7 +54,7 @@ class Message:
             line = 0
             for l in f.xreadlines():
                 if line < 100 or line > line_cnt - 100:
-                    self.body.write(l)
+                    self.body.write(recode(l))
                 if line == line_cnt - 100:
                     self.body.write("\n\n[...]\n\n")
                 line += 1
@@ -66,7 +77,16 @@ class Message:
         util.sendfile(self.body, f)
 
     def send(self):
-        send_sendmail = "/usr/sbin/sendmail -t -f %s" % config.admin_email
+        if not os.path.exists("/usr/lib/sendmail"):
+            # TODO: dump to file?
+            log.alert("/usr/lib/sendmail doesn't exist: Can't send email")
+            return False
+        send_sendmail = "/usr/lib/sendmail -i -t -f %s" % config.admin_email
         f = os.popen(send_sendmail, "w")
-        self.write_to(f)
-        f.close()
+        try:
+            self.write_to(f)
+        except IOError, e:
+            log.alert("sending email message failed: %s" % e)
+            f.close()
+            return False
+        return f.close()
This page took 0.028321 seconds and 4 git commands to generate.