Code polish
- Fix some typos. - Added more comments (and documentation) to the code.
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ pub enum HuskError {
|
||||
#[error("Cannot find the local trust root")]
|
||||
NoLocalTrustRoot,
|
||||
#[error("The local trust root is damaged - {0}")]
|
||||
DamangedLocalTrustRoot(String),
|
||||
DamagedLocalTrustRoot(String),
|
||||
#[error("Cannot access cert store")]
|
||||
NoCertStore,
|
||||
#[error("No encryption keys found")]
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
//! HuskContext
|
||||
//!
|
||||
//! Keep data in HuskContext while processing a mail.
|
||||
//! Keep data in `HuskContext` while processing emails. The HuskContext
|
||||
//! lives for a complete session with the MTA. A session might contain
|
||||
//! more than one email (the session is reused).
|
||||
//!
|
||||
//! The context of a single mail is stored in a `MailContext`. The
|
||||
//! `HuskContext` has a reference to the `MailContext` of the current
|
||||
//! email.
|
||||
|
||||
use anyhow;
|
||||
use sequoia_openpgp::policy::StandardPolicy;
|
||||
@@ -26,7 +32,7 @@ pub struct HuskContext<'hc> {
|
||||
|
||||
impl<'hc> HuskContext<'hc> {
|
||||
|
||||
/// Create a new HuskContext instance
|
||||
/// Create a new HuskContext instance.
|
||||
pub fn new(config: &HuskConfig) -> anyhow::Result<HuskContext<'hc>> {
|
||||
|
||||
let sequoia_home = Home::new(PathBuf::from(&config.sequoia_home))?;
|
||||
@@ -48,14 +54,19 @@ impl<'hc> HuskContext<'hc> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_sender(&mut self, sender: String) {
|
||||
self.mail.set_sender(sender);
|
||||
}
|
||||
|
||||
/// If the `HuskContext` is reused for another email, `reset_mail`
|
||||
/// creates the neccessary context for it.
|
||||
pub fn reset_mail(&mut self) {
|
||||
self.mail = MailContext::new();
|
||||
}
|
||||
|
||||
/// Store the sender of an email in the current `MailContext`.
|
||||
pub fn set_sender(&mut self, sender: String) {
|
||||
self.mail.set_sender(sender);
|
||||
}
|
||||
|
||||
/// Add a recipient to the current `MailContext`, try to fetch the
|
||||
/// corresponding certificate(s).
|
||||
pub async fn add_recipient(&mut self, rcpt: String) {
|
||||
|
||||
let certs = crypto::get_certificates(self, rcpt.as_str()).await;
|
||||
|
||||
@@ -108,6 +108,7 @@ use std::fmt::{Display, Formatter};
|
||||
impl Display for Introducer {
|
||||
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
// XXX: This is unsafe as ANSI control chars are not handled.
|
||||
let uids = self.cert.userids()
|
||||
.map(|u| String::from_utf8_lossy(u.userid().value()).to_string())
|
||||
.collect::<Vec<String>>()
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
//! Mail Context
|
||||
//!
|
||||
//! As a mail gets processed by the milter, the `MailContext` is used
|
||||
//! to keep the bits and pieces together.
|
||||
|
||||
use std::sync::Arc;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
|
||||
Reference in New Issue
Block a user