add better error handling

This commit is contained in:
Christopher Moyer 2024-05-19 22:49:50 -04:00
parent 0525230731
commit d1c3083a8f
2 changed files with 17 additions and 6 deletions

View file

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

View file

@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::fmt::Display;
use std::net::TcpStream;
use std::path::Path;
use log::{debug, info};
use log::{debug, error, info, warn};
use reqwest::blocking::Response;
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);
@ -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>) {
for ordinal in ordinals {
imap_session.store(format!("{}", ordinal), "+FLAGS (\\Deleted)")
.expect("Couldn't delete message");
match imap_session.store(format!("{}", ordinal), "+FLAGS (\\Deleted)") {
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> {