Use a file to handle multiple patterns
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
bd5b25a9b8
commit
2ff13e7f97
1 changed files with 9 additions and 2 deletions
11
src/main.rs
11
src/main.rs
|
@ -8,6 +8,8 @@
|
|||
|
||||
use imap;
|
||||
use regex::Regex;
|
||||
use std::fs::File;
|
||||
use std::io::{self, prelude::*, BufReader};
|
||||
|
||||
fn main() {
|
||||
fetch_inbox_top().unwrap();
|
||||
|
@ -17,12 +19,16 @@ 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 client = imap::ClientBuilder::new(domain, 993).native_tls()?;
|
||||
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();
|
||||
let file = File::open("patterns.txt")?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
for line in reader.lines() {
|
||||
let re = Regex::new(format!("({})+", line?).as_str()).unwrap();
|
||||
println!("Working on Pattern: {}", re.as_str());
|
||||
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() {
|
||||
|
@ -40,6 +46,7 @@ fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
|
|||
println!("Deleted Mail with Subject: {}", &subject_re[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
imap_session.expunge().unwrap();
|
||||
imap_session.logout()?;
|
||||
Ok(Some("logout".to_string()))
|
||||
|
|
Loading…
Reference in a new issue