add feature to process multiple mailboxes #3

Merged
c4181 merged 3 commits from process-multiple-mailboxes into main 2024-09-21 21:15:19 +00:00
2 changed files with 17 additions and 6 deletions
Showing only changes of commit d1c3083a8f - Show all commits

View file

@ -15,7 +15,7 @@ appenders:
# Set the default logging level to "warn" and attach the "stdout" appender to the root # Set the default logging level to "warn" and attach the "stdout" appender to the root
root: root:
level: info level: debug
appenders: appenders:
- stdout - stdout

View file

@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::fmt::Display; use std::fmt::Display;
use std::net::TcpStream; use std::net::TcpStream;
use std::path::Path; use std::path::Path;
use log::{debug, info}; use log::{debug, error, info, warn};
use reqwest::blocking::Response; use reqwest::blocking::Response;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -31,7 +31,13 @@ fn process_mailbox(imap_ip: &str, mailbox: &Mailbox) {
} }
}; };
imap_session.select("INBOX").unwrap(); match imap_session.select("INBOX") {
Err(error) => {
error!("Unable to select INBOX: {}", error);
return;
}
_ => {}
}
let message = get_emails(&mut imap_session); let message = get_emails(&mut imap_session);
@ -105,11 +111,16 @@ fn get_emails(imap_session: &mut imap::Session<TcpStream>) -> Option<HashMap<u32
fn delete_emails(ordinals: Vec<u32>, imap_session: &mut imap::Session<TcpStream>) { fn delete_emails(ordinals: Vec<u32>, imap_session: &mut imap::Session<TcpStream>) {
for ordinal in ordinals { for ordinal in ordinals {
imap_session.store(format!("{}", ordinal), "+FLAGS (\\Deleted)") match imap_session.store(format!("{}", ordinal), "+FLAGS (\\Deleted)") {
.expect("Couldn't delete message"); Err(error) => warn!("Failed to delete message {ordinal}: {error}"),
_ => {}
}
} }
imap_session.expunge().unwrap(); match imap_session.expunge() {
Err(error) => warn!("Failed to expunge session: {error}"),
_ => {}
}
} }
fn post_to_hookshot(hookshot_url: &str, email: &Email) -> reqwest::Result<Response> { fn post_to_hookshot(hookshot_url: &str, email: &Email) -> reqwest::Result<Response> {