1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
8 from config import config
13 if s.__class__ == ''.__class__:
14 return s.decode('iso-8859-1', 'replace').encode('us-ascii', 'replace')
16 return s.encode('us-ascii', 'replace')
21 self.body = StringIO.StringIO()
22 self.set_std_headers()
24 def set_header(self, n, v):
27 def set_headers(self, to = None, cc = None, subject = None):
29 self.set_header("To", to)
31 self.set_header("Cc", cc)
33 self.set_header("Subject", subject)
35 def remove_header(self, n):
39 def write_line(self, l):
40 self.body.write(recode("%s\n" % l))
43 self.body.write(recode(s))
45 def append_log(self, log):
51 for l in f.xreadlines():
55 for l in f.xreadlines():
56 if line < 100 or line > line_cnt - 100:
57 self.body.write(recode(l))
58 if line == line_cnt - 100:
59 self.body.write("\n\n[...]\n\n")
62 util.sendfile(open(log), self.body)
64 def set_std_headers(self):
65 self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
66 self.headers["Message-ID"] = "<tld-builder.%f.%d@%s>" \
67 % (time.time(), os.getpid(), os.uname()[1])
68 self.headers["From"] = "TLD %s builder <%s>" \
69 % (config.builder, config.email)
70 self.headers["X-TLD-Builder"] = config.builder
72 def write_to(self, f):
73 for k, v in self.headers.items():
74 f.write("%s: %s\n" % (k, v))
77 util.sendfile(self.body, f)
80 if not os.path.exists("/usr/lib/sendmail"):
82 log.alert("/usr/lib/sendmail doesn't exist: Can't send email")
84 send_sendmail = "/usr/lib/sendmail -i -t -f %s" % config.admin_email
85 f = os.popen(send_sendmail, "w")
89 log.alert("sending email message failed: %s" % e)