From 5cdd18fb72ef281c827fbe8d6d7f0171f432c6db Mon Sep 17 00:00:00 2001 From: lelgenio Date: Mon, 7 Feb 2022 20:05:28 -0300 Subject: [PATCH] minor cleanup --- src/main.rs | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index ec2a0bf..a65181c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use hotwatch::blocking::{ Flow, Hotwatch, @@ -9,35 +11,28 @@ use mailparse::{ use notify_rust::Notification; fn main() { - let args = std::env::args(); // .collect::>(); - // let path = args.get(1).expect("No path provided, exiting"); - let mut hotwatch = Hotwatch::new_with_custom_delay(std::time::Duration::from_secs(0)) .expect("hotwatch failed to initialize!"); - println!("starting"); - - for arg in args { + std::env::args().for_each(|arg| { hotwatch .watch(arg, handle_event) .expect("hotwatch failed to initialize!"); - } + }); + hotwatch.run(); - println!("exiting"); } fn handle_event(event: hotwatch::Event) -> hotwatch::blocking::Flow { - _handle_event(event); + if let hotwatch::Event::Create(newfile) = event { + _handle_event(newfile) + }; + Flow::Continue } -fn _handle_event(event: hotwatch::Event) { - let newfile = match dbg! {event} { - hotwatch::Event::Create(newfile) => newfile, - _ => return, - }; - +fn _handle_event(newfile: PathBuf) { let raw_content = match std::fs::read_to_string(&newfile) { Ok(c) => c, Err(e) => { @@ -64,8 +59,6 @@ fn _handle_event(event: hotwatch::Event) { let headers = mail_content.get_headers(); - eprintln!("getting from field"); - let from = match headers.get_first_value("From") { Some(f) => f, None => { @@ -74,8 +67,6 @@ fn _handle_event(event: hotwatch::Event) { } }; - eprintln!("getting subject field"); - let subject = match headers.get_first_value("Subject") { Some(sub) => sub, None => mail_content @@ -88,10 +79,6 @@ fn _handle_event(event: hotwatch::Event) { .to_string(), }; - eprintln!("setting subject field to {}", &subject); - - eprintln!("showing notification"); - Notification::new() .summary(&format!("From: {}", from)) .body(&format!("Subject: {}", subject))