use concat_with::concat_line; use mime_msg_builder::{process, CompilerBuilder, TplBuilder}; use regex::Regex; fn main() { let tpl = TplBuilder::default() .from("alice@localhost") .to("bob@localhost") .subject("Subject: Sending signed message with rust-mml") .text_plain_part(concat_line!( "<#part type=text/plain sign=command>", "This is an signed message!", "<#/part>", )) .build(); let mime_msg = tpl.compile( CompilerBuilder::default() .pgp_sign_cmd("gpg -saq -o - --recipient-file ./examples/keys/alice.key"), ); let mime_msg = String::from_utf8_lossy(&mime_msg.unwrap()).to_string(); let signature = Regex::new(r"(-*BEGIN PGP MESSAGE-*(?s:.)*-*END PGP MESSAGE-*)").unwrap(); let signature = signature.captures_iter(&mime_msg).next().unwrap(); let (_, code) = process::pipe( "gpg --verify --recipient-file ./tests/keys/alice.pub", signature[0].as_bytes(), ) .unwrap(); println!(""); println!("================================"); println!("TEMPLATE"); println!("================================"); println!(""); println!("{}", *tpl); println!(""); println!("================================"); println!("COMPILED MIME MESSAGE"); println!("================================"); println!(""); println!("{}", mime_msg); println!(""); println!("================================"); println!("SIGNATURE VERIFIED"); println!("================================"); println!(""); println!("{}", code == 0); }