# 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"]:
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"
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"]:
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
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)
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
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)
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)
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()
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"
################################################################################
-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:
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"]
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)