conform to pEp standards
This commit is contained in:
parent
0802cf5b3d
commit
182e1ceb43
1 changed files with 26 additions and 0 deletions
26
gpgmymail
26
gpgmymail
|
@ -42,6 +42,7 @@ import gnupg
|
|||
|
||||
# constants
|
||||
DEFAULT_ENCODING='utf-8' # default is latin-1 which fails w some unicode chars
|
||||
PEP_SUBJECT='=?utf-8?Q?p=E2=89=A1p?='
|
||||
|
||||
def is_message_encrypted(message: email.message.Message) -> bool:
|
||||
"""Determines whether or not an email message is encrypted.
|
||||
|
@ -169,6 +170,27 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
|||
|
||||
return decoded_bytes_to_return_value(decoded_bytes)
|
||||
|
||||
def set_email_header(
|
||||
message: email.message.Message,
|
||||
name: str,
|
||||
value: str
|
||||
) -> None:
|
||||
"""
|
||||
Set the header of an email Message. Will either replace the first instance
|
||||
of the header, or if the header is not present, will add the header.
|
||||
|
||||
Note: Python passes objects as references, so there is no need for a return
|
||||
value.
|
||||
|
||||
:param message: the Message object to be modified
|
||||
:param name: the email header to set
|
||||
:param value: the value to set the header to
|
||||
"""
|
||||
if message.get(name):
|
||||
message.replace_header(name, value)
|
||||
else:
|
||||
message.add_header(name, value)
|
||||
|
||||
def encrypt(
|
||||
message: email.message.Message,
|
||||
recipients: typing.List[str],
|
||||
|
@ -254,6 +276,10 @@ def encrypt(
|
|||
if key.lower() not in headers_not_to_override:
|
||||
encmsg[key] = value
|
||||
|
||||
# mark as confirming to pEp: https://blog.jak-linux.org/2019/06/13/encrypted-email-storage/#pretty-easy-privacy-pp
|
||||
set_email_header(encmsg, 'Subject', PEP_SUBJECT)
|
||||
set_email_header(encmsg, 'X-pEp-Version', '2.1')
|
||||
|
||||
return encmsg.as_string()
|
||||
|
||||
def decrypt(message: email.message.Message, *, encoding: str = DEFAULT_ENCODING) -> str:
|
||||
|
|
Loading…
Reference in a new issue