From b7729243adddfdd5781afe6c059092eb2c80db50 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 24 Jul 2018 20:20:32 +0300 Subject: [PATCH] Fix compiler warnings --- melib/Cargo.toml | 2 +- melib/src/conf/mod.rs | 1 - melib/src/lib.rs | 2 +- melib/src/mailbox/accounts.rs | 1 - melib/src/mailbox/email/attachments.rs | 39 ++++++++++++++++++++------ melib/src/mailbox/email/mod.rs | 1 - melib/src/mailbox/email/parser.rs | 6 ++-- src/bin.rs | 1 - ui/src/cells.rs | 2 +- ui/src/components/mail/listing.rs | 1 - ui/src/components/mail/view.rs | 18 ++++++------ ui/src/components/mod.rs | 10 +++---- ui/src/components/utilities.rs | 11 +++----- ui/src/execute/mod.rs | 4 ++- ui/src/helpers.rs | 4 +-- ui/src/lib.rs | 12 ++++---- 16 files changed, 65 insertions(+), 50 deletions(-) diff --git a/melib/Cargo.toml b/melib/Cargo.toml index 76f75ad8e..b33039ff4 100644 --- a/melib/Cargo.toml +++ b/melib/Cargo.toml @@ -16,7 +16,7 @@ serde_derive = "^1.0.8" serde = "^1.0.8" nom = "3.2.0" memmap = "0.5.2" -base64 = "*" +data-encoding = "2.1.1" encoding = "0.2.33" bitflags = "1.0" termion = "1.5.1" diff --git a/melib/src/conf/mod.rs b/melib/src/conf/mod.rs index 7173ecb96..c955ab4c5 100644 --- a/melib/src/conf/mod.rs +++ b/melib/src/conf/mod.rs @@ -31,7 +31,6 @@ use pager::PagerSettings; use std::collections::HashMap; use std::collections::hash_map::DefaultHasher; use std::hash::Hasher; -use std::io; use std::fs; use std::path::{Path, PathBuf}; diff --git a/melib/src/lib.rs b/melib/src/lib.rs index 177c78c81..cda927dcf 100644 --- a/melib/src/lib.rs +++ b/melib/src/lib.rs @@ -29,9 +29,9 @@ extern crate serde_derive; #[macro_use] extern crate nom; extern crate chrono; -extern crate base64; extern crate memmap; extern crate encoding; +extern crate data_encoding; #[macro_use] extern crate bitflags; diff --git a/melib/src/mailbox/accounts.rs b/melib/src/mailbox/accounts.rs index c1b134591..da642c4a4 100644 --- a/melib/src/mailbox/accounts.rs +++ b/melib/src/mailbox/accounts.rs @@ -85,7 +85,6 @@ impl IndexMut for Account { fn index_mut(&mut self, index: usize) -> &mut Option> { if self.folders[index].is_none() { let folder = &self.settings.folders[index]; - let path = folder.path().clone(); if self.sent_folder.is_some() { let id = self.sent_folder.unwrap(); if id == index { diff --git a/melib/src/mailbox/email/attachments.rs b/melib/src/mailbox/email/attachments.rs index 2830240d4..8b57ada61 100644 --- a/melib/src/mailbox/email/attachments.rs +++ b/melib/src/mailbox/email/attachments.rs @@ -21,6 +21,9 @@ use mailbox::email::parser; use std::fmt::{Display, Formatter, Result as FmtResult}; +use std::str; + +use data_encoding::BASE64_MIME; /* * @@ -158,14 +161,14 @@ impl AttachmentBuilder { // TODO: Use charset for decoding match self.content_transfer_encoding { ContentTransferEncoding::Base64 => { - match ::base64::decode(&::std::str::from_utf8(&self.raw) + match BASE64_MIME.decode(str::from_utf8(&self.raw) .unwrap() .trim() .lines() .fold(String::with_capacity(self.raw.len()), |mut acc, x| { acc.push_str(x); acc - })) { + }).as_bytes()) { Ok(ref v) => { let s = String::from_utf8_lossy(v); if s.find("\r\n").is_some() { @@ -251,7 +254,7 @@ impl AttachmentBuilder { eprintln!( "error {:?}\n\traw: {:?}\n\tboundary: {:?}", a, - ::std::str::from_utf8(raw).unwrap(), + str::from_utf8(raw).unwrap(), boundary ); Vec::new() @@ -277,7 +280,7 @@ impl Display for Attachment { AttachmentType::Data { .. } => { write!(f, "Data attachment of type {}", self.tag()) } - AttachmentType::Text { content: ref t } => { + AttachmentType::Text { .. } => { write!(f, "Text attachment") } AttachmentType::Multipart { @@ -294,6 +297,9 @@ impl Display for Attachment { } impl Attachment { + pub fn bytes(&self) -> &[u8] { + &self.raw + } fn get_text_recursive(&self, text: &mut String) { match self.attachment_type { AttachmentType::Data { .. } => { @@ -361,10 +367,27 @@ impl Attachment { } -pub fn interpret_format_flowed(t: &str) -> String { +pub fn interpret_format_flowed(_t: &str) -> String { //let mut n = String::with_capacity(t.len()); - - - unimplemented!() } + +pub fn decode(a: &Attachment) -> Vec { + // TODO: Use charset for decoding + match a.content_transfer_encoding { + ContentTransferEncoding::Base64 => { + match BASE64_MIME.decode(a.bytes()) { + Ok(v) => { + v + } + _ => a.bytes().to_vec(), + } + } + ContentTransferEncoding::QuotedPrintable => parser::quoted_printed_bytes(&a.bytes()).to_full_result() .unwrap(), + ContentTransferEncoding::_7Bit | + ContentTransferEncoding::_8Bit | + ContentTransferEncoding::Other { .. } => { + a.bytes().to_vec() + } + } +} diff --git a/melib/src/mailbox/email/mod.rs b/melib/src/mailbox/email/mod.rs index 8bb770701..8818c1101 100644 --- a/melib/src/mailbox/email/mod.rs +++ b/melib/src/mailbox/email/mod.rs @@ -23,7 +23,6 @@ pub mod parser; pub mod attachments; use mailbox::backends::BackendOpGenerator; -use self::attachments::*; pub use self::attachments::*; use std::string::String; diff --git a/melib/src/mailbox/email/parser.rs b/melib/src/mailbox/email/parser.rs index e6ad81f26..c55d90a12 100644 --- a/melib/src/mailbox/email/parser.rs +++ b/melib/src/mailbox/email/parser.rs @@ -20,7 +20,7 @@ */ use std; use std::str::from_utf8; -use base64; +use data_encoding::BASE64_MIME; use chrono; use nom::{is_hex_digit, le_u8}; use nom::{ErrorKind, IResult, Needed}; @@ -174,7 +174,7 @@ fn encoded_word(input: &[u8]) -> IResult<&[u8], Vec> { let encoded = &input[5 + tag_len..encoded_idx.unwrap()]; let s: Vec = match input[2 + tag_len + 1] { - b'b' | b'B' => match base64::decode(encoded) { + b'b' | b'B' => match BASE64_MIME.decode(encoded) { Ok(v) => v, Err(_) => encoded.to_vec(), }, @@ -239,7 +239,7 @@ fn encoded_word(input: &[u8]) -> IResult<&[u8], Vec> { named!(qp_underscore_header, do_parse!(tag!("_") >> ({ b' ' }))); named!( - quoted_printed_bytes>, + pub quoted_printed_bytes>, many0!(alt_complete!( quoted_printable_byte | qp_underscore_header | le_u8 )) diff --git a/src/bin.rs b/src/bin.rs index 43af70bf8..205ad16b6 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -31,7 +31,6 @@ use ui::*; pub use melib::*; use std::thread; -use std::io::{stdout,}; #[macro_use] extern crate chan; diff --git a/ui/src/cells.rs b/ui/src/cells.rs index 172c690b6..d17e9ed87 100644 --- a/ui/src/cells.rs +++ b/ui/src/cells.rs @@ -181,7 +181,7 @@ impl fmt::Display for CellBuffer { '_y: for y in 0..self.rows { '_x: for x in 0..self.cols { let c: &char = &self[(x,y)].ch(); - write!(f, "{}", *c); + write!(f, "{}", *c).unwrap(); if *c == '\n' { continue '_y; } diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 9046c7203..b04a51ef3 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -526,7 +526,6 @@ impl Component for MailListing { }, - _ => { unreachable!() }, } }, _ => { diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 2d601003a..0015faa07 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -7,8 +7,8 @@ use std::process::{Command, Stdio}; enum ViewMode { Normal, Url, - Attachment, - Raw, + // Attachment, + // Raw, } /// Contains an Envelope view, with sticky headers, a pager for the body, and subviews for more @@ -140,11 +140,10 @@ impl Component for MailView { match self.mode { ViewMode::Url => { // URL indexes must be colored (ugh..) - let (cols, _) = buf.size(); let lines: Vec<&str> = text.split('\n').collect(); let mut shift = 0; - for (ridx, r) in lines.iter().enumerate() { - for (lidx, l) in finder.links(&r).enumerate() { + for r in lines.iter() { + for l in finder.links(&r) { buf[(l.start() + shift - 1, 0)].set_fg(Color::Byte(226)); buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226)); buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226)); @@ -184,7 +183,7 @@ impl Component for MailView { self.cmd_buf.clear(); - let url = { + { let threaded = context.accounts[self.coordinates.0].runtime_settings.threaded; let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1].as_ref().unwrap().as_ref().unwrap(); let envelope_idx: usize = if threaded { @@ -195,7 +194,8 @@ impl Component for MailView { let envelope: &Envelope = &mailbox.collection[envelope_idx]; if let Some(u) = envelope.body().attachments().get(lidx) { - eprintln!("{:?}", u); + let p = create_temp_file(&decode(u), None); + eprintln!("{:?}", p); } else { context.replies.push_back(UIEvent { id: 0, event_type: UIEventType::StatusNotification(format!("Attachment `{}` not found.", lidx)) }); @@ -231,7 +231,7 @@ impl Component for MailView { }; - let open_url = Command::new("xdg-open") + Command::new("xdg-open") .arg(url) .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -243,7 +243,7 @@ impl Component for MailView { match self.mode { ViewMode::Normal => { self.mode = ViewMode::Url }, ViewMode::Url => { self.mode = ViewMode::Normal }, - _ => {}, + //_ => {}, } self.dirty = true; }, diff --git a/ui/src/components/mod.rs b/ui/src/components/mod.rs index 56eddbf59..10aa37e1c 100644 --- a/ui/src/components/mod.rs +++ b/ui/src/components/mod.rs @@ -43,17 +43,17 @@ const HORZ_BOUNDARY: char = '─'; const VERT_BOUNDARY: char = '│'; /// The top-left corner -const TOP_LEFT_CORNER: char = '┌'; +const _TOP_LEFT_CORNER: char = '┌'; /// The top-right corner -const TOP_RIGHT_CORNER: char = '┐'; +const _TOP_RIGHT_CORNER: char = '┐'; /// The bottom-left corner -const BOTTOM_LEFT_CORNER: char = '└'; +const _BOTTOM_LEFT_CORNER: char = '└'; /// The bottom-right corner -const BOTTOM_RIGHT_CORNER: char = '┘'; +const _BOTTOM_RIGHT_CORNER: char = '┘'; const LIGHT_VERTICAL_AND_RIGHT: char = '├'; -const LIGHT_VERTICAL_AND_LEFT: char = '┤'; +const _LIGHT_VERTICAL_AND_LEFT: char = '┤'; const LIGHT_DOWN_AND_HORIZONTAL: char = '┬'; diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index d448d8e1b..6bfd1605d 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -2,9 +2,6 @@ */ use super::*; -use melib::mailbox::email::interpret_format_flowed; -use melib::mailbox::email::Attachment; - /// A horizontally split in half container. pub struct HSplit { top: Entity, @@ -428,22 +425,22 @@ impl Component for StatusBar { // A box with a text content. pub struct TextBox { - content: String, + _content: String, } impl TextBox { pub fn new(s: String) -> Self { TextBox { - content: s, + _content: s, } } } impl Component for TextBox { - fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { + fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) { } - fn process_event(&mut self, event: &UIEvent, context: &mut Context) { + fn process_event(&mut self, _event: &UIEvent, _context: &mut Context) { return; } } diff --git a/ui/src/execute/mod.rs b/ui/src/execute/mod.rs index 9b481f432..c0e4a722a 100644 --- a/ui/src/execute/mod.rs +++ b/ui/src/execute/mod.rs @@ -1,7 +1,7 @@ /*! A parser module for user commands passed through the Ex mode. */ use std; -use nom::{digit, alpha}; +use nom::{digit, }; named!(usize_c, @@ -12,7 +12,9 @@ named!(pub goto, call!(usize_c)) ); +/* named!(pub sort<&str>, preceded!(tag!("sort "), map_res!(call!(alpha), std::str::from_utf8)) ); + */ diff --git a/ui/src/helpers.rs b/ui/src/helpers.rs index a276178cf..83bb3fa9d 100644 --- a/ui/src/helpers.rs +++ b/ui/src/helpers.rs @@ -1,10 +1,7 @@ use std; use std::path::PathBuf; use std::io::Write; -use std::ops::{Deref, DerefMut}; - -use std::fs; use uuid::Uuid; #[derive(Debug)] @@ -37,6 +34,7 @@ pub fn create_temp_file(bytes: &[u8], filename: Option<&PathBuf>) -> File { }; let mut f = std::fs::File::create(path).unwrap(); + f.write(bytes).unwrap(); f.flush().unwrap(); File { diff --git a/ui/src/lib.rs b/ui/src/lib.rs index f470fc674..a96f9f716 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -141,10 +141,10 @@ impl fmt::Display for UIMode { /// An event notification that is passed to Entities for handling. pub struct Notification { - title: String, - content: String, + _title: String, + _content: String, - timestamp: std::time::Instant, + _timestamp: std::time::Instant, } /// A context container for loaded settings, accounts, UI changes, etc. @@ -158,7 +158,7 @@ pub struct Context { /// Events queue that components send back to the state replies: VecDeque, - backends: Backends, + _backends: Backends, input_thread: chan::Sender, } @@ -225,7 +225,7 @@ impl State { context: Context { accounts: accounts, - backends: backends, + _backends: backends, settings: settings.clone(), runtime_settings: settings, dirty_areas: VecDeque::with_capacity(5), @@ -381,7 +381,7 @@ impl State { in_pipe.write(&buf).unwrap(); std::fs::remove_file(file.path()).unwrap(); } - let output = output.wait_with_output().expect("Failed to read stdout"); + output.wait_with_output().expect("Failed to read stdout"); return; },