From 86f21fbe528083d95ef93e9c92fd9fd4564990be Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 15 Sep 2019 23:37:14 +0300 Subject: [PATCH] ui: xbiff(1) support --- ui/src/components/notifications.rs | 16 ++++++++++++++++ ui/src/conf/notifications.rs | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs index 706275bdf..8f9b11c17 100644 --- a/ui/src/components/notifications.rs +++ b/ui/src/components/notifications.rs @@ -152,6 +152,22 @@ impl Component for NotificationFilter { debug!("{:?}", v); } } + + match kind { + Some(NotificationType::NewMail) => { + if let Some(ref path) = context.runtime_settings.notifications.xbiff_file_path { + let mut file = std::fs::OpenOptions::new().append(true) /* writes will append to a file instead of overwriting previous contents */ + .create(true) /* a new file will be created if the file does not yet already exist.*/ + .open(path).unwrap(); + if file.metadata().unwrap().len() > 128 { + file.set_len(0).unwrap(); + } else { + std::io::Write::write_all(&mut file, b"z").unwrap(); + } + } + } + _ => {} + } } false } diff --git a/ui/src/conf/notifications.rs b/ui/src/conf/notifications.rs index c450e2b4e..beeac0812 100644 --- a/ui/src/conf/notifications.rs +++ b/ui/src/conf/notifications.rs @@ -33,6 +33,11 @@ pub struct NotificationsSettings { /// Default: None #[serde(default = "none")] pub script: Option, + /// A file location which has its size changed when new mail arrives (max 128 bytes). Can be + /// used to trigger new mail notifications eg with `xbiff(1)` + /// Default: None + #[serde(default = "none")] + pub xbiff_file_path: Option, #[serde(deserialize_with = "toggleflag_de", default = "internal_value_false")] pub play_sound: super::ToggleFlag, #[serde(default = "none")]