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.
memfd
Manos Pitsidianakis 2020-06-06 12:24:39 +03:00
parent 3e31c46a74
commit e4d4cd55d3
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 7 additions and 1 deletions

View File

@ -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) => {