From b18ac50ef44cf071036fc178dfdf6ff1bd60ff16 Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Fri, 9 Jul 2021 11:04:35 +0000 Subject: [PATCH] Compile regex expression only once Signed-off-by: baalajimaestro --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 2c87279..c89d1ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ fn fetch_inbox_top() -> imap::error::Result> { .login("mail username", "mail pwd") .map_err(|e| e.0)?; let inbox = imap_session.select("Inbox")?; + let re = Regex::new(r"(insert string in message body, even 1 matching would do)+").unwrap(); for i in 1 as u32..inbox.exists { let messages = imap_session.fetch( (inbox.exists-i).to_string(), "RFC822")?; @@ -34,7 +35,6 @@ fn fetch_inbox_top() -> imap::error::Result> { let body = std::str::from_utf8(body) .unwrap_or("NULL") .to_string(); - let re = Regex::new(r"(insert string in message body, even 1 matching would do)+").unwrap(); if re.is_match(&body) { imap_session.store(format!("{}", message.message), "+FLAGS (\\Deleted)").unwrap(); println!("DELETED SPAM Target!");