diff --git a/pbincli/actions.py b/pbincli/actions.py index 43c721f..506e4be 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -22,15 +22,16 @@ def compress(s): return b64encode(''.join(map(chr, b)).encode('utf-8')) def send(args, api_client): - if args.stdin: - text = args.stdin.read() - elif args.text: - text = args.text - elif args.file: - text = "Sending a file to you!" - else: + if not args.notext: + if args.text: + text = args.text + elif args.stdin: + text = args.stdin.read() + elif not args.file: print("Nothing to send!") sys.exit(1) + else: + text = "" # Formatting request request = {'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)} @@ -61,8 +62,12 @@ def send(args, api_client): with open(args.file, "rb") as f: contents = f.read() f.close() - mime = guess_type(args.file) - if args.debug: print("Filename:\t{}\nMIME-type:\t{}".format(path_leaf(args.file), mime[0])) + mime = guess_type(args.file, strict=False)[0] + + # MIME fallback + if not mime: mime = "application/octet-stream" + + if args.debug: print("Filename:\t{}\nMIME-type:\t{}".format(path_leaf(args.file), mime)) file = "data:" + mime[0] + ";base64," + b64encode(contents).decode() filename = path_leaf(args.file) @@ -135,12 +140,16 @@ def get(args, api_client): if args.debug: print("Text:\t{}\n".format(data)) text = SJCL().decrypt(data, password) - print("{}\n".format(decompress(text.decode()))) - check_writable("paste.txt") - with open("paste.txt", "wb") as f: - f.write(decompress(text.decode())) - f.close + if args.debug: print("Decoded text size: {}\n".format(len(text))) + + if len(text): + print("{}\n".format(decompress(text.decode()))) + + check_writable("paste.txt") + with open("paste.txt", "wb") as f: + f.write(decompress(text.decode())) + f.close if 'attachment' in result and 'attachmentname' in result: print("Found file, attached to paste. Decoding it and saving") diff --git a/pbincli/cli.py b/pbincli/cli.py index d0000c3..bbd3c39 100755 --- a/pbincli/cli.py +++ b/pbincli/cli.py @@ -34,6 +34,7 @@ def main(): send_parser.add_argument("-F", "--format", default="plaintext", action="store", choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of text (default: plaintext)") send_parser.add_argument("-t", "--text", help="comment in quotes. Ignored if used stdin") + send_parser.add_argument("-q", "--notext", default=False, action="store_true", help="don't send text in paste") send_parser.add_argument("-p", "--password", help="password for encrypting paste") send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug") send_parser.add_argument("--dry", default=False, action="store_true", help="invoke dry run")