summaryrefslogtreecommitdiff
path: root/src/rfc822.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rfc822.rs')
-rw-r--r--src/rfc822.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/rfc822.rs b/src/rfc822.rs
index aafedde..658b167 100644
--- a/src/rfc822.rs
+++ b/src/rfc822.rs
@@ -1,4 +1,4 @@
-use chrono::NaiveDateTime;
+use chrono::DateTime;
use mailparse::{addrparse_header, body::Body, dateparse, DispositionType, ParsedMail};
use crate::error::{Error, Result};
@@ -48,9 +48,8 @@ pub fn me_to_lmh(mut me: maildir::MailEntry) -> Result<ListMailHeader> {
let mut lmh = ListMailHeader::new();
lmh.byte_size = me.path().metadata()?.len();
lmh.unread = !me.is_seen();
- lmh.rec_date = NaiveDateTime::from_timestamp_opt(get_received(&mut me), 0)
+ lmh.rec_date = DateTime::from_timestamp(get_received(&mut me), 0)
.unwrap()
- .and_utc()
.to_rfc3339();
lmh.mid = me.id().to_owned();
lmh.header = Some(parse_mail_header(&me.parsed()?)?).into();
@@ -77,7 +76,7 @@ pub fn parse_mail_content(v: &ParsedMail) -> Result<MIMEHeader> {
DispositionType::Attachment => {
c.contentdispo = CONTENT_DISPOSITION_ATTACHMENT.into();
if let Some(fname) = v.get_content_disposition().params.remove("filename") {
- c.file_name = Some(fname).into();
+ c.file_name = Some(fname);
}
}
_ => {}
@@ -89,11 +88,8 @@ pub fn parse_mail_content(v: &ParsedMail) -> Result<MIMEHeader> {
key.make_ascii_lowercase();
- match key.as_ref() {
- "filename" => {
- c.file_name = Some(val).into();
- }
- _ => {}
+ if key == "filename" {
+ c.file_name = Some(val);
}
}
@@ -127,9 +123,8 @@ fn parse_mail_header(pm: &ParsedMail) -> Result<MailHeader> {
match key.as_str() {
"date" => {
- mh.send_date = NaiveDateTime::from_timestamp_opt(dateparse(&val)?, 0)
+ mh.send_date = DateTime::from_timestamp(dateparse(&val)?, 0)
.unwrap()
- .and_utc()
.to_rfc3339()
}
"from" => {
@@ -314,13 +309,10 @@ fn find_pair(offset: usize, s: &str) -> Option<std::ops::Range<usize>> {
fn strip_comments(s: &mut String) {
let mut off = 0;
- loop {
- if let Some(r) = find_pair(off, &s[off..]) {
- s.drain(r.clone());
- off = r.start;
- } else {
- break;
- }
+
+ while let Some(r) = find_pair(off, &s[off..]) {
+ s.drain(r.clone());
+ off = r.start;
}
}