diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-03-14 12:19:25 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:39 +0300 |
commit | bf038428c2cc3da8eb348524be06ac612612d61c (patch) | |
tree | fe10fb1a8e959a862270d6cb4147e7f5525f0800 | |
parent | e7c95ba2297a9bd155760ee9adc14406401c6184 (diff) |
Run rustfmt
36 files changed, 1020 insertions, 723 deletions
diff --git a/melib/src/addressbook.rs b/melib/src/addressbook.rs index 420719d8..3db7f1ed 100644 --- a/melib/src/addressbook.rs +++ b/melib/src/addressbook.rs @@ -19,8 +19,8 @@ * along with meli. If not, see <http://www.gnu.org/licenses/>. */ use chrono::{DateTime, Local}; -use uuid::Uuid; use fnv::FnvHashMap; +use uuid::Uuid; use std::ops::Deref; @@ -31,7 +31,7 @@ pub struct AddressBook { display_name: String, created: DateTime<Local>, last_edited: DateTime<Local>, - cards: FnvHashMap<CardId, Card> + cards: FnvHashMap<CardId, Card>, } #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] @@ -44,7 +44,6 @@ pub struct Card { name_prefix: String, name_suffix: String, //address - birthday: Option<DateTime<Local>>, email: String, url: String, @@ -74,7 +73,11 @@ impl AddressBook { self.cards.contains_key(&card_id) } pub fn search(&self, term: &str) -> Vec<String> { - self.cards.values().filter(|c| c.email.contains(term)).map(|c| c.email.clone()).collect() + self.cards + .values() + .filter(|c| c.email.contains(term)) + .map(|c| c.email.clone()) + .collect() } } @@ -86,7 +89,6 @@ impl Deref for AddressBook { } } - impl Card { pub fn new() -> Card { Card { @@ -98,7 +100,6 @@ impl Card { name_prefix: String::new(), name_suffix: String::new(), //address - birthday: None, email: String::new(), url: String::new(), @@ -182,7 +183,6 @@ impl Card { pub fn extra_property(&self, key: &str) -> Option<&str> { self.extra_properties.get(key).map(|v| v.as_str()) } - } impl From<FnvHashMap<String, String>> for Card { diff --git a/melib/src/lib.rs b/melib/src/lib.rs index 7ba22d0c..7a983a17 100644 --- a/melib/src/lib.rs +++ b/melib/src/lib.rs @@ -18,11 +18,11 @@ * You should have received a copy of the GNU General Public License * along with meli. If not, see <http://www.gnu.org/licenses/>. */ +pub mod addressbook; pub mod async; pub mod conf; pub mod error; pub mod mailbox; -pub mod addressbook; #[macro_use] extern crate serde_derive; @@ -38,8 +38,8 @@ extern crate chan; #[macro_use] extern crate bitflags; -extern crate uuid; extern crate fnv; +extern crate uuid; pub use conf::*; pub use mailbox::*; diff --git a/melib/src/mailbox/backends/maildir/backend.rs b/melib/src/mailbox/backends/maildir/backend.rs index afb5d06f..6b7da6bd 100644 --- a/melib/src/mailbox/backends/maildir/backend.rs +++ b/melib/src/mailbox/backends/maildir/backend.rs @@ -27,7 +27,7 @@ extern crate xdg; use super::{MaildirFolder, MaildirOp}; use async::*; use conf::AccountSettings; -use error::{Result, MeliError}; +use error::{MeliError, Result}; use mailbox::backends::{ BackendFolder, BackendOp, Folder, FolderHash, MailBackend, RefreshEvent, RefreshEventConsumer, RefreshEventKind::*, @@ -132,16 +132,16 @@ fn get_file_hash(file: &Path) -> EnvelopeHash { } fn move_to_cur(p: PathBuf) -> PathBuf { - let mut new = p.clone(); - { - let file_name = p.file_name().unwrap(); - new.pop(); - new.pop(); + let mut new = p.clone(); + { + let file_name = p.file_name().unwrap(); + new.pop(); + new.pop(); - new.push("cur"); - new.push(file_name); - new.set_extension(":2,"); - } + new.push("cur"); + new.push(file_name); + new.set_extension(":2,"); + } eprintln!("moved to cur: {}", new.display()); fs::rename(p, &new).unwrap(); new @@ -347,7 +347,10 @@ impl MailBackend for MaildirType { } } - Err(MeliError::new(format!("'{}' is not a valid folder.", folder))) + Err(MeliError::new(format!( + "'{}' is not a valid folder.", + folder + ))) } } @@ -447,13 +450,13 @@ impl MaildirType { let thunk = move || { let mut path = path.clone(); let cache_dir = cache_dir.clone(); - path.push("new"); - for d in path.read_dir()? { - if let Ok(p) = d { - move_to_cur(p.path()); - } + path.push("new"); + for d in path.read_dir()? { + if let Ok(p) = d { + move_to_cur(p.path()); } - path.pop(); + } + path.pop(); path.push("cur"); let iter = path.read_dir()?; diff --git a/melib/src/mailbox/collection.rs b/melib/src/mailbox/collection.rs index 7b73e917..cfee4e87 100644 --- a/melib/src/mailbox/collection.rs +++ b/melib/src/mailbox/collection.rs @@ -56,24 +56,24 @@ impl Collection { let threads = Threads::new(&mut envelopes); /*let cache_dir = - xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash())) - .unwrap(); - if let Some(cached) = cache_dir.find_cache_file("threads") { - let reader = io::BufReader::new(fs::File::open(cached).unwrap()); - let result: result::Result<Threads, _> = bincode::deserialize_from(reader); - let ret = if let Ok(mut cached_t) = result { -use std::iter::FromIterator; - eprintln!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", FnvHashSet::from_iter(envelopes.keys().cloned()), cached_t.hash_set); - cached_t.amend(&mut envelopes); - cached_t - } else { - Threads::new(&mut envelopes) - }; - ret - } else { - Threads::new(&mut envelopes) - }; - */ + xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash())) + .unwrap(); + if let Some(cached) = cache_dir.find_cache_file("threads") { + let reader = io::BufReader::new(fs::File::open(cached).unwrap()); + let result: result::Result<Threads, _> = bincode::deserialize_from(reader); + let ret = if let Ok(mut cached_t) = result { + use std::iter::FromIterator; + eprintln!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", FnvHashSet::from_iter(envelopes.keys().cloned()), cached_t.hash_set); + cached_t.amend(&mut envelopes); + cached_t + } else { + Threads::new(&mut envelopes) + }; + ret + } else { + Threads::new(&mut envelopes) + }; + */ Collection { folder: folder.clone(), diff --git a/melib/src/mailbox/email.rs b/melib/src/mailbox/email.rs index 8cc16fec..2f0e582e 100644 --- a/melib/src/mailbox/email.rs +++ b/melib/src/mailbox/email.rs @@ -74,7 +74,7 @@ impl Address { Address::Group(g) => g.display_name.display(&g.raw), } } - + pub fn get_email(&self) -> String { match self { Address::Mailbox(m) => m.address_spec.display(&m.raw), @@ -94,11 +94,11 @@ impl PartialEq for Address { s.address_spec.display(&s.raw) == o.address_spec.display(&o.raw) } (Address::Group(s), Address::Group(o)) => { - s.display_name.display(&s.raw) == o.display_name.display(&o.raw) && s - .mailbox_list - .iter() - .zip(o.mailbox_list.iter()) - .fold(true, |b, (s, o)| b && (s == o)) + s.display_name.display(&s.raw) == o.display_name.display(&o.raw) + && s.mailbox_list + .iter() + .zip(o.mailbox_list.iter()) + .fold(true, |b, (s, o)| b && (s == o)) } } } @@ -616,22 +616,22 @@ impl Envelope { pub fn message_id_raw(&self) -> Cow<str> { String::from_utf8_lossy(self.message_id.raw()) } - fn set_date(&mut self, new_val: &[u8]) { + fn set_date(&mut self, new_val: &[u8]) { self.date = String::from_utf8_lossy(new_val).into_owned(); } - fn set_bcc(&mut self, new_val: Vec<Address>) { + fn set_bcc(&mut self, new_val: Vec<Address>) { self.bcc = new_val; } - fn set_cc(&mut self, new_val: Vec<Address>) { + fn set_cc(&mut self, new_val: Vec<Address>) { self.cc = new_val; } - fn set_from(&mut self, new_val: Vec<Address>) { + fn set_from(&mut self, new_val: Vec<Address>) { self.from = new_val; } - fn set_to(&mut self, new_val: Vec<Address>) { + fn set_to(&mut self, new_val: Vec<Address>) { self.to = new_val; } - fn set_in_reply_to(&mut self, new_val: &[u8]) { + fn set_in_reply_to(&mut self, new_val: &[u8]) { let slice = match parser::message_id(new_val).to_full_result() { Ok(v) => v, Err(_) => { @@ -641,10 +641,10 @@ impl Envelope { }; self.in_reply_to = Some(MessageID::new(new_val, slice)); } - fn set_subject(&mut self, new_val: Vec<u8>) { + fn set_subject(&mut self, new_val: Vec<u8>) { self.subject = Some(new_val); } - fn set_message_id(&mut self, new_val: &[u8]) { + fn set_message_id(&mut self, new_val: &[u8]) { let slice = match parser::message_id(new_val).to_full_result() { Ok(v) => v, Err(_) => { @@ -653,7 +653,7 @@ impl Envelope { }; self.message_id = MessageID::new(new_val, slice); } - fn push_references(&mut self, new_val: &[u8]) { + fn push_references(&mut self, new_val: &[u8]) { let slice = match parser::message_id(new_val).to_full_result() { Ok(v) => v, Err(_) => { @@ -685,7 +685,7 @@ impl Envelope { } } } - fn set_references(&mut self, new_val: &[u8]) { + fn set_references(&mut self, new_val: &[u8]) { match self.references { Some(ref mut s) => { s.raw = new_val.into(); @@ -713,10 +713,10 @@ impl Envelope { pub fn thread(&self) -> usize { self.thread } - pub fn set_thread(&mut self, new_val: usize) { + pub fn set_thread(&mut self, new_val: usize) { self.thread = new_val; } - pub fn set_datetime(&mut self, new_val: chrono::DateTime<chrono::FixedOffset>) { + pub fn set_datetime(&mut self, new_val: chrono::DateTime<chrono::FixedOffset>) { self.timestamp = new_val.timestamp() as UnixTimestamp; } pub fn set_flag(&mut self, f: Flag, mut operation: Box<BackendOp>) -> Result<()> { diff --git a/melib/src/mailbox/email/attachments.rs b/melib/src/mailbox/email/attachments.rs index b49f60c4..b0d95413 100644 --- a/melib/src/mailbox/email/attachments.rs +++ b/melib/src/mailbox/email/attachments.rs @@ -71,73 +71,77 @@ impl AttachmentBuilder { } pub fn content_type(&mut self, value: &[u8]) -> &Self { match parser::content_type(value).to_full_result() { - Ok((ct, cst, params)) => if ct.eq_ignore_ascii_case(b"multipart") { - let mut boundary = None; - for (n, v) in params { - if n.eq_ignore_ascii_case(b"boundary") { - boundary = Some(v); - break; + Ok((ct, cst, params)) => { + if ct.eq_ignore_ascii_case(b"multipart") { + let mut boundary = None; + for (n, v) in params { + if n.eq_ignore_ascii_case(b"boundary") { + boundary = Some(v); + break; + } } - } - assert!(boundary.is_some()); - let _boundary = boundary.unwrap(); - let offset = (_boundary.as_ptr() as usize).wrapping_sub(value.as_ptr() as usize); - let boundary = SliceBuild::new(offset, _boundary.len()); - let subattachments = Self::subattachments(&self.raw, boundary.get(&value)); - assert!(!subattachments.is_empty()); - self.content_type = ContentType::Multipart { - boundary, - kind: if cst.eq_ignore_ascii_case(b"mixed") { - MultipartType::Mixed - } else if cst.eq_ignore_ascii_case(b"alternative") { - MultipartType::Alternative - } else if cst.eq_ignore_ascii_case(b"digest") { - MultipartType::Digest - } else { - Default::default() - }, - subattachments, - }; - } else if ct.eq_ignore_ascii_case(b"text") { - self.content_type = ContentType::Text { - kind: Text::Plain, - charset: Charset::UTF8, - }; - for (n, v) in params { - if n.eq_ignore_ascii_case(b"charset") { + assert!(boundary.is_some()); + let _boundary = boundary.unwrap(); + let offset = + (_boundary.as_ptr() as usize).wrapping_sub(value.as_ptr() as usize); + let boundary = SliceBuild::new(offset, _boundary.len()); + let subattachments = Self::subattachments(&self.raw, boundary.get(&value)); + assert!(!subattachments.is_empty()); + self.content_type = ContentType::Multipart { + boundary, + kind: if cst.eq_ignore_ascii_case(b"mixed") { + MultipartType::Mixed + } else if cst.eq_ignore_ascii_case(b"alternative") { + MultipartType::Alternative + } else if cst.eq_ignore_ascii_case(b"digest") { + MultipartType::Digest + } else { + Default::default() + }, + subattachments, + }; + } else if ct.eq_ignore_ascii_case(b"text") { + self.content_type = ContentType::Text { + kind: Text::Plain, + charset: Charset::UTF8, + }; + for (n, v) in params { + if n.eq_ignore_ascii_case(b"charset") { + if let ContentType::Text { + charset: ref mut c, .. + } = self.content_type + { + *c = Charset::from(v); + } + break; + } + } + if cst.eq_ignore_ascii_case(b"html") { if let ContentType::Text { - charset: ref mut c, .. + kind: ref mut k, .. } = self.content_type { - *c = Charset::from(v); + *k = Text::Html; + } + } else if !cst.eq_ignore_ascii_case(b"plain") { + if let ContentType::Text { + kind: ref mut k, .. + } = self.content_type + { + *k = Text::Other { tag: cst.into() }; } - break; - } - } - if cst.eq_ignore_ascii_case(b"html") { - if let ContentType::Text { - kind: ref mut k, .. - } = self.content_type - { - *k = Text::Html; - } - } else if !cst.eq_ignore_ascii_case(b"plain") { - if let ContentType::Text { - kind: ref mut k, .. - } = self.content_type - { - *k = Text::Other { tag: cst.into() }; } + } else if ct.eq_ignore_ascii_case(b"message") && cst.eq_ignore_ascii_case(b"rfc822") + { + self.content_type = ContentType::MessageRfc822; + } else { + let mut tag: Vec<u8> = Vec::with_capacity(ct.len() + cst.len() + 1); + tag.extend(ct); + tag.push(b'/'); + tag.extend(cst); + self.content_type = ContentType::Unsupported { tag }; } - } else if ct.eq_ignore_ascii_case(b"message") && cst.eq_ignore_ascii_case(b"rfc822") { - self.content_type = ContentType::MessageRfc822; - } else { - let mut tag: Vec<u8> = Vec::with_capacity(ct.len() + cst.len() + 1); - tag.extend(ct); - tag.push(b'/'); - tag.extend(cst); - self.content_type = ContentType::Unsupported { tag }; - }, + } Err(v) => { eprintln!("parsing error in content_type: {:?} {:?}", value, v); } @@ -405,23 +409,25 @@ fn decode_rec_helper(a: &Attachment, filter: &Option<Filter>) -> Vec<u8> { kind: ref multipart_type, subattachments: ref sub_att_vec, .. - } => if *multipart_type == MultipartType::Alternative { - for a in sub_att_vec { - if let ContentType::Text { - kind: Text::Plain, .. - } = a.content_type - { - return decode_helper(a, filter); + } => { + if *multipart_type == MultipartType::Alternative { + for a in sub_att_vec { + if let ContentType::Text { + kind: Text::Plain, .. + } = a.content_type + { + return decode_helper(a, filter); + } } + decode_helper(a, filter) + } else { + let mut vec = Vec::new(); + for a in sub_att_vec { + vec.extend(decode_rec_helper(a, filter)); + } + vec } - decode_helper(a, filter) - } else { - let mut vec = Vec::new(); - for a in sub_att_vec { - vec.extend(decode_rec_helper(a, filter)); - } - vec - }, + } }; if let Some(filter) = filter { filter(a, &mut ret); diff --git a/melib/src/mailbox/email/compose.rs b/melib/src/mailbox/email/compose.rs index e027cf7f..cad33e5c 100644 --- a/melib/src/mailbox/email/compose.rs +++ b/melib/src/mailbox/email/compose.rs @@ -3,8 +3,8 @@ use chrono::{DateTime, Local}; use data_encoding::BASE64_MIME; use std::str; -mod random; mod mime; +mod random; //use self::mime::*; @@ -70,13 +70,16 @@ impl str::FromStr for Draft { if ignore_header(k) { continue; } - if ret.headers.insert( - String::from_utf8(k.to_vec())?, - String::from_utf8(v.to_vec())?, - ).is_none() { + if ret + .headers + .insert( + String::from_utf8(k.to_vec())?, + String::from_utf8(v.to_vec())?, + ) + .is_none() + { ret.header_order.push(String::from_utf8(k.to_vec())?); } - } let body = Envelope::new(0).body_bytes(s.as_bytes()); @@ -191,7 +194,6 @@ impl Draft { } Ok(ret) - } } diff --git a/melib/src/mailbox/email/parser.rs b/melib/src/mailbox/email/parser.rs index 5b0e0b75..a8d7ef34 100644 --- a/melib/src/mailbox/email/parser.rs +++ b/melib/src/mailbox/email/parser.rs @@ -135,16 +135,19 @@ named!( named!( header_no_val<(&[u8], &[u8])>, - do_parse!( - name: complete!(name) >> - tag!(b":") >> - opt!(is_a!(" \t")) >> - tag!(b"\n") >> - ( { (name, b"") } ))); + do_parse!( + name: complete!(name) + >> tag!(b":") + >> opt!(is_a!(" \t")) + >> tag!(b"\n") + >> ({ (name, b"") }) + ) +); named!( header<(&[u8], &[u8])>, - alt_complete!(header_no_val | header_has_val)); + alt_complete!(header_no_val | header_has_val) +); /* Parse all headers -> Vec<(&str, Vec<&str>)> */ named!(pub headers<std::vec::Vec<(&[u8], &[u8])>>, many1!(complete!(header))); diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/rustfmt.toml @@ -48,9 +48,9 @@ fn main() { //let _stdout = stdout(); //let mut _stdout = _stdout.lock(); /* - let _stderr = stderr(); - let mut _stderr = _stderr.lock(); - */ + let _stderr = stderr(); + let mut _stderr = _stderr.lock(); + */ /* Catch SIGWINCH to handle terminal resizing */ let signal = chan_signal::notify(&[Signal::WINCH]); @@ -66,7 +66,11 @@ fn main() { let menu = Entity::from(Box::new(AccountMenu::new(&state.context.accounts))); let listing = listing::Listing::from(IndexStyle::Compact); let b = Entity::from(Box::new(listing)); - let tabs = Box::new(Tabbed::new(vec![Box::new(VSplit::new(menu, b, 90, true)), Box::new(AccountsPanel::new(&state.context)), Box::new(ContactList::default())])); + let tabs = Box::new(Tabbed::new(vec![ + Box::new(VSplit::new(menu, b, 90, true)), + Box::new(AccountsPanel::new(&state.context)), + Box::new(ContactList::default()), + ])); let window = Entity::from(tabs); let status_bar = Entity::from(Box::new(StatusBar::new(window))); @@ -75,7 +79,9 @@ fn main() { let xdg_notifications = Entity::from(Box::new(ui::components::notifications::XDGNotifications {})); state.register_entity(xdg_notifications); - state.register_entity(Entity::from(Box::new(ui::components::notifications::NotificationFilter {}))); + state.register_entity(Entity::from(Box::new( + ui::components::notifications::NotificationFilter {}, + ))); /* Keep track of the input mode. See ui::UIMode for details */ 'main: loop { diff --git a/ui/src/components.rs b/ui/src/components.rs index d6dd2d9e..1ded7791 100644 --- a/ui/src/components.rs +++ b/ui/src/components.rs @@ -20,10 +20,10 @@ */ /*! - Components are ways to handle application data. They can draw on the terminal and receive events, but also do other stuff as well. (For example, see the `notifications` module.) +Components are ways to handle application data. They can draw on the terminal and receive events, but also do other stuff as well. (For example, see the `notifications` module.) - See the `Component` Trait for more details. - */ +See the `Component` Trait for more details. +*/ use super::*; @@ -76,8 +76,6 @@ const _DOUBLE_DOWN_AND_LEFT: char = '╗'; const _DOUBLE_UP_AND_LEFT: char = '╝'; const _DOUBLE_UP_AND_RIGHT: char = '╚'; - - type EntityId = Uuid; /// `Entity` is a container for Components. @@ -157,7 +155,9 @@ pub trait Component: Display + Debug + Send { fn kill(&mut self, _id: EntityId) {} fn set_id(&mut self, _id: EntityId) {} - fn get_shortcuts(&self, context: &Context) -> ShortcutMap { Default::default() } + fn get_shortcuts(&self, context: &Context) -> ShortcutMap { + Default::default() + } } /* @@ -429,20 +429,23 @@ pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: char) { } pub fn create_box(grid: &mut CellBuffer, area: Area) { - let upper_left = upper_left!(area); - let bottom_right = bottom_right!(area); + if !is_valid_area!(area) { + return; + } + let upper_left = upper_left!(area); + let bottom_right = bottom_right!(area); - for x in get_x(upper_left)..get_x(bottom_right) { - grid[(x, get_y(upper_left))].set_ch(HORZ_BOUNDARY); - grid[(x, get_y(bottom_right))].set_ch(HORZ_BOUNDARY); - } + for x in get_x(upper_left)..get_x(bottom_right) { + grid[(x, get_y(upper_left))].set_ch(HORZ_BOUNDARY); + grid[(x, get_y(bottom_right))].set_ch(HORZ_BOUNDARY); + } - for y in get_y(upper_left)..get_y(bottom_right) { - grid[(get_x(upper_left), y)].set_ch(VERT_BOUNDARY); - grid[(get_x(bottom_right), y)].set_ch(VERT_BOUNDARY); - } - set_and_join_box(grid, upper_left, HORZ_BOUNDARY); - set_and_join_box(grid, set_x(upper_left, get_x(bottom_right)), HORZ_BOUNDARY); - set_and_join_box(grid, set_y(upper_left, get_y(bottom_right)), VERT_BOUNDARY); - set_and_join_box(grid, bottom_right, VERT_BOUNDARY); + for y in get_y(upper_left)..get_y(bottom_right) { + grid[(get_x(upper_left), y)].set_ch(VERT_BOUNDARY); + grid[(get_x(bottom_right), y)].set_ch(VERT_BOUNDARY); + } + set_and_join_box(grid, upper_left, HORZ_BOUNDARY); + set_and_join_box(grid, set_x(upper_left, get_x(bottom_right)), HORZ_BOUNDARY); + set_and_join_box(grid, set_y(upper_left, get_y(bottom_right)), VERT_BOUNDARY); + set_and_join_box(grid, bottom_right, VERT_BOUNDARY); } diff --git a/ui/src/components/contacts.rs b/ui/src/components/contacts.rs index 08190b85..9bd73f86 100644 --- a/ui/src/components/contacts.rs +++ b/ui/src/components/contacts.rs @@ -78,7 +78,7 @@ impl ContactManager { Color::Default, ((0, 0), (width, 0)), |