fix bad sender and date in reply and forward tpl (#321)

This commit is contained in:
Clément DOUIN 2022-03-03 15:16:34 +01:00
parent 1b16804ed6
commit e5164a2ce3
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
2 changed files with 20 additions and 9 deletions

View file

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Some emojis break the table layout [#300]
- Bad sender and date in reply and forward template [#321]
## [0.5.7] - 2022-03-01

View file

@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Error, Result};
use chrono::{DateTime, FixedOffset};
use html_escape;
use lettre::message::{header::ContentType, Attachment, MultiPart, SinglePart};
use log::{debug, info, trace};
use log::{debug, info, trace, warn};
use regex::Regex;
use std::{collections::HashSet, convert::TryInto, env::temp_dir, fmt::Debug, fs, path::PathBuf};
use uuid::Uuid;
@ -170,9 +170,6 @@ impl Msg {
// In-Reply-To
self.in_reply_to = self.message_id.to_owned();
// From
self.from = Some(vec![account_addr.clone()].into());
// To
let addrs = self
.reply_to
@ -198,11 +195,6 @@ impl Msg {
self.bcc = None;
}
// Subject
if !self.subject.starts_with("Re:") {
self.subject = format!("Re: {}", self.subject);
}
// Body
let plain_content = {
let date = self
@ -236,6 +228,14 @@ impl Msg {
self.parts = Parts(vec![Part::new_text_plain(plain_content)]);
// Subject
if !self.subject.starts_with("Re:") {
self.subject = format!("Re: {}", self.subject);
}
// From
self.from = Some(vec![account_addr.clone()].into());
Ok(self)
}
@ -648,6 +648,16 @@ impl Msg {
"subject" => {
msg.subject = val;
}
"date" => {
msg.date = DateTime::parse_from_rfc2822(
val.split_at(val.find(" (").unwrap_or_else(|| val.len())).0,
)
.map_err(|err| {
warn!("cannot parse message date {:?}, skipping it", val);
err
})
.ok();
}
"from" => {
msg.from = from_slice_to_addrs(val)
.context(format!("cannot parse header {:?}", key))?