Run cargo fmt

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-08-22 11:00:15 +05:30
parent 792d27d9eb
commit a112607d40
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -19,26 +19,23 @@ fn fetch_inbox_top() -> imap::error::Result<Option<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 pattern = std::env::var("DELETE_PATTERN").unwrap_or("none".to_string()); let pattern = std::env::var("DELETE_PATTERN").unwrap_or("none".to_string());
let client = imap::ClientBuilder::new(domain, 993).native_tls()?; let client = imap::ClientBuilder::new(domain, 993).native_tls()?;
let mut imap_session = client let mut imap_session = client.login(username, password).map_err(|e| e.0)?;
.login(username, password)
.map_err(|e| e.0)?;
let inbox = imap_session.select("Inbox")?; let inbox = imap_session.select("Inbox")?;
let re = Regex::new(format!("({})+", &pattern).as_str()).unwrap(); let re = Regex::new(format!("({})+", &pattern).as_str()).unwrap();
let subject = Regex::new(r"Subject: (.*)").unwrap(); let subject = Regex::new(r"Subject: (.*)").unwrap();
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) let body = std::str::from_utf8(body).unwrap_or("NULL").to_string();
.unwrap_or("NULL")
.to_string();
if re.is_match(&body) { if re.is_match(&body) {
imap_session.store(format!("{}", message.message), "+FLAGS (\\Deleted)").unwrap(); imap_session
.store(format!("{}", message.message), "+FLAGS (\\Deleted)")
.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]);
} }