Add a check to prevent purging everything

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-08-22 12:23:13 +05:30
parent 4d860b8d6a
commit 38a3fb72a6
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -17,9 +17,10 @@ fn main() {
fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
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::<u16>().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<Option<String>> {
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")?;