documentation + add unconditionally_encrypt optional kwarg to encrypt()
This commit is contained in:
parent
3f0aa89f08
commit
fe0caa446a
2 changed files with 16 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
.venv/
|
||||
|
||||
.idea/
|
||||
|
|
18
gpgmymail
18
gpgmymail
|
@ -46,12 +46,24 @@ def is_message_encrypted(message: email.message.Message) -> bool:
|
|||
|
||||
return message.get_content_type() == "multipart/encrypted"
|
||||
|
||||
def encrypt(message: email.message.Message, recipients: typing.List[str]) -> str:
|
||||
"""Encrypt given message"""
|
||||
def encrypt(
|
||||
message: email.message.Message,
|
||||
recipients: typing.List[str],
|
||||
*,
|
||||
unconditionally_encrypt: bool = False
|
||||
) -> str:
|
||||
"""Encrypt given message
|
||||
|
||||
:param message: an email.message.Message object to be encrypted
|
||||
:param recipients: a List of recipients
|
||||
:param unconditionally_encrypt: if True, will encrypt no matter what. If
|
||||
False (default), will NOT encrypt if any of the following conditions are
|
||||
met:
|
||||
- The message is already encrypted"""
|
||||
|
||||
# some mail clients like Thunderbird don't like twice-encrypted emails,
|
||||
# so we return the message as-is if it's already encrypted
|
||||
if is_message_encrypted(message):
|
||||
if is_message_encrypted(message) and not unconditionally_encrypt:
|
||||
return message.as_string()
|
||||
|
||||
encrypted_content = gnupg.GPG().encrypt(message.as_string(), recipients, armor=True)
|
||||
|
|
Loading…
Reference in a new issue