From fc69f77923137a8b8f066023c150e3b8de2cb586 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 12 Oct 2020 01:41:05 +0200 Subject: [PATCH] Allow saving attachment without running a plumber Add a second (optional) positional argument to specify the destination file. If a file has been specified, just save without running the default plumber. Specifying a custom plumber allows to both save and run the plumber. --- contrib/matrix_decrypt.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/contrib/matrix_decrypt.py b/contrib/matrix_decrypt.py index 6adc8b1..8196a8e 100755 --- a/contrib/matrix_decrypt.py +++ b/contrib/matrix_decrypt.py @@ -44,6 +44,7 @@ def main(): description='Download and decrypt matrix attachments' ) parser.add_argument('url', help='the url of the attachment') + parser.add_argument('file', nargs='?', help='save attachment to ') parser.add_argument('--plumber', help='program that gets called with the ' 'dowloaded file') @@ -68,11 +69,19 @@ def main(): print("Error downloading file") return -2 - plumber = args.plumber or "/usr/bin/rifle" + plumber = args.plumber plaintext = decrypt_attachment(request.content, key, hash, iv) - file_name = save_file(plaintext) - subprocess.run([plumber, "{file}".format(file=file_name)]) + if args.file is None: + file_name = save_file(plaintext) + if plumber is None: + plumber = "/usr/bin/rifle" + else: + file_name = args.file + open(file_name, "wb").write(plaintext) + + if plumber is not None: + subprocess.run([plumber, "{file}".format(file=file_name)]) return 0