summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-01-02 14:44:03 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-02 18:53:21 +0100
commita5335e97790137ca27e5d04d65928400a44f2137 (patch)
treedb63fca9ec1032c9ed871c016cab9b22d5bf249e
parentfd16ed4674ec8af07705838dd2240577bf1bf67a (diff)
downloadimag-a5335e97790137ca27e5d04d65928400a44f2137.tar.gz
imag-a5335e97790137ca27e5d04d65928400a44f2137.tar.xz
-rw-r--r--lib/domain/libimagmail/src/util.rs13
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()