Start collecting recipients

- Collect recipients for processed email.
- Add proper email parsing
This commit is contained in:
Malte Meiboom
2025-12-11 11:53:55 +01:00
parent 49c1b99b5a
commit 23c698f445
5 changed files with 85 additions and 15 deletions
+29 -13
View File
@@ -26,6 +26,7 @@ use indymilter::{
use crate::types::husk_context::HuskContext;
use crate::config::{HuskConfig, HuskConfigContainer};
use crate::mail;
pub struct Daemon { }
@@ -105,19 +106,19 @@ impl Daemon {
async fn handle_mail(cx: &mut Context<HuskContext<'_>>, args: Vec<CString>) -> Status {
log::debug!("MAIL: {args:?}");
// XXX
let sender = match args.first() {
Some(cs) => {
match cs.to_str() {
Ok(s) => s.to_string(),
_ => "corrupt".to_string()
}
},
None => { "missing".to_string() }
};
let mut sender: Option<String> = None;
for arg in args {
if let Some(s) = mail::to_email(&arg) {
sender = Some(s);
break;
}
}
if sender.is_none() { return Status::Tempfail; }
if let Some(ref mut context) = cx.data {
context.set_sender(sender);
context.reset_mail();
context.set_sender(sender.unwrap());
Status::Continue
} else {
Status::Tempfail
@@ -129,9 +130,23 @@ impl Daemon {
if let Some(ref mut context) = cx.data {
let mut rcpt: Option<String> = None;
for arg in args {
if let Some(s) = mail::to_email(&arg) {
rcpt = Some(s);
break;
}
}
if rcpt.is_none() {
Status::Tempfail
} else {
context.add_recipient(rcpt.unwrap()).unwrap();
Status::Continue
}
} else {
Status::Tempfail
}
Status::Continue
}
async fn handle_data(_cx: &mut Context<HuskContext<'_>>) -> Status {
@@ -163,6 +178,7 @@ impl Daemon {
if let Some(ref mut context) = cx.data {
log::debug!("Mail from {:?} complete", context.mail.sender);
log::debug!("recipients: {:?}", context.mail.recipients);
}
Status::Continue