]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - modules/mailer.py
- works
[projects/pld-ftp-admin.git] / modules / mailer.py
CommitLineData
972c18d7
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3import time
4import os
5import sys
6import StringIO
7
59ecaf12
MM
8import config
9cval=config.value
972c18d7
MM
10
11class Message:
12 def __init__(self):
13 self.headers = {}
14 self.body = StringIO.StringIO()
59ecaf12 15 self.__set_std_headers()
972c18d7
MM
16
17 def set_header(self, n, v):
18 self.headers[n] = v
19
20 def set_headers(self, to = None, cc = None, subject = None):
21 if to != None:
22 self.set_header("To", to)
23 if cc != None:
24 self.set_header("Cc", cc)
25 if subject != None:
26 self.set_header("Subject", subject)
27
28 def write_line(self, l):
29 self.body.write("%s\n" % l)
30
31 def write(self, s):
32 self.body.write(s)
33
59ecaf12
MM
34 def send(self):
35 send_sendmail = "/usr/sbin/sendmail -t"
36 f = os.popen(send_sendmail, "w")
37 self.__write_to(f)
38 f.close()
972c18d7 39
59ecaf12 40 def __set_std_headers(self):
972c18d7
MM
41 self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
42 self.headers["Message-ID"] = "<pld-builder.%f.%d@%s>" \
43 % (time.time(), os.getpid(), os.uname()[1])
59ecaf12
MM
44 self.headers["From"] = cval['from_field']
45 self.headers["X-PLD-Builder"] = cval['xpldbuilder']
972c18d7 46
59ecaf12 47 def __write_to(self, f):
972c18d7
MM
48 for k, v in self.headers.items():
49 f.write("%s: %s\n" % (k, v))
50 f.write("\n")
51 self.body.seek(0)
59ecaf12
MM
52 self.__sendfile(self.body, f)
53
54 def __sendfile(self, src, dst):
55 cnt = 0
56 while 1:
57 s = src.read(10000)
58 if s == "": break
59 cnt += len(s)
60 dst.write(s)
61 return cnt
62
63
This page took 0.17736 seconds and 4 git commands to generate.