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(()) }