]> git.pld-linux.org Git - projects/pld-ftp-admin.git/commitdiff
- works
authorMariusz Mazur <mmazur@pld-linux.org>
Wed, 4 May 2005 23:15:31 +0000 (23:15 +0000)
committerMariusz Mazur <mmazur@pld-linux.org>
Wed, 4 May 2005 23:15:31 +0000 (23:15 +0000)
Changed files:
    modules/mailer.py -> 1.2

modules/mailer.py

index 31584b055e107b640fbaaa00ead392429b0bdce8..bf13ef5e551ebf9b51b31ac2f52d49af435efdcc 100644 (file)
@@ -5,14 +5,14 @@ import os
 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()
-        self.set_std_headers()
+        self.__set_std_headers()
 
     def set_header(self, n, v):
         self.headers[n] = v
@@ -31,42 +31,33 @@ class Message:
     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["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):
+    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)
-        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
+
This page took 0.038964 seconds and 4 git commands to generate.