Added thing
This commit is contained in:
parent
8cc8561e6a
commit
2a28b63c08
|
@ -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> {
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue