Added thing

This commit is contained in:
vanten-s 2024-08-28 12:12:09 +02:00
parent 8cc8561e6a
commit 2a28b63c08
Signed by: vanten-s
GPG key ID: DE3060396884D3F2
2 changed files with 9 additions and 2 deletions

View file

@ -8,6 +8,7 @@ pub(crate) struct Config {
pub access_token: String, pub access_token: String,
pub channel: String, pub channel: String,
pub homeserver: String, pub homeserver: String,
pub target: String,
} }
pub(crate) fn get_config(file: Option<&str>) -> Result<Config> { pub(crate) fn get_config(file: Option<&str>) -> Result<Config> {

View file

@ -48,15 +48,21 @@ extern "C" fn message_handler_wrapper(message: *const c_char) {
} }
async fn message_handler(message: String) -> Result<()> { async fn message_handler(message: String) -> Result<()> {
let config = get_config();
let message = MessageParser::default().parse(&message).unwrap(); let message = MessageParser::default().parse(&message).unwrap();
let message_body = message.body_text(0).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() .address()
.unwrap(); .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?; send_message(&message).await?;
Ok(()) Ok(())
} }