gpgmime

Create mail agent parseable email from a PGP message
git clone git://git.defalsify.org/gigmime.git
Log | Files | Refs | LICENSE

commit a1222d29b79ac6782f5715f354532d5a9e06c475
Author: lash <dev@holbrook.no>
Date:   Tue, 11 Oct 2022 14:26:03 +0000

Initial commit

Diffstat:
ACargo.toml | 11+++++++++++
Asrc/main.rs | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Atestdata/msg.txt | 4++++
Atestdata/msg.txt.asc | 16++++++++++++++++
Atestdata/msg.txt.gpg | 0
5 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "gpgmime" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +sequoia-openpgp = "1.10.0" +mail-builder = "0.2.2" +base64 = "0.13.0" diff --git a/src/main.rs b/src/main.rs @@ -0,0 +1,51 @@ +use std::io::Write; +use std::io::Read; +use std::fs::read; +use std::env::args; + +use sequoia_openpgp::parse::Parse; +use sequoia_openpgp::Message; +use sequoia_openpgp::serialize::SerializeInto; +use sequoia_openpgp::armor::Writer as ArmorWriter; +use sequoia_openpgp::armor::Kind; +use mail_builder::MessageBuilder; +use mail_builder::mime::MimePart; + +fn main() { + let mut argv = args(); + argv.next(); + let fp_s = argv.next().unwrap(); + let msg = Message::from_file(fp_s).unwrap(); + + let mut msg_w = ArmorWriter::new(Vec::new(), Kind::Message).unwrap(); + msg_w.write_all(msg.to_vec().unwrap().as_ref()); + let msg_b = msg_w.finalize().unwrap(); + let msg_s = String::from_utf8_lossy(&msg_b); + + let enc_version_part = MimePart::new_binary( + "application/pgp-encrypted", + "Version: 1".as_bytes(), + ); + + let enc_contents_part = MimePart::new_text_other( + "application/octet-stream", + msg_s, + ); + + let enc_envelope = MimePart::new_multipart( + "multipart/encrypted; protocol=\"application/pgp-encrypted\"", + vec![ + enc_version_part, + enc_contents_part, + ], + ) + .inline(); + + let eml = MessageBuilder::new() + .from(("Forro contact form", "no-reply@holbrook.no")) + .to(("Louis Holbrook", "l@holbrook.no")) + .subject("Rust pgp enc message bridge") + .body(enc_envelope); + + println!("{}", eml.write_to_string().unwrap()); +} diff --git a/testdata/msg.txt b/testdata/msg.txt @@ -0,0 +1,4 @@ +Content-Type: text/plain; charset="UTF-8" +Content-Disposition:inline + +foobar diff --git a/testdata/msg.txt.asc b/testdata/msg.txt.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP MESSAGE----- + +hQGMA1Xol6lCjZtiAQwAt9JFvcfdnysOfFUNxXbjfQLKZcw+qBpJBP6+vVlq6OlE +2XZkuVTtbrimyGQQcxDYdYPRzMPH1MrtuFfFzS0wbqeIJjJXlSroxb/hY+AXysoC +IW9yBncUFvKjh9jIGAAafIUODK4RUQnntS2dna3VSGVM9M0SABj1LGfJhmhnzKIV +533oDi++FnXxV2iekM/8VFgtfCqDmfotr2f7H5AfsIUrC24NJHpgzzvT63GST+Zq +mHfMvrVrtuajB07RXxguOfE06D7OsuRlz7v/hILOJ0ossXU/48leiOupI6nEMou6 +TepoArsBjiHUQfXJv9zA4Erd2oLqIN2299gg8VyPCtaQIVpkuRvoMOvNET4jQt0J +HYtU/rWEv99xRq6XuZkX4MX6W+9BtvHcdIzPuaeT3M5S8DEBJX7c9BNUqg7fdZ3h +worplIikVkRKyQ8USXQnfIMixmq+4MG1z9nj69xhJHnLlVSUcGafLwAkxeel4tFL +MRVqoDZfkksShgmHwTAI0okBiZM71M3A10CUKqryH9/Woq11TcGsftYFK955bM5d +pHjfYGz0u5JF48wCJ7hbX4mujvKp8X0rOMF1UUS0bt9o/RhBOYfuLRgeqoHBNNXN +I32sNnDJ7gQTw+gqFw3VyJ3vJrmDi9RbRCd99v+dnQO3bMtBr6OetVgzNj5/l20E +JX4Drq9u+2k6/w== +=DNsr +-----END PGP MESSAGE----- diff --git a/testdata/msg.txt.gpg b/testdata/msg.txt.gpg Binary files differ.