Run cargo fmt

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

View file

@ -17,7 +17,10 @@ fn main() {
fn fetch_inbox_top() -> imap::error::Result<Option<String>> { fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
let domain = std::env::var("IMAP_DOMAIN").unwrap_or("none".to_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 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 username = std::env::var("IMAP_USERNAME").unwrap_or("none".to_string());
let password = std::env::var("IMAP_PASSWORD").unwrap_or("none".to_string()); let password = std::env::var("IMAP_PASSWORD").unwrap_or("none".to_string());
let client = imap::ClientBuilder::new(domain, imap_port).native_tls()?; let client = imap::ClientBuilder::new(domain, imap_port).native_tls()?;
@ -33,24 +36,24 @@ fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
break; break;
} }
println!("Working on Pattern: {}", re.as_str()); println!("Working on Pattern: {}", re.as_str());
for i in 1 as u32..inbox.exists { for i in 1 as u32..inbox.exists {
let messages = imap_session.fetch((inbox.exists - i).to_string(), "RFC822")?; let messages = imap_session.fetch((inbox.exists - i).to_string(), "RFC822")?;
let message = if let Some(m) = messages.iter().next() { let message = if let Some(m) = messages.iter().next() {
m m
} else { } else {
return Ok(None); return Ok(None);
}; };
let body = message.body().unwrap_or("NULL".as_bytes()); let body = message.body().unwrap_or("NULL".as_bytes());
let body = std::str::from_utf8(body).unwrap_or("NULL").to_string(); let body = std::str::from_utf8(body).unwrap_or("NULL").to_string();
if re.is_match(&body) { if re.is_match(&body) {
imap_session imap_session
.store(format!("{}", message.message), "+FLAGS (\\Deleted)") .store(format!("{}", message.message), "+FLAGS (\\Deleted)")
.unwrap(); .unwrap();
let subject_re = subject.captures(&body).unwrap(); let subject_re = subject.captures(&body).unwrap();
println!("Deleted Mail with Subject: {}", &subject_re[1]); println!("Deleted Mail with Subject: {}", &subject_re[1]);
}
} }
} }
}
imap_session.expunge().unwrap(); imap_session.expunge().unwrap();
imap_session.logout()?; imap_session.logout()?;
println!("\n\n\n********PURGED ALL REQUESTED MAIL********"); println!("\n\n\n********PURGED ALL REQUESTED MAIL********");