#2195 koji-gc: allow specifying CC and BCC address for email notifications
Merged 2 years ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue2169  into  master

file modified
+17 -4
@@ -76,6 +76,10 @@ 

                        help=_("Email domain appended to Koji username for notifications"))

      parser.add_option("--from-addr", default="Koji Build System <buildsys@example.com>",

                        help=_("From address for notifications"))

+     parser.add_option("--cc-addr", help=_("CC address for notifications (multiple)"),

+                       action="append", metavar="EMAIL_ADDRESS")

+     parser.add_option("--bcc-addr", help=_("BCC address for notifications (multiple)"),

+                       action="append", metavar="EMAIL_ADDRESS")

      parser.add_option("--email-template", default="/etc/koji-gc/email.tpl",

                        help=_("notification template"))

      parser.add_option("--action", help=_("action(s) to take"))
@@ -135,6 +139,8 @@ 

          ['smtp_user', None, 'string'],

          ['smtp_pass', None, 'string'],

          ['from_addr', None, 'string'],

+         ['cc_addr', None, 'string'],

+         ['bcc_addr', None, 'string'],

          ['email_template', None, 'string'],

          ['email_domain', None, 'string'],

          ['mail', None, 'boolean'],
@@ -159,6 +165,10 @@ 

                  setattr(defaults, name, config.getboolean(*alias))

              else:

                  setattr(defaults, name, config.get(*alias))

+     if config.has_option('main', 'cc_addr'):

+         setattr(defaults, 'cc_addr', config.get('main', 'cc_addr').split(','))

+     if config.has_option('main', 'bcc_addr'):

+         setattr(defaults, 'bcc_addr', config.get('main', 'bcc_addr').split(','))

      # parse again with defaults

      (options, args) = parser.parse_args(values=defaults)

      options.config = config
@@ -400,23 +410,26 @@ 

          msg['Subject'] = "%i builds marked for deletion" % len(builds)

      msg['From'] = options.from_addr

      msg['To'] = "%s@%s" % (owner_name, options.email_domain)  # XXX!

+     emails = [msg['To']] + options.cc_addr + options.bcc_addr

+     if options.cc_addr:

+         msg['Cc'] = ','.join(options.cc_addr)

      msg['X-Koji-Builder'] = owner_name

      if options.test:

          if options.debug:

              print(str(msg))

          else:

-             print("Would have sent warning notice to %s" % msg['To'])

+             print("Would have sent warning notice to %s" % emails)

      else:

          if options.debug:

-             print("Sending warning notice to %s" % msg['To'])

+             print("Sending warning notice to %s" % emails)

          try:

              s = smtplib.SMTP(options.smtp_host)

              if options.smtp_user is not None and options.smtp_pass is not None:

                  s.login(options.smtp_user, options.smtp_pass)

-             s.sendmail(msg['From'], msg['To'], msg.as_string())

+             s.sendmail(msg['From'], emails, msg.as_string())

              s.quit()

          except Exception:

-             print("FAILED: Sending warning notice to %s" % msg['To'])

+             print("FAILED: Sending warning notice to %s" % emails)

  

  

  def main(args):

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

this indent should be removed

rebased onto 24e8cdb

2 years ago

2 new commits added

  • lib: check consistency of rpm from openRemoteFile
  • lib: retry openRemoteFile and check size
2 years ago

3 new commits added

  • fix indentation
  • hide bcc addresses
  • Add CC/BCC for email notifications
2 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

2 years ago

Commit 8734a9c fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago