From 61d1182acb8937cdb727e194bbc0166b84f53b56 Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Sat, 10 Jul 2021 03:45:56 +0000 Subject: [PATCH] Use commandline args for credentials and pattern `Use cargo run username password pattern` to execute Signed-off-by: baalajimaestro --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index c89d1ff..438b0c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,12 +17,15 @@ fn main() { fn fetch_inbox_top() -> imap::error::Result> { let domain = "imap.mail.com"; + let username = std::env::args().nth(1).expect("no username given"); + let password = std::env::args().nth(2).expect("no password given"); + let pattern = std::env::args().nth(3).expect("no pattern given"); let client = imap::ClientBuilder::new(domain, 993).native_tls()?; let mut imap_session = client - .login("mail username", "mail pwd") + .login(username, password) .map_err(|e| e.0)?; let inbox = imap_session.select("Inbox")?; - let re = Regex::new(r"(insert string in message body, even 1 matching would do)+").unwrap(); + let re = Regex::new(format!("({})+", &pattern).as_str()).unwrap(); for i in 1 as u32..inbox.exists { let messages = imap_session.fetch( (inbox.exists-i).to_string(), "RFC822")?;