aboutsummaryrefslogtreecommitdiff
path: root/src/process_mail.rs
diff options
context:
space:
mode:
authorMroik <mroik@delayed.space>2026-05-09 03:23:52 +0200
committerMroik <mroik@delayed.space>2026-05-30 16:57:25 +0200
commit3bdf7734903c3b444866b744a461acf0ee728797 (patch)
tree25e9e62e9b6f8001fbcbac575391b3048ade42e5 /src/process_mail.rs
parent6602bf798653e48f020d1151d0a07aa413feaf25 (diff)
Add queue for mail processing
Add DB table for queue. It is necessary in case the delivery fails and we'll need to retry. Signed-off-by: Mroik <mroik@delayed.space>
Diffstat (limited to 'src/process_mail.rs')
-rw-r--r--src/process_mail.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/process_mail.rs b/src/process_mail.rs
index 5a22ce1..90fdd2a 100644
--- a/src/process_mail.rs
+++ b/src/process_mail.rs
@@ -1,11 +1,20 @@
+use std::sync::Arc;
+
use anyhow::Result;
-use tokio::sync::mpsc::{Receiver, Sender};
+use tokio::sync::{
+ Mutex,
+ mpsc::{Receiver, Sender},
+};
-use crate::model::Mail;
+use crate::{
+ database::Database,
+ model::{Mail, MailQuery},
+};
struct MailProcessor {
rx: Receiver<Mail>,
tx: Sender<Mail>,
+ db: Arc<Mutex<Database>>,
}
// TODO: Store first then forward. On complete forward remove from db, otherwise save db with the
@@ -15,9 +24,17 @@ impl MailProcessor {
// TODO: Check againts self.rx.is_closed() instead to stop the program before consuming all
// of the queue. Store the emails not yet processed and restore the queue upon startup.
while let Some(mail) = self.rx.recv().await {
- todo!()
+ let mut db_guard = self.db.lock().await;
+ db_guard.execute(MailQuery::Insert(&mail))?;
+ drop(db_guard);
+
+ todo!();
}
Ok(())
}
}
+
+mod tests {
+ // TODO: Think of a way to test
+}
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj