Raphael Hertzog <hert...@debian.org> writes:
> I just created the attached patch. It's untested for now but I wanted you
> to check if the approach used was matching your expectation.

Yes, that's the idea I came up with some days ago.

> There's a new configuration entry DInstall::UploadMailRecipients that
> lists the recipients of the mails, either static ones (like
> d...@security.debian.org) or dynamic ones (like "maintainer", "changed_by"
> or "signer").

I prefer something like "mail:f...@example.com" over using the "@" do
discriminate between e-mail addresses and keywords.

> --- a/daklib/utils.py
> +++ b/daklib/utils.py
> @@ -1086,13 +1086,40 @@ def mail_addresses_for_upload(maintainer, changed_by, 
> fingerprint):
>      @return: list of RFC 2047-encoded mail addresses to contact regarding
>               this upload
>      """
> -    addresses = [maintainer]
> -    if changed_by != maintainer:
> -        addresses.append(changed_by)
> +    recipients = Cnf.value_list('Dinstall::UploadMailRecipients')
> +    if not recipients:
> +        recipients = [
> +            'maintainer',
> +            'changed_by',
> +            'signer'
> +        ]
> +
> +    addresses = []
> +    emails_added = {}
> +    for recipient in recipients:
> +        if '@' in recipient:  # Email hardcoded in config
> +            address = recipient
> +        elif recipient == 'maintainer':
> +            address = maintainer
> +        elif recipient == 'changed_by':
> +            address = changed_by
> +        elif recipient == 'signer':
> +            fpr_addresses = gpg_get_key_addresses(fingerprint)
> +            for fpr_addr in fpr_addresses:
> +                if fpr_addr in emails_added:
> +                    break  # The signer already gets a copy via another email
> +            else:
               ^^^^
Wrong indent?

Python also has a `any` function for this type of loops which should be
a bit less verbose.

> +                if len(fpr_addresses) > 0:
> +                    address = fpr_addresses[0]
> +        else:
> +            raise Exception('Unsupported entry in {0}: {1}'.format(
> +                'Dinstall::UploadMailRecipients', recipient))
>  
> -    fpr_addresses = gpg_get_key_addresses(fingerprint)
> -    if len(fpr_addresses) > 0 and fix_maintainer(changed_by)[3] not in 
> fpr_addresses and fix_maintainer(maintainer)[3] not in fpr_addresses:
> -        addresses.append(fpr_addresses[0])
> +        if address is not None:
> +            email = fix_maintainer(address)[3]
> +            if email not in emails_added:
> +                addresses.append(address)
> +                emails_added[email] = True

That looks like `emails_added` should be a `set`.  As the order of
recipients shouldn't matter, we can probably just use a single set for
the mail addresses.

Also the new logic to include the GPG mail address only when no other
address from the key is already used depends on `signer` being the last
keyword.

Ansgar

Reply via email to