From 2a28b63c08be935f4dc313ca82e7a1be01095edc Mon Sep 17 00:00:00 2001 From: vanten-s Date: Wed, 28 Aug 2024 12:12:09 +0200 Subject: [PATCH] Added thing --- src/config.rs | 1 + src/lib.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 10a497f..d409276 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,6 +8,7 @@ pub(crate) struct Config { pub access_token: String, pub channel: String, pub homeserver: String, + pub target: String, } pub(crate) fn get_config(file: Option<&str>) -> Result { diff --git a/src/lib.rs b/src/lib.rs index a1f56f4..cea6196 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,15 +48,21 @@ extern "C" fn message_handler_wrapper(message: *const c_char) { } async fn message_handler(message: String) -> Result<()> { + let config = get_config(); + let message = MessageParser::default().parse(&message).unwrap(); let message_body = message.body_text(0).unwrap(); - let message_sender = message.sender().unwrap().as_list().unwrap()[0] + let message_sender = message.from().unwrap().as_list().unwrap()[0] .address() .unwrap(); - let message = format!("New mail from {message_sender}:\n{message_body}"); + if message.to().unwrap().first().unwrap().address().unwrap() != &config.target { + return Ok(()); + } + let message = format!("New mail from {message_sender}:\n{message_body}"); + send_message(&message).await?; Ok(()) }