summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-08-03 18:20:03 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-08-03 18:20:03 +0200
commitba225549e3ca60fee55a6449055a02be1f4cd5b7 (patch)
tree1ef569892be53ed7727df791abd3bb1d97509f2c
parent632725d650d4c6975cc7c3563627e09662667709 (diff)
Add viewing of all direct subparts
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml1
-rw-r--r--src/mail_view.rs33
2 files changed, 24 insertions, 10 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 78d8006..4c95a4a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ mailparse.git = "https://git.sr.ht/~matthiasbeyer/mailparse"
notmuch = "0.6"
serde = { version = "1.0", features = ["derive"] }
walkdir = "2"
+result-inspect = "0.1"
cursive = "0.15"
cursive_core = "0.1"
diff --git a/src/mail_view.rs b/src/mail_view.rs
index eb446ce..ce1d4b5 100644
--- a/src/mail_view.rs
+++ b/src/mail_view.rs
@@ -18,6 +18,7 @@ use cursive::views::ResizedView;
use cursive::views::TextView;
use cursive::views::LinearLayout;
use cursive::views::ScrollView;
+use result_inspect::ResultInspect;
pub struct MailView {
database_path: PathBuf,
@@ -33,11 +34,25 @@ impl MailView {
.search_messages()?
.map(|msg| {
debug!("Constructing textview for '{}'", msg.filename().display());
- MailView::path_to_textview(msg.filename())
+ let buf = std::fs::read(msg.filename())?;
+ debug!("Found {} bytes from {}", buf.len(), msg.filename().display());
+
+ let parsed = mailparse::parse_mail(buf)?;
+
+ let iter = std::iter::once(parsed.get_body().map(TextView::new))
+ .chain({
+ parsed.subparts
+ .into_iter()
+ .map(|chld| chld.get_body().map(TextView::new))
+ });
+
+ Ok(iter)
})
- .fold(Ok(LinearLayout::vertical()), |r, el| {
- el.and_then(|e| {
- r.map(|lv| lv.child(e))
+ .fold(Ok(LinearLayout::vertical()), |ll: Result<_>, views: Result<_>| {
+ views?.fold(ll, |l, elem| {
+ l.and_then(|l| {
+ elem.map_err(Error::from).map(|e| l.child(e))
+ })
})
})?;
@@ -53,13 +68,11 @@ impl MailView {
}
fn path_to_textview(pb: PathBuf) -> Result<TextView> {
- let s = std::fs::read(&pb)
+ std::fs::read(&pb)
.map_err(Error::from)
- .and_then(|b| String::from_utf8(b).map_err(Error::from))?;
-
- debug!("Found {} bytes from {}", s.bytes().len(), pb.display());
-
- Ok(TextView::new(s))
+ .and_then(|b| String::from_utf8(b).map_err(Error::from))
+ .inspect(|s| debug!("Found {} bytes from {}", s.bytes().len(), pb.display()))
+ .map(TextView::new)
}
}