]> err.no Git - dak/commitdiff
Add per-suite mail whitelists.
authorAnsgar Burchardt <ansgar@debian.org>
Mon, 17 Sep 2012 08:51:26 +0000 (10:51 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Mon, 17 Sep 2012 14:21:19 +0000 (16:21 +0200)
dak/rm.py
daklib/announce.py
daklib/queue.py
daklib/utils.py

index e4f4a6cb8e0d428042bb634847c86de91ac8cc13..ec36bf4e49f57687b94e2044812c7fc5629b0cab 100755 (executable)
--- a/dak/rm.py
+++ b/dak/rm.py
@@ -210,6 +210,7 @@ def main ():
 
     # Additional suite checks
     suite_ids_list = []
+    whitelists = []
     suites = utils.split_args(Options["Suite"])
     suites_list = utils.join_with_commas_and(suites)
     if not Options["No-Action"]:
@@ -217,6 +218,7 @@ def main ():
             s = get_suite(suite, session=session)
             if s is not None:
                 suite_ids_list.append(s.suite_id)
+                whitelists.append(s.mail_whitelist)
             if suite in ("oldstable", "stable"):
                 print "**WARNING** About to remove from the (old)stable suite!"
                 print "This should only be done just prior to a (point) release and not at"
@@ -498,7 +500,7 @@ def main ():
                 mail_message = utils.TemplateSubst(Subst_close_rm,cnf["Dir::Templates"]+"/rm.bug-close-with-related")
             else:
                 mail_message = utils.TemplateSubst(Subst_close_rm,cnf["Dir::Templates"]+"/rm.bug-close")
-            utils.send_mail(mail_message)
+            utils.send_mail(mail_message, whitelists=whitelists)
 
     # close associated bug reports
     if Options["Do-Close"]:
index 6c0fd374186aed603dfc74e7ebeab90a6e034acb..fdc3e468555a4782adc22c586dd75f0e1a3ebaf6 100644 (file)
@@ -87,9 +87,13 @@ def _subst_for_upload(upload):
 
     return subst
 
+def _whitelists(upload):
+    return [ s.mail_whitelist for s in upload.suites ]
+
 def announce_reject(upload, reason, rejected_by=None):
     cnf = Config()
     subst = _subst_for_upload(upload)
+    whitelists = _whitelists(upload)
 
     automatic = rejected_by is None
 
@@ -103,11 +107,12 @@ def announce_reject(upload, reason, rejected_by=None):
         subst['__BCC__'] = '{0}\nBcc: {1}'.format(subst['__BCC__'], cnf['Dinstall::MyEmailAddress'])
 
     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected'))
-    send_mail(message)
+    send_mail(message, whitelists=whitelists)
 
 def announce_accept(upload):
     cnf = Config()
     subst = _subst_for_upload(upload)
+    whitelists = _whitelists(upload)
 
     accepted_to_real_suite = any(suite.policy_queue is None or suite in upload.from_policy_suites for suite in upload.suites)
 
@@ -121,7 +126,7 @@ def announce_accept(upload):
     subst['__SUITE__'] = ', '.join(suite_names) or '(none)'
 
     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.accepted'))
-    send_mail(message)
+    send_mail(message, whitelists=whitelists)
 
     if accepted_to_real_suite and upload.sourceful:
         # senf mail to announce lists and tracking server
@@ -141,7 +146,7 @@ def announce_accept(upload):
             my_subst['__ANNOUNCE_LIST_ADDRESS__'] = announce_list_address
 
             message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce'))
-            send_mail(message)
+            send_mail(message, whitelists=whitelists)
 
     close_bugs_default = cnf.find_b('Dinstall::CloseBugs')
     close_bugs = any(s.close_bugs if s.close_bugs is not None else close_bugs_default for s in upload.suites)
@@ -151,11 +156,12 @@ def announce_accept(upload):
             my_subst['__BUG_NUMBER__'] = str(bug)
 
             message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close'))
-            send_mail(message)
+            send_mail(message, whitelists=whitelists)
 
 def announce_new(upload):
     cnf = Config()
     subst = _subst_for_upload(upload)
+    whitelists = _whitelists(upload)
 
     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new'))
-    send_mail(message)
+    send_mail(message, whitelists=whitelists)
index 547972ed0932b6af669e836e96a61dbfcbdf100d..9dd2702ca02aa296071f768cd7764c7c4e9f37cf 100644 (file)
@@ -104,6 +104,7 @@ def check_valid(overrides, session):
 def prod_maintainer(notes, upload):
     cnf = Config()
     changes = upload.changes
+    whitelists = [ upload.target_suite.mail_whitelist ]
 
     # Here we prepare an editor and get them ready to prod...
     (fd, temp_filename) = utils.temp_filename()
@@ -154,7 +155,7 @@ def prod_maintainer(notes, upload):
         Subst,cnf["Dir::Templates"]+"/process-new.prod")
 
     # Send the prod mail
-    utils.send_mail(prod_mail_message)
+    utils.send_mail(prod_mail_message, whitelists=whitelists)
 
     print "Sent prodding message"
 
index 03cd589463c5e81908529c8d8ed17927d6082abc..fd50cb1c7430a6f852131377bdd7bc1556262e58 100755 (executable)
@@ -603,8 +603,16 @@ def build_package_list(dsc, session = None):
 
 ################################################################################
 
-def send_mail (message, filename=""):
-    """sendmail wrapper, takes _either_ a message string or a file as arguments"""
+def send_mail (message, filename="", whitelists=None):
+    """sendmail wrapper, takes _either_ a message string or a file as arguments
+
+    @type  whitelists: list of (str or None)
+    @param whitelists: path to whitelists. C{None} or an empty list whitelists
+                       everything, otherwise an address is whitelisted if it is
+                       included in any of the lists.
+                       In addition a global whitelist can be specified in
+                       Dinstall::MailWhiteList.
+    """
 
     maildir = Cnf.get('Dir::Mail')
     if maildir:
@@ -624,23 +632,24 @@ def send_mail (message, filename=""):
         os.write (fd, message)
         os.close (fd)
 
-    if Cnf.has_key("Dinstall::MailWhiteList") and \
-           Cnf["Dinstall::MailWhiteList"] != "":
+    if whitelists is None or None in whitelists:
+        whitelists = []
+    if Cnf.get('Dinstall::MailWhiteList', ''):
+        whitelists.append(Cnf['Dinstall::MailWhiteList'])
+    if len(whitelists) != 0:
         message_in = open_file(filename)
         message_raw = modemail.message_from_file(message_in)
         message_in.close();
 
         whitelist = [];
-        whitelist_in = open_file(Cnf["Dinstall::MailWhiteList"])
-        try:
+        for path in whitelists:
+          with open_file(path, 'r') as whitelist_in:
             for line in whitelist_in:
                 if not re_whitespace_comment.match(line):
                     if re_re_mark.match(line):
                         whitelist.append(re.compile(re_re_mark.sub("", line.strip(), 1)))
                     else:
                         whitelist.append(re.compile(re.escape(line.strip())))
-        finally:
-            whitelist_in.close()
 
         # Fields to check.
         fields = ["To", "Bcc", "Cc"]
@@ -657,7 +666,7 @@ def send_mail (message, filename=""):
                             mail_whitelisted = 1
                             break
                     if not mail_whitelisted:
-                        print "Skipping %s since it's not in %s" % (item, Cnf["Dinstall::MailWhiteList"])
+                        print "Skipping {0} since it's not whitelisted".format(item)
                         continue
                     match.append(item)