parser.error("--rt-owner requires specifying a queue")
return options, args
+def nop_msg_filter(rcpt, body):
+ return rcpt, body
+
def msg_filter_factory(opts):
if not opts.rt_queue:
- return lambda rcpt, body: body
+ return nop_msg_filter
import rtkit.tracker, rtkit.authenticators, rtkit.errors
cookie = rtkit.authenticators.CookieAuthenticator
logger.error(e.response.status)
logger.error(e.response.parsed)
- return msg.as_string()
+ # We don't want to send mail to the real recipient, because RT
+ # will send them a copy too.
+ return None, msg.as_string()
return filter_rt
def mail_merge(opts, cc_addr, email_file, recipients_file):
- email = open(email_file, 'r').read()
+ email_tmpl = open(email_file, 'r').read()
reader = csv.reader(open(recipients_file, 'r'))
header = reader.next()
msg_filter = msg_filter_factory(opts)
for line in reader:
dct = dictize_line(header, line, )
print dct
- text = email % dct
- text = msg_filter(dct['email'], text, )
- print text
- sendmail([dct['email'], cc_addr, ], text, )
+ text = email_tmpl % dct
+ rcpt, text = msg_filter(dct['email'], text, )
+ rcpts = [cc_addr]
+ if rcpt:
+ rcpts.append(rcpt)
+ sendmail(rcpts, text, )
if __name__=='__main__':
options, args = parse_arguments()