add feature to process multiple mailboxes #3
2 changed files with 17 additions and 6 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
21
src/main.rs
21
src/main.rs
|
|
@ -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> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue