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

@ -17,31 +17,28 @@ fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
let domain = std::env::var("IMAP_DOMAIN").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 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 mut imap_session = client
.login(username, password)
.map_err(|e| e.0)?;
let mut imap_session = client.login(username, password).map_err(|e| e.0)?;
let inbox = imap_session.select("Inbox")?;
let re = Regex::new(format!("({})+", &pattern).as_str()).unwrap();
let subject = Regex::new(r"Subject: (.*)").unwrap();
for i in 1 as u32..inbox.exists {
let messages = imap_session.fetch( (inbox.exists-i).to_string(), "RFC822")?;
let message = if let Some(m) = messages.iter().next() {
m
} else {
return Ok(None);
};
let body = message.body().unwrap_or("NULL".as_bytes());
let body = std::str::from_utf8(body)
.unwrap_or("NULL")
.to_string();
if re.is_match(&body) {
imap_session.store(format!("{}", message.message), "+FLAGS (\\Deleted)").unwrap();
let subject_re = subject.captures(&body).unwrap();
println!("Deleted Mail with Subject: {}", &subject_re[1]);
}
let messages = imap_session.fetch((inbox.exists - i).to_string(), "RFC822")?;
let message = if let Some(m) = messages.iter().next() {
m
} else {
return Ok(None);
};
let body = message.body().unwrap_or("NULL".as_bytes());
let body = std::str::from_utf8(body).unwrap_or("NULL").to_string();
if re.is_match(&body) {
imap_session
.store(format!("{}", message.message), "+FLAGS (\\Deleted)")
.unwrap();
let subject_re = subject.captures(&body).unwrap();
println!("Deleted Mail with Subject: {}", &subject_re[1]);
}
}
imap_session.expunge().unwrap();
imap_session.logout()?;