/[qa]/trunk/mia/mia-record
ViewVC logotype

Contents of /trunk/mia/mia-record

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1123 - (hide annotations) (download)
Wed Nov 9 17:59:22 2005 UTC (7 years, 6 months ago) by tbm
File size: 4403 byte(s)
do iterate over every line
1 tbm 133 #!/usr/bin/env python
2 tbm 5
3 tbm 161 # Store an e-mail or a summary in the database; called by exim
4 tbm 1116 # Copyright (C) 2001, 2002, 2003, 2004, 2005 Martin Michlmayr <tbm@cyrius.com>
5 tbm 21 # $Id$
6 tbm 5
7     # This program is free software; you can redistribute it and/or modify
8     # it under the terms of the GNU General Public License as published by
9     # the Free Software Foundation; either version 2 of the License, or
10     # (at your option) any later version.
11    
12     # This program is distributed in the hope that it will be useful,
13     # but WITHOUT ANY WARRANTY; without even the implied warranty of
14     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     # GNU General Public License for more details.
16    
17     # You should have received a copy of the GNU General Public License
18     # along with this program; if not, write to the Free Software
19     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20    
21    
22 tbm 1117 import email, os, re, sys, time
23 tbm 673 import apt_pkg, utils, status
24 tbm 5
25 tbm 675 re_summary = re.compile(r"MIA-Summary:\s*(.+)")
26     re_id = re.compile(r"MIA-ID:\s*(\d+)")
27    
28 tbm 230 apt_pkg.init()
29 tbm 246 Cnf = apt_pkg.newConfiguration()
30     apt_pkg.ReadConfigFileISC(Cnf, status.config)
31 tbm 230
32 tbm 1117 msg = email.message_from_string(sys.stdin.read())
33 tbm 5
34 tbm 845 # Check where the mail is being delivered to because we only want to accept
35     # mail for mia-*@qa users.
36 tbm 1117 maint = msg.get("Delivered-To", "").split("@")[0]
37 tbm 845 if not maint:
38 jeroen 979 print >> sys.stderr, "No maintainer given, please use mia-<maint>@qa"
39 tbm 845 sys.exit(1)
40     # mail has to be sent to mia-*, otherwise mia-record will not accept it
41     if maint[:4] != "mia-":
42 jeroen 979 print >> sys.stderr, "No such user"
43 tbm 845 sys.exit(1)
44     maint = maint[4:]
45 jeroen 979 # make sure to not allow shell stuff, /'s, etc!
46 jeroen 1078 if re.compile(r"[^a-z0-9=+._-]").search(maint, re.I):
47 jeroen 979 print >> sys.stderr, "Invalid characters found in maintainer, aborting"
48     sys.exit(1)
49 tbm 845
50 tbm 673 Subst = {}
51 tbm 674 Subst["__FROM__"] = "%s <%s@%s>" % (Cnf["MyAdminName"], Cnf["MyUser"], Cnf["MyHost"])
52 tbm 673 Subst["__SUBJECT__"] = msg.get("Subject", "")
53     Subst["__MESSAGE_ID__"] = msg.get("Message-ID", "")
54 tbm 1117 Subst["__REFERENCES__"] = "%s %s" % (msg.get("References", ""), msg.get("Message-ID", ""))
55 tbm 674 Subst["__MIA_USER__"] = Cnf["MyUser"]
56     Subst["__MIA_DOMAIN__"] = Cnf["MyHost"]
57 tbm 673 Subst["__LOGIN__"] = maint
58 tbm 844 Subst["__EMAIL__"] = maint.replace("=", "@")
59 tbm 673 Subst["__REVISION__"] = "$Revision$"
60    
61 tbm 1117 if "MIA-SUMMARY" in msg.get("Subject", ""):
62 tbm 675 summary = id = None
63 tbm 1123 for line in msg.as_string().split("\n"):
64 tbm 675 if not summary:
65     summary = re_summary.search(line, re.I)
66     if not id:
67     id = re_id.search(line, re.I)
68 tbm 231
69 tbm 675 if summary and id:
70 tbm 22 status.write_status(maint, id.group(1), summary.group(1))
71 tbm 673 Subst["__SUMMARY__"] = summary.group(1)
72     Subst["__ID__"] = str(id.group(1))
73     mail_message = utils.TemplateSubst(Subst, Cnf["Dir::Templates"]+"/mia-record.thanks")
74     utils.send_mail(mail_message)
75 tbm 5 else:
76 jeroen 979 print >> sys.stderr, "not ok: no summary or ID"
77 tbm 5 sys.exit(1)
78     else:
79     try:
80 tbm 515 mbox = open(Cnf["Dir::Database"] + "/" + maint, "a")
81 tbm 412 except IOError, e:
82 jeroen 979 print >> sys.stderr, "Cannot open mbox file for %s to append: %s" % (maint, e)
83 tbm 5 sys.exit(1)
84 tbm 1119 mbox.write(msg.as_string())
85 tbm 5 mbox.close()
86    
87 tbm 1117 date_tz = email.Utils.parsedate_tz(msg["Date"])
88 tbm 27 # subtract the timezone so we get a TZ independent value
89 tbm 138 when = int(time.mktime(date_tz[:9])) - date_tz[9] - time.timezone
90 tbm 5
91 tbm 673 summary = msg.get("X-MIA-Summary")
92     if summary:
93     status.write_status(maint, when, summary)
94     Subst["__SUMMARY__"] = summary
95 tbm 1121 mail_msg = utils.TemplateSubstMIMEMultipart(Subst, Cnf["Dir::Templates"]+"/mia-record.added")
96 tbm 673 else:
97     Subst["__ID__"] = str(when)
98 tbm 677 Subst["__SUMMARIES__"] = ""
99     for i in Cnf.SubTree("Summaries").List():
100 tbm 1116 Subst["__SUMMARIES__"] += " %s: %s\n" % (i, ", ".join(Cnf.ValueList("Summaries::%s" % i)))
101 tbm 1121 mail_msg = utils.TemplateSubstMIMEMultipart(Subst, Cnf["Dir::Templates"]+"/mia-record.respond")
102     # Attach the original message
103     a = email.Message.Message()
104     a["Content-Type"] = "message/rfc822"
105     a.set_payload([msg])
106     mail_msg.attach(a)
107     utils.send_mail(mail_msg.as_string())
108 tbm 673
109 tbm 516 # debian.org's exim has dumb default file permissions. Give group write perms
110 tbm 515 for file in os.listdir(Cnf["Dir::Database"]):
111 tbm 202 try:
112 tbm 515 os.chmod(Cnf["Dir::Database"] + "/" + file, 0664)
113 tbm 202 except OSError:
114     pass
115 tbm 24
116 tbm 454
117 tbm 672 # vim: ts=4:expandtab:shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5