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,14 +19,11 @@ fn fetch_inbox_top() -> imap::error::Result<Option<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 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
@ -34,11 +31,11 @@ fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
return Ok(None);
};
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) {
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();
println!("Deleted Mail with Subject: {}", &subject_re[1]);
}