Remove the `sign` option. If you've configured pgp_keys for the
correspondents, it's because you want to use them.
This commit also ensures that the sender is also encluded on the
recipient list for encryption, although there is currently no copy of
the email forwarded to the sender.
return _email_utils.formataddr((name, person.emails[0]))
return _email_utils.formataddr((person.name, person.emails[0]))
return _email_utils.formataddr((name, person.emails[0]))
return _email_utils.formataddr((person.name, person.emails[0]))
-def construct_email(author, targets, subject, text, cc=None, sign=True):
+def construct_email(author, targets, subject, text, cc=None):
r"""Built a text/plain email using `Person` instances
>>> from pygrader.model.person import Person as Person
r"""Built a text/plain email using `Person` instances
>>> from pygrader.model.person import Person as Person
<BLANKLINE>
"""
msg = _pgp_mime.encodedMIMEText(text)
<BLANKLINE>
"""
msg = _pgp_mime.encodedMIMEText(text)
- if sign and author.pgp_key:
- msg = _pgp_mime.sign(message=msg, sign_as=author.pgp_key)
+ if author.pgp_key:
+ signers = [author.pgp_key]
+ else:
+ signers = []
+ recipients = [p.pgp_key for p in targets if p.pgp_key]
+ if signers and recipients:
+ if author.pgp_key not in recipients:
+ recipients.append(author.pgp_key)
+ msg = _pgp_mime.sign_and_encrypt(
+ message=msg, signers=signers, recipients=recipients,
+ always_trust=True)
+ elif signers:
+ msg = _pgp_mime.sign(message=msg, signers=signers)
+ elif recipients:
+ msg = _pgp_mime.encrypt(message=msg, recipients=recipients)
msg['Date'] = _email_utils.formatdate()
msg['From'] = get_address(author, header=True)
msg['Date'] = _email_utils.formatdate()
msg['From'] = get_address(author, header=True)