make decoding emails optional
This commit is contained in:
parent
224de12f09
commit
f5a0d3fdde
1 changed files with 14 additions and 9 deletions
23
gpgmymail
23
gpgmymail
|
@ -223,7 +223,8 @@ def encrypt(
|
||||||
*,
|
*,
|
||||||
unconditionally_encrypt: bool = False,
|
unconditionally_encrypt: bool = False,
|
||||||
encoding: str = DEFAULT_ENCODING,
|
encoding: str = DEFAULT_ENCODING,
|
||||||
ignore_errors: bool = False
|
ignore_errors: bool = False,
|
||||||
|
decode_before_encrypting: bool = False
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Encrypt given message
|
"""Encrypt given message
|
||||||
|
|
||||||
|
@ -262,13 +263,14 @@ def encrypt(
|
||||||
# make necessary changes to message
|
# make necessary changes to message
|
||||||
# this function is quite clunky and seems to throw exceptions from time to
|
# this function is quite clunky and seems to throw exceptions from time to
|
||||||
# time; if we can't make the necessary changes we want to just continue
|
# time; if we can't make the necessary changes we want to just continue
|
||||||
try:
|
if decode_before_encrypting:
|
||||||
message = decode_email(message)
|
try:
|
||||||
except Exception as e:
|
message = decode_email(message)
|
||||||
if ignore_errors:
|
except Exception as e:
|
||||||
pass
|
if ignore_errors:
|
||||||
else:
|
pass
|
||||||
raise e
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
gpg = gnupg.GPG()
|
gpg = gnupg.GPG()
|
||||||
gpg.encoding = encoding
|
gpg.encoding = encoding
|
||||||
|
@ -331,6 +333,8 @@ def main() -> None:
|
||||||
help="Encrypt mail unconditionally. By default, mail is not encrypted if it is already encrypted.")
|
help="Encrypt mail unconditionally. By default, mail is not encrypted if it is already encrypted.")
|
||||||
parser.add_argument('--ignore-errors', action="store_true",
|
parser.add_argument('--ignore-errors', action="store_true",
|
||||||
help="Ignore errors at certain error-prone points of the script.")
|
help="Ignore errors at certain error-prone points of the script.")
|
||||||
|
parser.add_argument('--decode', action="store_true",
|
||||||
|
"Attempt to decode quoted-printable and base64 parts to latin-1 before encrypting a message")
|
||||||
parser.add_argument('recipient', nargs='*',
|
parser.add_argument('recipient', nargs='*',
|
||||||
help="Key ID or email of keys to encrypt for")
|
help="Key ID or email of keys to encrypt for")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -344,7 +348,8 @@ def main() -> None:
|
||||||
args.recipient,
|
args.recipient,
|
||||||
unconditionally_encrypt=args.unconditional,
|
unconditionally_encrypt=args.unconditional,
|
||||||
encoding=args.encoding,
|
encoding=args.encoding,
|
||||||
ignore_errors=args.ignore_errors
|
ignore_errors=args.ignore_errors,
|
||||||
|
decode_before_encrypting=args.decode
|
||||||
))
|
))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue