summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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()