From daa53a059daf0d57dd6dbb05b7cbd20528903b93 Mon Sep 17 00:00:00 2001 From: teldra Date: Mon, 26 Aug 2019 04:41:46 +0200 Subject: [PATCH 1/2] outputfile and i3blocks command via argument --- src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 063917d..adc6154 100644 --- a/src/main.rs +++ b/src/main.rs @@ -296,14 +296,19 @@ fn main() { for (i, num_unseen) in rx { unseen[i] = num_unseen; - let mut file = std::fs::File::create("/tmp/mails").expect("create failed"); + let output_path = ::std::env::args().nth(1).unwrap(); + let commands = ::std::env::args().nth(2).unwrap(); + let mut file = std::fs::File::create(&output_path).expect("create failed"); file.write_all(num_unseen.to_string().as_bytes()).expect( "write failed", ); - Command::new("pkill") - .arg("-RTMIN+2") - .arg("i3blocks") - .spawn() - .expect("pkill command failed to start"); + Command::new("sh").arg("-c").arg(&commands).spawn().expect( + "command failed to start", + ); + // Command::new("pkill") + // .arg("-RTMIN+2") + // .arg("i3blocks") + // .spawn() + // .expect("pkill command failed to start"); } } From 3bbfd34ea9ea5a85438783b58438ad179306db2a Mon Sep 17 00:00:00 2001 From: teldra Date: Mon, 26 Aug 2019 10:53:24 +0200 Subject: [PATCH 2/2] del unused crust --- src/main.rs | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) diff --git a/src/main.rs b/src/main.rs index adc6154..aed1de2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,8 +9,6 @@ extern crate xdg; use native_tls::{TlsConnector, TlsStream}; use rayon::prelude::*; -use std::borrow::Cow; -use std::collections::BTreeMap; use std::fs::File; use std::io::prelude::*; use std::net::TcpStream; @@ -105,56 +103,6 @@ impl Connection { } last_notified = std::cmp::max(last_notified, uids.iter().cloned().max().unwrap_or(0)); - let mut subjects = BTreeMap::new(); - if !uids.is_empty() { - let uids: Vec<_> = uids.into_iter().map(|v: u32| format!("{}", v)).collect(); - for msg in self.socket - .uid_fetch(&uids.join(","), "RFC822.HEADER")? - .iter() - { - let msg = msg.header(); - if msg.is_none() { - continue; - } - - match mailparse::parse_headers(msg.unwrap()) { - Ok((headers, _)) => { - use mailparse::MailHeaderMap; - - let subject = match headers.get_first_value("Subject") { - Ok(Some(subject)) => Cow::from(subject), - Ok(None) => Cow::from(""), - Err(e) => { - println!("failed to get message subject: {:?}", e); - continue; - } - }; - - let date = match headers.get_first_value("Date") { - Ok(Some(date)) => { - match chrono::DateTime::parse_from_rfc2822(&date) { - Ok(date) => date.with_timezone(&chrono::Local), - Err(e) => { - println!("failed to parse message date: {:?}", e); - chrono::Local::now() - } - } - } - Ok(None) => chrono::Local::now(), - Err(e) => { - println!("failed to get message date: {:?}", e); - continue; - } - }; - - subjects.insert(date, subject); - } - Err(e) => println!("failed to parse headers of message: {:?}", e), - } - } - } - - tx.send((account, num_unseen)).unwrap(); // IDLE until we see changes