Browse Source

print and print and …

PYADPT-55
Volker Birk 6 years ago
parent
commit
fe0a232d6d
  1. 26
      test/sync_handshake.py
  2. 22
      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 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("<payload>(.*)</payload>", 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 = "<!-- " + device_name + " -->\n" + m.attachments[0].decode()
text = "<!-- sending from " + device_name + " -->\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 = "<!-- receiving on " + device_name + " -->\n" + msg2.attachments[0].decode()
#output(text)
except KeyboardInterrupt:
pass

22
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("<payload>(.*)</payload>", msg.opt_fields["pEp.sync"])
print(m.group(1))
print_msg(p)
else:
from multiprocessing import Process

Loading…
Cancel
Save