Browse Source

add own-identities to imap sync_handsjake

master
David 6 years ago
parent
commit
09abd3e5f2
  1. 47
      test/sync_handshake.py

47
test/sync_handshake.py

@ -77,11 +77,7 @@ def print_msg(p):
raise TypeError("print_msg(): pathlib.Path and pEp.Message supported, but " raise TypeError("print_msg(): pathlib.Path and pEp.Message supported, but "
+ str(type(p)) + " delivered") + str(type(p)) + " delivered")
m = False m = re.search("<keysync>(.*)</keysync>", msg.opt_fields["pEp.sync"].replace("\n", " "))
if msg.opt_fields.get("pEp.sync"):
m = re.search("<keysync>(.*)</keysync>", msg.opt_fields["pEp.sync"].replace("\n", " "))
if m: if m:
if etree: if etree:
tree = objectify.fromstring(m.group(1).replace("\r", "")) tree = objectify.fromstring(m.group(1).replace("\r", ""))
@ -90,31 +86,18 @@ def print_msg(p):
text = m.group(1).replace("\r", "").strip() text = m.group(1).replace("\r", "").strip()
while text.count(" "): while text.count(" "):
text = text.replace(" ", " ") text = text.replace(" ", " ")
print('-- BEACON --')
print(text) print(text)
def messageToSend(msg): def messageToSend(msg):
if msg.enc_format: msg = add_debug_info(msg)
m, keys, rating, flags = msg.decrypt(DONT_TRIGGER_SYNC)
else:
m = msg
text = "<!-- sending from " + device_name + " -->\n" + m.attachments[0].decode()
output(text)
msg.opt_fields = { "pEp.sync": text }
minimail.send(inbox, msg, device_name) minimail.send(inbox, msg, device_name)
def messageImapToSend(msg): def messageImapToSend(msg):
if msg.enc_format: msg = add_debug_info(msg)
m, keys, rating, flags = msg.decrypt(DONT_TRIGGER_SYNC)
else:
m = msg
text = "<!-- sending from " + device_name + " -->\n" + m.attachments[0].decode()
output(text)
msg.opt_fields = { "pEp.sync": text }
miniimap.send('Inbox', msg) miniimap.send('Inbox', msg)
def getMessageToSend(msg): def add_debug_info(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:
@ -124,6 +107,7 @@ def getMessageToSend(msg):
msg.opt_fields = { "pEp.sync": text } msg.opt_fields = { "pEp.sync": text }
return msg return msg
class UserInterface(pEp.UserInterface): class UserInterface(pEp.UserInterface):
def notifyHandshake(self, me, partner, signal): def notifyHandshake(self, me, partner, signal):
print(colored(str(signal), "yellow"), end=" ") print(colored(str(signal), "yellow"), end=" ")
@ -159,7 +143,7 @@ def shutdown_sync():
pEp.shutdown_sync() pEp.shutdown_sync()
def run(name, color=None, imap=False): def run(name, color=None, imap=False, own_ident=1):
global device_name global device_name
device_name = name device_name = name
@ -180,9 +164,16 @@ def run(name, color=None, imap=False):
else: else:
me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman", name) me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman", name)
pEp.myself(me) pEp.myself(me)
pEp.messageToSend = messageToSend
if own_ident >= 2:
me2 = pEp.Identity("alice@pep.security", name + " of Alice Neuman", name)
pEp.myself(me2)
if own_ident == 3:
me3 = pEp.Identity("alice@pep.foundation", name + " of Alice Neuman", name)
pEp.myself(me3)
pEp.messageToSend = messageToSend
if multithreaded: if multithreaded:
from threading import Thread from threading import Thread
@ -240,12 +231,17 @@ if __name__=="__main__":
optParser.add_option("-i", "--imap", action="store_true", optParser.add_option("-i", "--imap", action="store_true",
dest="imap", dest="imap",
help="use imap instead of minimail") help="use imap instead of minimail")
optParser.add_option("-o", "--own-identities", type="int", dest="own_ident",
help="simulate having OWN_IDENT own identities (1 to 3)", default=1)
options, args = optParser.parse_args() options, args = optParser.parse_args()
if not options.exec_for: if not options.exec_for:
options.exec_for = os.path.basename(os.getcwd()) options.exec_for = os.path.basename(os.getcwd())
if options.own_ident < 1 or options.own_ident > 3:
raise ValueError("illegal number of own identities (allowed are 1 to 3)")
if options.notifications: if options.notifications:
end_on = eval(options.notifications) end_on = eval(options.notifications)
try: None in end_on try: None in end_on
@ -255,6 +251,9 @@ if __name__=="__main__":
if options.noend: if options.noend:
end_on = (None,) end_on = (None,)
if options.imap and options.own_ident >1:
raise ValueError("Multiple own identities not supported for imap mode")
multithreaded = options.multithreaded multithreaded = options.multithreaded
run(options.exec_for, options.color, options.imap) run(options.exec_for, options.color, options.imap)

Loading…
Cancel
Save