Determine the sender

This commit is contained in:
Benedikt Terhechte 2021-10-10 10:02:54 +02:00
parent b5be751e3f
commit 2d5b528d46
2 changed files with 9 additions and 4 deletions

View File

@ -33,7 +33,7 @@ pub fn into_database<Mail: ParseableEmail + 'static>(
//.par_iter()
.par_iter_mut()
// parsing them
.map(|raw_mail| parse_email(raw_mail))
.map(|raw_mail| parse_email(raw_mail, config.sender_email.as_str()))
// and inserting them into SQLite
.for_each(|entry| {
// Try to write the message into the database

View File

@ -22,7 +22,10 @@ pub trait ParseableEmail: Send + Sized + Sync {
fn meta(&self) -> Result<Option<EmailMeta>>;
}
pub fn parse_email<Entry: ParseableEmail>(entry: &mut Entry) -> Result<EmailEntry> {
pub fn parse_email<Entry: ParseableEmail>(
entry: &mut Entry,
config_sender_email: &str,
) -> Result<EmailEntry> {
if let Err(e) = entry.prepare() {
tracing::error!("Prepare Error: {:?}", e);
return Err(e);
@ -53,8 +56,10 @@ pub fn parse_email<Entry: ParseableEmail>(entry: &mut Entry) -> Result<EmailEntr
let meta = entry.meta()?;
// FIXME: This is filled out at a later stage
let is_send = false;
// In order to determine the sender, we have to
// build up the address again :-(
let is_send =
format!("{}@{}", sender_local_part, sender_domain).as_str() == config_sender_email;
Ok(EmailEntry {
path: path.to_path_buf(),