summaryrefslogtreecommitdiff
path: root/src/rfc822.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rfc822.rs')
-rw-r--r--src/rfc822.rs49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/rfc822.rs b/src/rfc822.rs
index a8fa5c3..b8bad6a 100644
--- a/src/rfc822.rs
+++ b/src/rfc822.rs
@@ -7,7 +7,7 @@ use mailparse::{
use crate::de_jmhoffmann_jwebmail_mailstorage::MIMEHeader_content_dispo as CD;
use crate::de_jmhoffmann_jwebmail_mailstorage::*;
-fn parse_mail_addrs(
+pub fn parse_mail_addrs(
inp: &mailparse::MailHeader,
) -> std::result::Result<Vec<MailAddr>, MailParseError> {
let mut mal = addrparse_header(inp)?;
@@ -36,25 +36,17 @@ fn parse_mail_addrs(
// ----------------
-fn get_received(me: &mut maildir::MailEntry) -> i64 {
- me.received().unwrap_or_else(|_| {
- let mut id = me.id();
- id = &id[..id.find('.').unwrap()];
- id.parse().unwrap_or_default()
- })
-}
-
pub fn me_to_lmh(
mut me: maildir::MailEntry,
) -> std::result::Result<ListMailHeader, MailEntryError> {
let lmh = ListMailHeader {
byte_size: me.path().metadata()?.len() as i64,
unread: !me.is_seen(),
- rec_date: DateTime::from_timestamp(get_received(&mut me), 0)
+ rec_date: DateTime::from_timestamp(me.received().unwrap_or_default(), 0)
.unwrap()
.to_rfc3339(),
mid: me.id().to_owned(),
- header: parse_mail_header(&me.parsed()?)?,
+ header: parse_mail_header(&me.headers()?)?,
};
Ok(lmh)
@@ -104,18 +96,11 @@ pub fn parse_mail_content(v: &ParsedMail) -> MIMEHeader {
}
}
-fn parse_mail_header(pm: &ParsedMail) -> std::result::Result<MailHeader, MailParseError> {
- let v = &pm.headers;
-
- let mut val = pm.ctype.mimetype.clone();
- if let Some(i) = val.find(';') {
- val.truncate(i);
- }
- let j = val.find('/').unwrap();
- let sub_type = val.split_off(j + 1);
- val.pop();
- let main_type = val;
-
+fn parse_mail_header(
+ v: &Vec<mailparse::MailHeader>,
+) -> std::result::Result<MailHeader, MailParseError> {
+ let mut sub_type = String::new();
+ let mut main_type = String::new();
let mut file_name = None;
let mut content_dispo = CD::none;
let mut cc = vec![];
@@ -138,6 +123,15 @@ fn parse_mail_header(pm: &ParsedMail) -> std::result::Result<MailHeader, MailPar
key.make_ascii_lowercase();
match key.as_str() {
+ "content-type" => {
+ if let Some(i) = val.find(';') {
+ val.truncate(i);
+ }
+ let j = val.find('/').unwrap();
+ sub_type = val.split_off(j + 1);
+ val.pop();
+ main_type = val;
+ }
"date" => {
send_date = DateTime::from_timestamp(dateparse(&val)?, 0)
.unwrap()
@@ -187,6 +181,13 @@ fn parse_mail_header(pm: &ParsedMail) -> std::result::Result<MailHeader, MailPar
key.clear();
}
+
+ // this is not correct for multipart/digest
+ if main_type.is_empty() || sub_type.is_empty() {
+ main_type = "text".to_string();
+ sub_type = "plain".to_string();
+ }
+
Ok(MailHeader {
written_from,
sender,
@@ -362,7 +363,7 @@ fn strip_comments(s: &mut String) {
pub fn parsed_mail_to_mail(pm: ParsedMail) -> std::result::Result<Mail, MailParseError> {
Ok(Mail {
- head: parse_mail_header(&pm)?,
+ head: parse_mail_header(&pm.headers)?,
body: parse_mail_body(&pm)?,
})
}