diff --git a/Cargo.toml b/Cargo.toml index 4e1d884de..19ff176b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,4 @@ version = "5.86.0" [profile.release] lto = true +#debug = true diff --git a/src/error.rs b/src/error.rs index c61a438c9..d6bcf94fe 100644 --- a/src/error.rs +++ b/src/error.rs @@ -25,7 +25,7 @@ use std::io; pub type Result = result::Result; -#[derive(Debug)] +#[derive(Debug,Clone)] pub struct MeliError { details: String } diff --git a/src/mailbox/email/attachments.rs b/src/mailbox/email/attachments.rs index fb225db1c..f4b9b02fa 100644 --- a/src/mailbox/email/attachments.rs +++ b/src/mailbox/email/attachments.rs @@ -21,6 +21,7 @@ use mailbox::email::parser; use std::fmt::{Display, Formatter, Result}; +use std::ascii::AsciiExt; /* * @@ -107,61 +108,47 @@ impl AttachmentBuilder { } pub fn content_type(&mut self, value: &str) -> &Self { match parser::content_type(value.as_bytes()).to_full_result() { -Ok((ct, cst, params)) => { - match ct.to_lowercase().as_ref() { - "multipart" => { - let mut boundary = None; - for (n, v) in params { - if n.to_lowercase() == "boundary" { - boundary = Some(format!("--{}--", v).to_string()); - break; - } + Ok((ct, cst, params)) => { + if ct.eq_ignore_ascii_case("multipart") { + let mut boundary = None; + for (n, v) in params { + if n.eq_ignore_ascii_case("boundary") { + boundary = Some(format!("--{}--", v).to_string()); + break; } - assert!(boundary.is_some()); - self.content_type.0 = ContentType::Multipart { boundary: boundary.unwrap() }; - self.content_type.1 = ContentSubType::Other { tag: cst.to_string() }; - }, - "text" => { - self.content_type.0 = ContentType::Text; - let cst = cst.to_lowercase(); - match cst.as_ref() { - "plain" => {}, - _ => { - self.content_type.1 = ContentSubType::Other { tag: cst }; - }, - } - }, - unsupported_type => { - self.content_type.0 = ContentType::Unsupported { tag: unsupported_type.to_string() }; - self.content_type.1 = ContentSubType::Other { tag: cst.to_string() }; - }, + } + assert!(boundary.is_some()); + self.content_type.0 = ContentType::Multipart { boundary: boundary.unwrap() }; + self.content_type.1 = ContentSubType::Other { tag: cst.to_string() }; + } else if ct.eq_ignore_ascii_case("text") { + self.content_type.0 = ContentType::Text; + if !cst.eq_ignore_ascii_case("plain") { + self.content_type.1 = ContentSubType::Other { tag: cst.to_ascii_lowercase() }; + } + } else { + self.content_type.0 = ContentType::Unsupported { tag: ct.to_ascii_lowercase() }; + self.content_type.1 = ContentSubType::Other { tag: cst.to_ascii_lowercase() }; } - }, - Err(v) => { - eprintln!("parsing error in content_type: {:?} {:?}", value, v); - } - } - self + }, + Err(v) => { + eprintln!("parsing error in content_type: {:?} {:?}", value, v); + } +} +self } pub fn content_transfer_encoding(&mut self, value: &str) -> &Self { self.content_transfer_encoding = - match value.to_lowercase().as_ref() { - "base64" => { + if value.eq_ignore_ascii_case("base64") { ContentTransferEncoding::Base64 - }, - "7bit" => { + } else if value.eq_ignore_ascii_case("7bit") { ContentTransferEncoding::_7Bit - }, - "8bit" => { + } else if value.eq_ignore_ascii_case("8bit") { ContentTransferEncoding::_8Bit - }, - "quoted-printable" => { + } else if value.eq_ignore_ascii_case("quoted-printable") { ContentTransferEncoding::QuotedPrintable - }, - k => { - ContentTransferEncoding::Other { tag: k.to_string() } - }, - }; + } else { + ContentTransferEncoding::Other { tag: value.to_ascii_lowercase() } + }; self } fn decode(&self) -> String { @@ -194,7 +181,7 @@ Ok((ct, cst, params)) => { let multipart_type = match self.content_type.1 { ContentSubType::Other { ref tag } => { - match tag.to_lowercase().as_ref() { + match tag.as_ref() { "mixed" => { MultipartType::Mixed }, @@ -303,15 +290,10 @@ impl Attachment { }; let mut builder = AttachmentBuilder::new(body); for (name, value) in headers { - match name.to_lowercase().as_ref(){ - "content-type" => { - builder.content_type(value); - }, - "content-transfer-encoding" => { - builder.content_transfer_encoding(value); - }, - _ => { - }, + if name.eq_ignore_ascii_case("content-type") { + builder.content_type(value); + } else if name.eq_ignore_ascii_case("content-transfer-encoding") { + builder.content_transfer_encoding(value); } } vec.push(builder.build()); diff --git a/src/ui/index.rs b/src/ui/index.rs index e3d781b49..3288487c5 100644 --- a/src/ui/index.rs +++ b/src/ui/index.rs @@ -94,7 +94,7 @@ impl Window for Index { let mut y = 0; ncurses::getbegyx(self.win, &mut y, &mut x); - ncurses::wclear(self.pad); + //ncurses::wclear(self.pad); if self.threaded { let mut indentations : Vec = Vec::with_capacity(6); @@ -172,16 +172,23 @@ impl Window for Index { ); } fn redraw(&mut self) -> () { + ncurses::wnoutrefresh(self.win); + ncurses::doupdate(); if self.mailbox.get_length() == 0 { return; } + /* Draw newly highlighted entry */ + ncurses::wmove(self.pad, self.cursor_idx as i32, 0); + let pair = super::COLOR_PAIR_CURSOR; + ncurses::wchgat(self.pad, -1, 0, pair); ncurses::getmaxyx(self.win, &mut self.screen_height, &mut self.screen_width); let mut x = 0; let mut y = 0; ncurses::getbegyx(self.win, &mut y, &mut x); let pminrow = (self.cursor_idx as i32).wrapping_div(self.screen_height) * self.screen_height; - ncurses::touchline(self.pad, 1, 1); ncurses::prefresh( + ncurses::touchline(self.pad, 1, 1); + ncurses::prefresh( self.pad, pminrow, 0, @@ -446,8 +453,8 @@ impl Index { } impl Drop for Index { fn drop(&mut self) { + ncurses::delwin(self.pad); ncurses::wclear(self.win); ncurses::delwin(self.win); - ncurses::delwin(self.pad); } } diff --git a/src/ui/pager.rs b/src/ui/pager.rs index ee9a1f9ea..a2187816b 100644 --- a/src/ui/pager.rs +++ b/src/ui/pager.rs @@ -51,7 +51,7 @@ impl Pager { x, ); ncurses::wclear(win); - ncurses::touchwin(win); + //ncurses::touchwin(win); for _ in 1..screen_width + 1 { ncurses::waddstr(win, "─"); } @@ -241,7 +241,6 @@ impl Drop for Pager { fn drop(&mut self) { ncurses::delwin(self.pad); ncurses::wclear(self.win); - ncurses::wrefresh(self.win); ncurses::delwin(self.win); } }