From e4d4cd55d3ba2c80e7efa420ea94193f4701e8dc Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 6 Jun 2020 12:24:39 +0300 Subject: [PATCH] melib: skip mbox `From ` header if present mbox messages might end up in the parser by mistake, for example by being present in a Maildir store. --- melib/src/email.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/melib/src/email.rs b/melib/src/email.rs index b3d5e3f1..3ba96ddf 100644 --- a/melib/src/email.rs +++ b/melib/src/email.rs @@ -236,7 +236,13 @@ impl Envelope { pub fn hash(&self) -> EnvelopeHash { self.hash } - pub fn populate_headers(&mut self, bytes: &[u8]) -> Result<()> { + pub fn populate_headers(&mut self, mut bytes: &[u8]) -> Result<()> { + if bytes.starts_with(b"From ") { + /* Attempt to recover if message includes the mbox From label as first line */ + if let Some(offset) = bytes.find(b"\n") { + bytes = &bytes[offset + 1..]; + } + } let (headers, body) = match parser::mail(bytes).to_full_result() { Ok(v) => v, Err(e) => {