Browse Source

print and print and …

PYADPT-55
Volker Birk 6 years ago
parent
commit
fe0a232d6d
  1. 26
      test/sync_handshake.py
  2. 24
      test/sync_test.py

26
test/sync_handshake.py

@ -20,9 +20,12 @@ $ cd $DEV && HOME=$PWD lldb python3 -- ../sync_handshake.py -e $DEV
import pathlib import pathlib
import os import os
import sys import sys
import re
import pEp import pEp
import minimail import minimail
from datetime import datetime
try: try:
from termcolor import colored from termcolor import colored
except: except:
@ -36,12 +39,28 @@ output = print
DONT_TRIGGER_SYNC = 0x200 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("<payload>(.*)</payload>", msg.opt_fields["pEp.sync"])
print(m.group(1))
def messageToSend(msg): def messageToSend(msg):
if msg.enc_format: if msg.enc_format:
m, keys, rating, flags = msg.decrypt(DONT_TRIGGER_SYNC) m, keys, rating, flags = msg.decrypt(DONT_TRIGGER_SYNC)
else: else:
m = msg m = msg
text = "<!-- " + device_name + " -->\n" + m.attachments[0].decode() text = "<!-- sending from " + device_name + " -->\n" + m.attachments[0].decode()
output(text) output(text)
msg.opt_fields = { "pEp.sync": text } msg.opt_fields = { "pEp.sync": text }
minimail.send(inbox, msg, device_name) minimail.send(inbox, msg, device_name)
@ -71,7 +90,10 @@ def run(name, color=None):
l = minimail.recv_all(inbox, name) l = minimail.recv_all(inbox, name)
for m in l: for m in l:
msg = pEp.Message(m) msg = pEp.Message(m)
msg.decrypt() msg2, keys, rating, flags = msg.decrypt()
#text = "<!-- receiving on " + device_name + " -->\n" + msg2.attachments[0].decode()
#output(text)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass

24
test/sync_test.py

@ -119,29 +119,11 @@ if __name__ == "__main__":
shutil.copytree("Backup/TestInbox", "TestInbox", symlinks=True, copy_function=shutil.copy2) shutil.copytree("Backup/TestInbox", "TestInbox", symlinks=True, copy_function=shutil.copy2)
elif options.print: elif options.print:
import pEp from sync_handshake import print_msg
import re
from datetime import datetime
try:
from termcolor import colored
except:
colored = lambda x, y: x
inbox = pathlib.Path("TestInbox") inbox = pathlib.Path("TestInbox")
for p in reversed([ path for path in inbox.glob("*.eml") ]): for p in reversed([ path for path in inbox.glob("*.eml") ]):
with open(p, "rb") as f: print_msg(p)
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("<payload>(.*)</payload>", msg.opt_fields["pEp.sync"])
print(m.group(1))
else: else:
from multiprocessing import Process from multiprocessing import Process

Loading…
Cancel
Save