Start collecting recipients
- Collect recipients for processed email. - Add proper email parsing
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
//
|
||||
|
||||
use anyhow;
|
||||
use sequoia_openpgp::policy::StandardPolicy;
|
||||
use std::path::PathBuf;
|
||||
use sequoia_openpgp::Cert;
|
||||
use sequoia_cert_store::{CertStore, StoreUpdate};
|
||||
@@ -14,6 +15,7 @@ use crate::{config::HuskConfig, crypto};
|
||||
use crate::types::mail_context::MailContext;
|
||||
|
||||
pub struct HuskContext<'hc> {
|
||||
pub policy: StandardPolicy<'hc>,
|
||||
pub cert_store: CertStore<'hc>,
|
||||
pub local_trust_root: Cert,
|
||||
pub mail: MailContext<'hc>,
|
||||
@@ -28,9 +30,12 @@ impl<'hc> HuskContext<'hc> {
|
||||
let cert_store_base = sequoia_home.data_dir(sequoia_directories::Component::CertD);
|
||||
let cert_store = CertStore::open(cert_store_base)?;
|
||||
|
||||
let policy = StandardPolicy::new();
|
||||
|
||||
let local_trust_root = crypto::get_local_trust_root(&cert_store)?;
|
||||
|
||||
Ok(HuskContext {
|
||||
policy,
|
||||
cert_store,
|
||||
local_trust_root,
|
||||
mail: MailContext::new(),
|
||||
@@ -41,4 +46,12 @@ impl<'hc> HuskContext<'hc> {
|
||||
self.mail.set_sender(sender);
|
||||
}
|
||||
|
||||
pub fn reset_mail(&mut self) {
|
||||
self.mail = MailContext::new();
|
||||
}
|
||||
|
||||
pub fn add_recipient(&mut self, rcpt: String) -> anyhow::Result<()> {
|
||||
self.mail.add_recipient(rcpt)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,15 +4,25 @@
|
||||
// Mail Context
|
||||
//
|
||||
|
||||
use std::ffi::CString;
|
||||
use anyhow;
|
||||
|
||||
use sequoia_openpgp::cert::ValidCert;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Recipient<'r> {
|
||||
pub email: CString,
|
||||
pub email: String,
|
||||
pub cert: Option<ValidCert<'r>>,
|
||||
}
|
||||
|
||||
impl From<String> for Recipient<'_> {
|
||||
fn from(email: String) -> Self {
|
||||
Recipient {
|
||||
email: email,
|
||||
cert: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MailContext<'c> {
|
||||
pub sender: Option<String>,
|
||||
pub recipients: Vec<Recipient<'c>>,
|
||||
@@ -34,4 +44,12 @@ impl MailContext<'_> {
|
||||
self.sender = Some(sender);
|
||||
}
|
||||
|
||||
pub fn add_recipient(&mut self, rcpt: String) -> anyhow::Result<()> {
|
||||
let recipient: Recipient = rcpt.into();
|
||||
|
||||
self.recipients.push(recipient);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user