Run cargo fmt
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
792d27d9eb
commit
a112607d40
1 changed files with 17 additions and 20 deletions
37
src/main.rs
37
src/main.rs
|
@ -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()?;
|
||||
|
|
Loading…
Reference in a new issue