diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-01-02 14:44:03 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-01-02 18:53:21 +0100 |
commit | a5335e97790137ca27e5d04d65928400a44f2137 (patch) | |
tree | db63fca9ec1032c9ed871c016cab9b22d5bf249e | |
parent | fd16ed4674ec8af07705838dd2240577bf1bf67a (diff) |
Fix: Do not assume a mail file to be valid UTF8
We did assume that the file contained valid UTF8 when reading to `String`.
Now we read to a byte buffer, which removes the (wrong) assumtion.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
(cherry picked from commit 9c249dbeea23ce7c12706ee614d42034aacbf8a6)
-rw-r--r-- | lib/domain/libimagmail/src/util.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/domain/libimagmail/src/util.rs b/lib/domain/libimagmail/src/util.rs index d16c2fd5..2c43dd6e 100644 --- a/lib/domain/libimagmail/src/util.rs +++ b/lib/domain/libimagmail/src/util.rs @@ -18,6 +18,8 @@ // use std::path::Path; +use std::fs::OpenOptions; +use std::io::Read; use failure::Error; use failure::Fallible as Result; @@ -35,7 +37,16 @@ use failure::ResultExt; /// TODO: Optimize /// pub(crate) fn get_message_header_at_key<P: AsRef<Path>, K: AsRef<str>>(p: P, k: K) -> Result<String> { - ::mailparse::parse_mail(::std::fs::read_to_string(p.as_ref())?.as_bytes()) + let buffer = { + let mut buffer = Vec::with_capacity(4096); // allocate new buffer with 4 KB space + OpenOptions::new() + .read(true) + .open(p.as_ref())? + .read_to_end(&mut buffer)?; + buffer + }; + + ::mailparse::parse_mail(&buffer) .context(format_err!("Cannot parse Email {}", p.as_ref().display()))? .headers .into_iter() |