From fe0a232d6dffc89143baa1c1074eed475dff89b5 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Fri, 22 Mar 2019 16:57:00 +0100 Subject: [PATCH] =?UTF-8?q?print=20and=20print=20and=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/sync_handshake.py | 26 ++++++++++++++++++++++++-- test/sync_test.py | 24 +++--------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index dbbea1d..f28a9f5 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -20,9 +20,12 @@ $ cd $DEV && HOME=$PWD lldb python3 -- ../sync_handshake.py -e $DEV import pathlib import os import sys +import re import pEp import minimail +from datetime import datetime + try: from termcolor import colored except: @@ -36,12 +39,28 @@ output = print DONT_TRIGGER_SYNC = 0x200 +def print_msg(p): + if p.name[:5] == "Phone": + color = "red" + elif p.name[:6] == "Laptop": + color = "green" + else: + color = None + with open(p, "r") as f: + t = f.read(-1) + msg = pEp.Message(t) + print("\n" + colored(str(p), color)) + print(datetime.fromtimestamp(p.stat().st_mtime)) + m = re.search("(.*)", msg.opt_fields["pEp.sync"]) + print(m.group(1)) + + def messageToSend(msg): if msg.enc_format: m, keys, rating, flags = msg.decrypt(DONT_TRIGGER_SYNC) else: m = msg - text = "\n" + m.attachments[0].decode() + text = "\n" + m.attachments[0].decode() output(text) msg.opt_fields = { "pEp.sync": text } minimail.send(inbox, msg, device_name) @@ -71,7 +90,10 @@ def run(name, color=None): l = minimail.recv_all(inbox, name) for m in l: msg = pEp.Message(m) - msg.decrypt() + msg2, keys, rating, flags = msg.decrypt() + #text = "\n" + msg2.attachments[0].decode() + #output(text) + except KeyboardInterrupt: pass diff --git a/test/sync_test.py b/test/sync_test.py index 2c07aa8..96f01db 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -119,29 +119,11 @@ if __name__ == "__main__": shutil.copytree("Backup/TestInbox", "TestInbox", symlinks=True, copy_function=shutil.copy2) elif options.print: - import pEp - import re - from datetime import datetime - try: - from termcolor import colored - except: - colored = lambda x, y: x - + from sync_handshake import print_msg + inbox = pathlib.Path("TestInbox") for p in reversed([ path for path in inbox.glob("*.eml") ]): - with open(p, "rb") as f: - if p.name[:5] == "Phone": - color = "red" - elif p.name[:6] == "Laptop": - color = "green" - else: - color = None - t = f.read(-1) - msg = pEp.Message(t) - print("\n" + colored(str(p), color)) - print(datetime.fromtimestamp(p.stat().st_mtime)) - m = re.search("(.*)", msg.opt_fields["pEp.sync"]) - print(m.group(1)) + print_msg(p) else: from multiprocessing import Process