From 8c80d252d0af219f1938ad5271279f6966146967 Mon Sep 17 00:00:00 2001 From: Jack Chakany Date: Mon, 23 Sep 2024 11:44:49 -0400 Subject: [PATCH] pushing changes --- Cargo.toml | 2 +- shell.nix | 26 ++++++++++++++++++++++++++ src/mail_event.rs | 34 ++++++++++++++++++++++++++++++++++ src/main.rs | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 shell.nix create mode 100644 src/mail_event.rs diff --git a/Cargo.toml b/Cargo.toml index 44981e5..0214af0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,6 @@ puffin_http = { version = "0.16.0", optional = true } ewebsock = { version = "0.6.0", features = ["tls"] } nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "ee8afeeb0b6695fca6d27dd0b74a8dc159e37b95" } rand = "0.8.5" -nostr = { version = "0.32.1", features = ["std"] } +nostr = { version = "0.32.1", features = ["std", "nip59"] } serde = "1.0.204" serde_json = "1.0.121" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..65d9d45 --- /dev/null +++ b/shell.nix @@ -0,0 +1,26 @@ +{ pkgs ? import { } +}: +with pkgs; + +let + x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers libxkbcommon ]; +in +mkShell ({ + nativeBuildInputs = [ + rustup + rustfmt + libiconv + pkg-config + fontconfig + ] ++ lib.optional stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Security + darwin.apple_sdk.frameworks.OpenGL + darwin.apple_sdk.frameworks.CoreServices + darwin.apple_sdk.frameworks.AppKit + ]; + +} // ( + lib.optionalAttrs (!stdenv.isDarwin) { + LD_LIBRARY_PATH = "${x11libs}"; + } +)) diff --git a/src/mail_event.rs b/src/mail_event.rs new file mode 100644 index 0000000..3f02062 --- /dev/null +++ b/src/mail_event.rs @@ -0,0 +1,34 @@ +use std::collections::HashMap; +use nostr::{EventBuilder, Event, PublicKey, Kind, Tag, Keys}; + +pub const MAIL_EVENT_KIND: u16 = 1059; + +pub struct MailMessage { + to: Vec, + cc: Vec, + bcc: Vec, + subject: String, + content: String, +} + +impl MailMessage { + pub fn to_events(&mut self, sending_keys: &Keys) -> HashMap { + let mut pubkeys_to_send_to: Vec = Vec::new(); + let mut tags: Vec = Vec::new(); + + for pubkey in &self.to { + tags.push(Tag::public_key(*pubkey)); + pubkeys_to_send_to.push(*pubkey); + } + + let base_event = EventBuilder::new(Kind::Custom(MAIL_EVENT_KIND), &self.content, []).to_unsigned_event(sending_keys.clone().public_key()); + + let mut event_list: HashMap = HashMap::new(); + for pubkey in pubkeys_to_send_to { + let wrapped_event = EventBuilder::gift_wrap(sending_keys, &pubkey, base_event.clone(), None).unwrap(); + event_list.insert(pubkey, wrapped_event); + } + + event_list + } +} diff --git a/src/main.rs b/src/main.rs index 164929b..ee456d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ mod error; mod keystorage; mod relay; mod ui; +mod mail_event; fn main() -> Result<(), eframe::Error> { let (non_blocking, _guard) = tracing_appender::non_blocking(std::io::stdout()); // add log files in prod one day