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
13
src/main.rs
13
src/main.rs
|
@ -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]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue