Changed files:
modules/mailer.py -> 1.2
import sys
import StringIO
import sys
import StringIO
-from config import config
-import util
+import config
+cval=config.value
class Message:
def __init__(self):
self.headers = {}
self.body = StringIO.StringIO()
class Message:
def __init__(self):
self.headers = {}
self.body = StringIO.StringIO()
+ self.__set_std_headers()
def set_header(self, n, v):
self.headers[n] = v
def set_header(self, n, v):
self.headers[n] = v
def write(self, s):
self.body.write(s)
def write(self, s):
self.body.write(s)
- def append_log(self, log):
- s = os.stat(log)
- if s.st_size > 50000:
- # just head and tail
- f = open(log)
- line_cnt = 0
- for l in f.xreadlines():
- line_cnt += 1
- f.seek(0)
- line = 0
- for l in f.xreadlines():
- if line < 100 or line > line_cnt - 100:
- self.body.write(l)
- if line == line_cnt - 100:
- self.body.write("\n\n[...]\n\n")
- line += 1
- else:
- util.sendfile(open(log), self.body)
+ def send(self):
+ send_sendmail = "/usr/sbin/sendmail -t"
+ f = os.popen(send_sendmail, "w")
+ self.__write_to(f)
+ f.close()
- def set_std_headers(self):
+ def __set_std_headers(self):
self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
self.headers["Message-ID"] = "<pld-builder.%f.%d@%s>" \
% (time.time(), os.getpid(), os.uname()[1])
self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
self.headers["Message-ID"] = "<pld-builder.%f.%d@%s>" \
% (time.time(), os.getpid(), os.uname()[1])
- self.headers["From"] = "PLD %s builder <%s>" \
- % (config.builder, config.email)
- self.headers["X-PLD-Builder"] = config.builder
+ self.headers["From"] = cval['from_field']
+ self.headers["X-PLD-Builder"] = cval['xpldbuilder']
+ def __write_to(self, f):
for k, v in self.headers.items():
f.write("%s: %s\n" % (k, v))
f.write("\n")
self.body.seek(0)
for k, v in self.headers.items():
f.write("%s: %s\n" % (k, v))
f.write("\n")
self.body.seek(0)
- util.sendfile(self.body, f)
-
- def send(self):
- send_sendmail = "/usr/sbin/sendmail -t -f %s" % config.admin_email
- f = os.popen(send_sendmail, "w")
- self.write_to(f)
- f.close()
+ self.__sendfile(self.body, f)
+
+ def __sendfile(self, src, dst):
+ cnt = 0
+ while 1:
+ s = src.read(10000)
+ if s == "": break
+ cnt += len(s)
+ dst.write(s)
+ return cnt
+
+