From f119789cb03fd3d089b77d70ac89a06b7735a61d Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 22 Jul 2018 14:05:12 +0300 Subject: [PATCH] Add stub for format_flowed support Concerns #17 --- melib/src/conf/mod.rs | 3 +-- melib/src/conf/pager.rs | 7 ++++++- melib/src/mailbox/email/attachments.rs | 9 +++++++++ melib/src/mailbox/email/mod.rs | 2 ++ ui/src/components/utilities.rs | 15 ++++++++++++--- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/melib/src/conf/mod.rs b/melib/src/conf/mod.rs index 1f2b6f2f..7173ecb9 100644 --- a/melib/src/conf/mod.rs +++ b/melib/src/conf/mod.rs @@ -99,10 +99,9 @@ impl AccountSettings { } } -#[derive(Debug)] +#[derive(Debug, Clone, Default)] pub struct Settings { pub accounts: HashMap, - pub pager: PagerSettings, } diff --git a/melib/src/conf/pager.rs b/melib/src/conf/pager.rs index 4d8c6032..edb65c95 100644 --- a/melib/src/conf/pager.rs +++ b/melib/src/conf/pager.rs @@ -18,7 +18,7 @@ fn none() -> Option { } /// Settings for the pager function. -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone, Default)] pub struct PagerSettings { /// Number of context lines when going to next page. /// Default: 0 @@ -44,4 +44,9 @@ pub struct PagerSettings { /// Default: None #[serde(default = "none")] pub filter: Option, + + /// Respect "format=flowed" + /// Default: true + #[serde(default = "true_val")] + pub format_flowed: bool, } diff --git a/melib/src/mailbox/email/attachments.rs b/melib/src/mailbox/email/attachments.rs index 24103b5e..bfa0df48 100644 --- a/melib/src/mailbox/email/attachments.rs +++ b/melib/src/mailbox/email/attachments.rs @@ -334,3 +334,12 @@ impl Attachment { counter } } + + +pub fn interpret_format_flowed(t: &str) -> String { + let mut n = String::with_capacity(t.len()); + + + + unimplemented!() +} diff --git a/melib/src/mailbox/email/mod.rs b/melib/src/mailbox/email/mod.rs index e2faede6..da703916 100644 --- a/melib/src/mailbox/email/mod.rs +++ b/melib/src/mailbox/email/mod.rs @@ -21,8 +21,10 @@ pub mod parser; mod attachments; + use mailbox::backends::BackendOpGenerator; use self::attachments::*; +pub use self::attachments::interpret_format_flowed; use std::string::String; use std::sync::Arc; diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 7f6315b8..ef394f62 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -2,6 +2,8 @@ */ use super::*; +use melib::mailbox::email::interpret_format_flowed; + /// A horizontally split in half container. pub struct HSplit { top: Entity, @@ -132,10 +134,14 @@ pub struct Pager { content: CellBuffer, } -// TODO: Make the `new` method content agnostic. +// TODO: Make a `new` method that is content agnostic. impl Pager { - pub fn new(mail: &Envelope, pager_filter: Option) -> Self { - let mut text = mail.body().text(); + pub fn from_envelope(mailbox_idx: (usize, usize), envelope_idx: usize, context: &mut Context) -> Self { + let mailbox = &mut context.accounts[mailbox_idx.0][mailbox_idx.1].as_ref().unwrap().as_ref().unwrap(); + let envelope : &Envelope = &mailbox.collection[envelope_idx]; + let pager_filter: Option<&String> = context.settings.pager.filter.as_ref(); + let format_flowed: bool = context.settings.pager.format_flowed; + let mut text = envelope.body().text(); if let Some(bin) = pager_filter { use std::io::Write; use std::process::{Command, Stdio}; @@ -158,6 +164,9 @@ impl Pager { let height = lines.len(); let width = lines.iter().map(|l| l.len()).max().unwrap_or(0); let mut content = CellBuffer::new(width, height, Cell::with_char(' ')); + if false { + interpret_format_flowed(&text); + } Pager::print_string(&mut content, &text); Pager { cursor_pos: 0,