From 38a3fb72a63cc883f663e0efffb79027b197b93c Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Mon, 22 Aug 2022 12:23:13 +0530 Subject: [PATCH] Add a check to prevent purging everything Signed-off-by: baalajimaestro --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fb1c2a5..55eb3b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,9 +17,10 @@ fn main() { fn fetch_inbox_top() -> imap::error::Result> { let domain = std::env::var("IMAP_DOMAIN").unwrap_or("none".to_string()); + let imap_port = std::env::var("IMAP_PORT").unwrap_or("none".to_string()).parse::().unwrap(); let username = std::env::var("IMAP_USERNAME").unwrap_or("none".to_string()); let password = std::env::var("IMAP_PASSWORD").unwrap_or("none".to_string()); - let client = imap::ClientBuilder::new(domain, 993).native_tls()?; + let client = imap::ClientBuilder::new(domain, imap_port).native_tls()?; let mut imap_session = client.login(username, password).map_err(|e| e.0)?; let inbox = imap_session.select("Inbox")?; let subject = Regex::new(r"Subject: (.*)").unwrap(); @@ -28,6 +29,9 @@ fn fetch_inbox_top() -> imap::error::Result> { for line in reader.lines() { let re = Regex::new(format!("({})+", line?).as_str()).unwrap(); + if re.as_str() == "()+" { + break; + } println!("Working on Pattern: {}", re.as_str()); for i in 1 as u32..inbox.exists { let messages = imap_session.fetch((inbox.exists - i).to_string(), "RFC822")?;