diff --git a/src/config.rs b/src/config.rs index f2b2686..02484f2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -65,6 +65,8 @@ pub struct GitlabWebhookConfig { #[derive(Clone, Deserialize)] pub struct MailListConfig { pub name: String, + #[serde(default = "default_true")] + pub publish_on_replies: bool, #[serde(default)] pub rooms: Vec, } @@ -89,6 +91,10 @@ pub struct Config { pub mail_archive: Option, } +fn default_true() -> bool { + true +} + fn load_blocking(path: &String) -> anyhow::Result { let f = File::open(path)?; let r = BufReader::new(f); diff --git a/src/mail_archive.rs b/src/mail_archive.rs index 38d7309..d229dd6 100644 --- a/src/mail_archive.rs +++ b/src/mail_archive.rs @@ -105,6 +105,7 @@ async fn handle_list( http_client: &reqwest::Client, url: &String, matrix_client: &Client, + publish_on_replies: bool, room_ids: &[OwnedRoomOrAliasId], ) -> anyhow::Result<()> { let list_state = load_list_state(state_file).await?; @@ -161,11 +162,15 @@ async fn handle_list( for room in rooms { for item in &items { - let msg = - RoomMessageEventContent::text_markdown(format!("\\[{}\\] [{}]({})", list.name, item.title, item.link)); - room.send(msg, None) - .await - .with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?; + if publish_on_replies || !item.title.starts_with("Re: ") { + let msg = RoomMessageEventContent::text_markdown(format!( + "\\[{}\\] [{}]({})", + list.name, item.title, item.link + )); + room.send(msg, None) + .await + .with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?; + } save_list_state( ListState { last_pub_date: item.pub_date.value, @@ -207,8 +212,16 @@ pub fn start_polling(config: MailArchiveConfig, matrix_client: Client) -> anyhow tokio::spawn(async move { if !room_ids.is_empty() { loop { - if let Err(err) = - handle_list(&list, &state_file, &http_client, &url, &matrix_client, &room_ids).await + if let Err(err) = handle_list( + &list, + &state_file, + &http_client, + &url, + &matrix_client, + list.publish_on_replies, + &room_ids, + ) + .await { warn!("{:#}", err); }