def test_simple(self, mycmd, gen_mail): mycmd.run_ok(["init"]) mail = gen_mail() out1 = mycmd.run_ok(["process-outgoing"], input=mail.as_string()) m = mime.parse_message_from_string(out1) assert len(m.get_all("Autocrypt")) == 1 found_header = "Autocrypt: " + m["Autocrypt"] gen_header = mycmd.run_ok(["make-header", "*****@*****.**"]) x1 = mime.parse_one_ac_header_from_string(gen_header) x2 = mime.parse_one_ac_header_from_string(found_header) assert x1 == x2
def test_simple_dont_replace(self, mycmd, gen_mail): mycmd.run_ok(["init"]) mail = gen_mail() gen_header = mycmd.run_ok(["make-header", "*****@*****.**"]) mail.add_header("Autocrypt", gen_header) out1 = mycmd.run_ok(["process-outgoing"], input=mail.as_string()) m = mime.parse_message_from_string(out1) assert len(m.get_all("Autocrypt")) == 1 x1 = mime.parse_ac_headervalue(m["Autocrypt"]) x2 = mime.parse_ac_headervalue(gen_header) assert x1 == x2
def test_sendmail(self, mycmd, gen_mail, popen_mock): mycmd.run_ok(["init"]) mail = gen_mail().as_string() pargs = ["-oi", "*****@*****.**"] mycmd.run_ok(["sendmail", "-f", "--"] + pargs, input=mail) assert len(popen_mock.calls) == 1 call = popen_mock.pop_next_call() for x in pargs: assert x in call.args # make sure unknown option is passed to pipe assert "-f" in call.args out_msg = mime.parse_message_from_string(call.input) assert "Autocrypt" in out_msg, out_msg.as_string()
def test_matching_identity(self, mycmd, gen_mail): mycmd.run_ok(["init", "--no-identity"]) mycmd.run_ok(["add-identity", "ident1", "[email protected]"]) mail = gen_mail(From="*****@*****.**") mycmd.run_fail(["process-outgoing"], input=mail.as_string(), fnl=""" *IdentityNotFound*[email protected]* """) mail = gen_mail(From="*****@*****.**") out1 = mycmd.run_ok(["process-outgoing"], input=mail.as_string()) msg2 = mime.parse_message_from_string(out1) assert "*****@*****.**" in msg2["Autocrypt"]
def test_reply_no_autocrypt(self, bcmd): adr = "*****@*****.**" msg = mime.gen_mail_msg( From=adr, To=[bcmd.bot_adr], Autocrypt=None, Subject="hello", _dto=True) out = bcmd.run_ok(["bot-reply"], input=msg.as_string()) reply_msg = mime.parse_message_from_string(out) assert reply_msg["Subject"] == "Re: " + msg["Subject"] assert reply_msg["Autocrypt"] body = decode_body(reply_msg) print(body) assert "no autocrypt header" in body.lower()
def test_reply_no_delivto(self, bcmd, ac_sender, linematch): send_adr = ac_sender.adr msg = mime.gen_mail_msg(From=send_adr, To=[bcmd.bot_adr], Subject="hello") out = bcmd.run_ok(["bot-reply", "--fallback-delivto", bcmd.bot_adr], input=msg.as_string()) reply_msg = mime.parse_message_from_string(out) linematch(decode_body(reply_msg), """ *processed*identity*default* """) assert reply_msg["Subject"] == "Re: " + msg["Subject"] assert reply_msg["From"] == bcmd.bot_adr assert reply_msg["To"] == msg["From"] assert reply_msg["Autocrypt"]
def test_process_incoming(self, mycmd, datadir): mycmd.run_ok(["init", "--no-identity"]) mycmd.run_ok(["add-identity", "ident1", "[email protected]"]) mail = datadir.read("rsa2048-simple.eml") mycmd.run_fail(["process-incoming"], """ *IdentityNotFound*[email protected]* """, input=mail) msg = mime.parse_message_from_string(mail) msg.replace_header("Delivered-To", "*****@*****.**") newmail = msg.as_string() out = mycmd.run_ok(["process-incoming"], """ *processed*identity*ident1* """, input=newmail) # now export the public key m = re.search(r'key (\w+) ', out) keyhandle, = m.groups() mycmd.run_ok(["export-public-key", "--id=ident1", keyhandle]) mycmd.run_ok(["status"])
def test_reply_with_autocrypt(self, bcmd, ac_sender, linematch): send_adr = ac_sender.adr msg = mime.gen_mail_msg( From=send_adr, To=[bcmd.bot_adr], Autocrypt=ac_sender.ac_headerval, Subject="hello", _dto=True) out = bcmd.run_ok(["bot-reply"], input=msg.as_string()) reply_msg = mime.parse_message_from_string(out) linematch(decode_body(reply_msg), """ *processed*identity*default* """) assert reply_msg["Subject"] == "Re: " + msg["Subject"] assert reply_msg["From"] == bcmd.bot_adr assert reply_msg["To"] == msg["From"] assert reply_msg["Autocrypt"] ac_dict = mime.parse_ac_headervalue(reply_msg["Autocrypt"]) assert ac_dict["to"] == bcmd.bot_adr assert ac_dict["key"] body = decode_body(reply_msg) assert "no Autocrypt header" not in body print(body)
def test_render(datadir): msg = mime.parse_message_from_string(datadir.read("rsa2048-simple.eml")) x = mime.render_mime_structure(msg) assert "text/plain" in x
def test_parse_message_from_string(datadir): msg = mime.parse_message_from_string(datadir.read("rsa2048-simple.eml")) assert msg.get_all("Autocrypt") assert msg.get_payload()