run cargo fmt

embed
Manos Pitsidianakis 2019-04-04 14:24:05 +03:00
parent 1c7aa0ec9c
commit ee4462881e
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
21 changed files with 208 additions and 127 deletions

View File

@ -63,7 +63,6 @@ impl Into<String> for MeliError {
} }
} }
impl Error for MeliError { impl Error for MeliError {
fn description(&self) -> &str { fn description(&self) -> &str {
&self.details &self.details

View File

@ -29,8 +29,8 @@ pub mod email;
pub use self::email::*; pub use self::email::*;
/* Mail backends. Currently only maildir is supported */ /* Mail backends. Currently only maildir is supported */
pub mod backends; pub mod backends;
use crate::error::Result;
use self::backends::Folder; use self::backends::Folder;
use crate::error::Result;
pub mod thread; pub mod thread;
pub use self::thread::{SortField, SortOrder, ThreadNode, Threads}; pub use self::thread::{SortField, SortOrder, ThreadNode, Threads};

View File

@ -19,14 +19,14 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>. * along with meli. If not, see <http://www.gnu.org/licenses/>.
*/ */
use super::{MaildirFolder, MaildirOp};
use crate::async_workers::*;
use crate::conf::AccountSettings;
use crate::error::{MeliError, Result};
use super::{ use super::{
BackendFolder, BackendOp, Folder, FolderHash, MailBackend, RefreshEvent, RefreshEventConsumer, BackendFolder, BackendOp, Folder, FolderHash, MailBackend, RefreshEvent, RefreshEventConsumer,
RefreshEventKind::*, RefreshEventKind::*,
}; };
use super::{MaildirFolder, MaildirOp};
use crate::async_workers::*;
use crate::conf::AccountSettings;
use crate::error::{MeliError, Result};
use crate::mailbox::email::{Envelope, EnvelopeHash}; use crate::mailbox::email::{Envelope, EnvelopeHash};
use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
@ -36,7 +36,6 @@ use std::sync::mpsc::channel;
//use std::sync::mpsc::sync_channel; //use std::sync::mpsc::sync_channel;
//use std::sync::mpsc::SyncSender; //use std::sync::mpsc::SyncSender;
//use std::time::Duration; //use std::time::Duration;
use std::thread;
use fnv::{FnvHashMap, FnvHasher}; use fnv::{FnvHashMap, FnvHasher};
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::ffi::OsStr; use std::ffi::OsStr;
@ -47,6 +46,7 @@ use std::ops::{Deref, DerefMut};
use std::path::{Component, Path, PathBuf}; use std::path::{Component, Path, PathBuf};
use std::result; use std::result;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::thread;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct HashIndex { pub struct HashIndex {
@ -344,13 +344,26 @@ eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`",
path.push("cur"); path.push("cur");
{ {
let mut rand_buf = [0u8; 16]; let mut rand_buf = [0u8; 16];
let mut f = fs::File::open("/dev/urandom").expect("Could not open /dev/urandom for reading"); let mut f = fs::File::open("/dev/urandom")
f.read_exact(&mut rand_buf).expect("Could not read from /dev/urandom/"); .expect("Could not open /dev/urandom for reading");
f.read_exact(&mut rand_buf)
.expect("Could not read from /dev/urandom/");
let mut hostn_buf = String::with_capacity(256); let mut hostn_buf = String::with_capacity(256);
let mut f = fs::File::open("/etc/hostname").expect("Could not open /etc/hostname for reading"); let mut f = fs::File::open("/etc/hostname")
f.read_to_string(&mut hostn_buf).expect("Could not read from /etc/hostname"); .expect("Could not open /etc/hostname for reading");
let timestamp = std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH).unwrap().as_millis(); f.read_to_string(&mut hostn_buf)
path.push(&format!("{}.{:x}_{}.{}:2,", timestamp, u128::from_be_bytes(rand_buf), std::process::id(), hostn_buf.trim())); .expect("Could not read from /etc/hostname");
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis();
path.push(&format!(
"{}.{:x}_{}.{}:2,",
timestamp,
u128::from_be_bytes(rand_buf),
std::process::id(),
hostn_buf.trim()
));
} }
if cfg!(feature = "debug_log") { if cfg!(feature = "debug_log") {
eprintln!("saving at {}", path.display()); eprintln!("saving at {}", path.display());
@ -363,8 +376,8 @@ eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`",
} }
Err(MeliError::new(format!( Err(MeliError::new(format!(
"'{}' is not a valid folder.", "'{}' is not a valid folder.",
folder folder
))) )))
} }
} }
@ -409,7 +422,7 @@ impl MaildirType {
} }
} }
} }
if folders.is_empty() { if folders.is_empty() {
recurse_folders(&mut folders, &path); recurse_folders(&mut folders, &path);
} else { } else {

View File

@ -103,7 +103,11 @@ impl Collection {
env.set_hash(new_hash); env.set_hash(new_hash);
self.envelopes.insert(new_hash, env); self.envelopes.insert(new_hash, env);
{ {
if self.threads.update_envelope(old_hash, new_hash, &self.envelopes).is_ok() { if self
.threads
.update_envelope(old_hash, new_hash, &self.envelopes)
.is_ok()
{
return; return;
} }
} }
@ -119,7 +123,11 @@ impl Collection {
let new_hash = envelope.hash(); let new_hash = envelope.hash();
self.envelopes.insert(new_hash, envelope); self.envelopes.insert(new_hash, envelope);
{ {
if self.threads.update_envelope(old_hash, new_hash, &self.envelopes).is_ok() { if self
.threads
.update_envelope(old_hash, new_hash, &self.envelopes)
.is_ok()
{
return; return;
} }
} }

View File

@ -32,8 +32,8 @@ pub use crate::attachments::*;
pub mod parser; pub mod parser;
use parser::BytesExt; use parser::BytesExt;
use crate::error::{MeliError, Result};
use super::backends::BackendOp; use super::backends::BackendOp;
use crate::error::{MeliError, Result};
use std::borrow::Cow; use std::borrow::Cow;
use std::cmp::Ordering; use std::cmp::Ordering;

View File

@ -18,10 +18,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>. * along with meli. If not, see <http://www.gnu.org/licenses/>.
*/ */
use data_encoding::BASE64_MIME;
use crate::mailbox::email::parser; use crate::mailbox::email::parser;
use crate::mailbox::email::parser::BytesExt; use crate::mailbox::email::parser::BytesExt;
use crate::mailbox::email::EnvelopeWrapper; use crate::mailbox::email::EnvelopeWrapper;
use data_encoding::BASE64_MIME;
use std::fmt; use std::fmt;
use std::str; use std::str;

View File

@ -1,7 +1,7 @@
use super::*; use super::*;
use crate::mailbox::backends::BackendOp;
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use data_encoding::BASE64_MIME; use data_encoding::BASE64_MIME;
use crate::mailbox::backends::BackendOp;
use std::str; use std::str;
mod mime; mod mime;

View File

@ -1339,7 +1339,9 @@ fn node_build(
let mut has_unseen = if let Some(msg) = thread_nodes[idx].message { let mut has_unseen = if let Some(msg) = thread_nodes[idx].message {
!collection[&msg].is_seen() !collection[&msg].is_seen()
} else { false }; } else {
false
};
let mut child_vec: Vec<ThreadTree> = Vec::new(); let mut child_vec: Vec<ThreadTree> = Vec::new();
thread_nodes[idx].len = thread_nodes[idx].children.len(); thread_nodes[idx].len = thread_nodes[idx].children.len();

View File

@ -29,7 +29,6 @@ use std::alloc::System;
#[global_allocator] #[global_allocator]
static GLOBAL: System = System; static GLOBAL: System = System;
use ui; use ui;
pub use melib::*; pub use melib::*;

View File

@ -74,7 +74,12 @@ impl ContactList {
if self.id_positions.capacity() < book.len() { if self.id_positions.capacity() < book.len() {
self.id_positions.reserve(book.len()); self.id_positions.reserve(book.len());
} }
let mut maxima = ("First Name".len(), "Last Name".len(), "E-mail".len(), "URL".len()); let mut maxima = (
"First Name".len(),
"Last Name".len(),
"E-mail".len(),
"URL".len(),
);
for c in book.values() { for c in book.values() {
self.id_positions.push(*c.id()); self.id_positions.push(*c.id());
@ -94,7 +99,7 @@ impl ContactList {
Color::Default, Color::Default,
((0, 0), (MAX_COLS - 1, self.length)), ((0, 0), (MAX_COLS - 1, self.length)),
false, false,
); );
write_string_to_grid( write_string_to_grid(
"Last Name", "Last Name",
&mut self.content, &mut self.content,
@ -102,15 +107,15 @@ impl ContactList {
Color::Default, Color::Default,
((maxima.0, 0), (MAX_COLS - 1, self.length)), ((maxima.0, 0), (MAX_COLS - 1, self.length)),
false, false,
); );
write_string_to_grid( write_string_to_grid(
"E-mail", "E-mail",
&mut self.content, &mut self.content,
Color::Default, Color::Default,
Color::Default, Color::Default,
(( maxima.1, 0), (MAX_COLS - 1, self.length)), ((maxima.1, 0), (MAX_COLS - 1, self.length)),
false, false,
); );
write_string_to_grid( write_string_to_grid(
"URL", "URL",
&mut self.content, &mut self.content,
@ -118,7 +123,7 @@ impl ContactList {
Color::Default, Color::Default,
((maxima.2, 0), (MAX_COLS - 1, self.length)), ((maxima.2, 0), (MAX_COLS - 1, self.length)),
false, false,
); );
for (i, c) in book.values().enumerate() { for (i, c) in book.values().enumerate() {
self.id_positions.push(*c.id()); self.id_positions.push(*c.id());
@ -143,12 +148,13 @@ impl ContactList {
&mut self.content, &mut self.content,
Color::Default, Color::Default,
Color::Default, Color::Default,
(( maxima.1, i + 1), (MAX_COLS - 1, self.length)), ((maxima.1, i + 1), (MAX_COLS - 1, self.length)),
false, false,
); );
write_string_to_grid( write_string_to_grid(
c.url(), c.url(),
&mut self.content, Color::Default, &mut self.content,
Color::Default,
Color::Default, Color::Default,
((maxima.2, i + 1), (MAX_COLS - 1, self.length)), ((maxima.2, i + 1), (MAX_COLS - 1, self.length)),
false, false,

View File

@ -426,7 +426,7 @@ impl Component for Composer {
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
match (&mut self.mode, &mut self.reply_context, &event.event_type) { match (&mut self.mode, &mut self.reply_context, &event.event_type) {
// don't pass Reply command to thread view in reply_context // don't pass Reply command to thread view in reply_context
(_, _, UIEventType::Input(Key::Char('R'))) => {}, (_, _, UIEventType::Input(Key::Char('R'))) => {}
(ViewMode::Overview, Some((_, ref mut view)), _) => { (ViewMode::Overview, Some((_, ref mut view)), _) => {
if view.process_event(event, context) { if view.process_event(event, context) {
self.dirty = true; self.dirty = true;
@ -501,7 +501,10 @@ impl Component for Composer {
} }
context.replies.push_back(UIEvent { context.replies.push_back(UIEvent {
id: 0, id: 0,
event_type: UIEventType::Notification(Some("Could not save draft.".into()), e.into()) event_type: UIEventType::Notification(
Some("Could not save draft.".into()),
e.into(),
),
}); });
} }
context.replies.push_back(UIEvent { context.replies.push_back(UIEvent {
@ -607,8 +610,7 @@ impl Component for Composer {
fn get_shortcuts(&self, context: &Context) -> ShortcutMap { fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
let mut map = if self.mode.is_overview() { let mut map = if self.mode.is_overview() {
self.pager self.pager.get_shortcuts(context)
.get_shortcuts(context)
} else { } else {
Default::default() Default::default()
}; };
@ -619,21 +621,12 @@ impl Component for Composer {
} }
if self.mode.is_overview() { if self.mode.is_overview() {
map.insert( map.insert("Switch to edit mode", Key::Char('o'));
"Switch to edit mode",
Key::Char('o')
);
} }
if self.mode.is_edit() { if self.mode.is_edit() {
map.insert( map.insert("Switch to overview", Key::Char('v'));
"Switch to overview",
Key::Char('v')
);
} }
map.insert( map.insert("Edit in $EDITOR", Key::Char('e'));
"Edit in $EDITOR",
Key::Char('e')
);
map map
} }

View File

@ -83,7 +83,7 @@ impl Component for Listing {
Listing::Plain(_) => { Listing::Plain(_) => {
return true; return true;
} }
Listing::Threaded(l) => { Listing::Threaded(l) => {
let mut new_l = PlainListing::default(); let mut new_l = PlainListing::default();
new_l.set_coordinates(l.coordinates()); new_l.set_coordinates(l.coordinates());
new_l new_l
@ -102,7 +102,7 @@ impl Component for Listing {
Listing::Threaded(_) => { Listing::Threaded(_) => {
return true; return true;
} }
Listing::Plain(l) => { Listing::Plain(l) => {
let mut new_l = ThreadListing::default(); let mut new_l = ThreadListing::default();
new_l.set_coordinates(l.coordinates()); new_l.set_coordinates(l.coordinates());
new_l new_l
@ -121,7 +121,7 @@ impl Component for Listing {
Listing::Compact(_) => { Listing::Compact(_) => {
return true; return true;
} }
Listing::Threaded(l) => { Listing::Threaded(l) => {
let mut new_l = CompactListing::default(); let mut new_l = CompactListing::default();
new_l.set_coordinates(l.coordinates()); new_l.set_coordinates(l.coordinates());
new_l new_l

View File

@ -275,7 +275,8 @@ impl CompactListing {
/// Draw the list of `Envelope`s. /// Draw the list of `Envelope`s.
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 { if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
} }
let upper_left = upper_left!(area); let upper_left = upper_left!(area);
@ -484,11 +485,15 @@ impl Component for CompactListing {
UIEventType::RefreshMailbox(_) => { UIEventType::RefreshMailbox(_) => {
self.dirty = true; self.dirty = true;
} }
UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { UIEventType::MailboxUpdate((ref idxa, ref idxf))
if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 =>
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
} }
UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { UIEventType::StartupCheck(ref f)
if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) =>
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
} }
@ -534,7 +539,12 @@ impl Component for CompactListing {
false false
} }
fn is_dirty(&self) -> bool { fn is_dirty(&self) -> bool {
self.dirty || if self.unfocused { self.view.is_dirty() } else { false } self.dirty
|| if self.unfocused {
self.view.is_dirty()
} else {
false
}
} }
fn set_dirty(&mut self) { fn set_dirty(&mut self) {
if self.unfocused { if self.unfocused {

View File

@ -252,7 +252,8 @@ impl PlainListing {
/// Draw the list of `Envelope`s. /// Draw the list of `Envelope`s.
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 { if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
} }
let upper_left = upper_left!(area); let upper_left = upper_left!(area);
@ -502,11 +503,15 @@ impl Component for PlainListing {
self.dirty = true; self.dirty = true;
self.view = None; self.view = None;
} }
UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { UIEventType::MailboxUpdate((ref idxa, ref idxf))
if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 =>
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
} }
UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { UIEventType::StartupCheck(ref f)
if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) =>
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
} }

View File

@ -48,7 +48,11 @@ pub struct ThreadListing {
impl ListingTrait for ThreadListing { impl ListingTrait for ThreadListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) { fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) {
(self.cursor_pos.0, self.cursor_pos.1, Some(self.locations[self.cursor_pos.2])) (
self.cursor_pos.0,
self.cursor_pos.1,
Some(self.locations[self.cursor_pos.2]),
)
} }
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) { fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) {
self.new_cursor_pos = (coordinates.0, coordinates.1, 0); self.new_cursor_pos = (coordinates.0, coordinates.1, 0);
@ -291,7 +295,8 @@ impl ThreadListing {
/// Draw the list of `Envelope`s. /// Draw the list of `Envelope`s.
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 { if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
} }
let upper_left = upper_left!(area); let upper_left = upper_left!(area);
@ -660,11 +665,15 @@ impl Component for ThreadListing {
self.dirty = true; self.dirty = true;
self.view = None; self.view = None;
} }
UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { UIEventType::MailboxUpdate((ref idxa, ref idxf))
if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 =>
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
} }
UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { UIEventType::StartupCheck(ref f)
if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) =>
{
self.refresh_mailbox(context); self.refresh_mailbox(context);
self.set_dirty(); self.set_dirty();
} }

View File

@ -88,10 +88,7 @@ impl MailView {
let account = &mut context.accounts[coordinates.0]; let account = &mut context.accounts[coordinates.0];
let (hash, is_seen) = { let (hash, is_seen) = {
let mailbox = &mut account[coordinates.1].as_mut().unwrap(); let mailbox = &mut account[coordinates.1].as_mut().unwrap();
let envelope: &mut Envelope = &mut mailbox let envelope: &mut Envelope = &mut mailbox.collection.entry(coordinates.2).or_default();
.collection
.entry(coordinates.2)
.or_default();
(envelope.hash(), envelope.is_seen()) (envelope.hash(), envelope.is_seen())
}; };
if !is_seen { if !is_seen {
@ -104,10 +101,7 @@ impl MailView {
backend.operation(hash, folder_hash) backend.operation(hash, folder_hash)
}; };
let mailbox = &mut account[coordinates.1].as_mut().unwrap(); let mailbox = &mut account[coordinates.1].as_mut().unwrap();
let envelope: &mut Envelope = &mut mailbox let envelope: &mut Envelope = &mut mailbox.collection.entry(coordinates.2).or_default();
.collection
.entry(coordinates.2)
.or_default();
envelope.set_seen(op).unwrap(); envelope.set_seen(op).unwrap();
} }
MailView { MailView {
@ -428,34 +422,37 @@ impl Component for MailView {
if let ViewMode::ContactSelector(_) = self.mode { if let ViewMode::ContactSelector(_) = self.mode {
if let ViewMode::ContactSelector(s) = if let ViewMode::ContactSelector(s) =
std::mem::replace(&mut self.mode, ViewMode::Normal) std::mem::replace(&mut self.mode, ViewMode::Normal)
{
let account = &mut context.accounts[self.coordinates.0];
let mut results = Vec::new();
{ {
let account = &mut context.accounts[self.coordinates.0]; let mailbox = &account[self.coordinates.1].as_ref().unwrap();
let mut results = Vec::new(); let envelope: &Envelope = &mailbox.collection[&self.coordinates.2];
{ for c in s.collect() {
let mailbox = &account[self.coordinates.1] let c = usize::from_ne_bytes({
.as_ref() [c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]]
.unwrap(); });
let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; for (idx, env) in envelope
for c in s.collect() { .from()
let c = usize::from_ne_bytes({ .iter()
[c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]] .chain(envelope.to().iter())
}); .enumerate()
for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() { {
if idx != c { if idx != c {
continue; continue;
}
let mut new_card: Card = Card::new();
new_card.set_email(env.get_email());
new_card.set_lastname(env.get_display_name());
results.push(new_card);
} }
let mut new_card: Card = Card::new();
new_card.set_email(env.get_email());
new_card.set_lastname(env.get_display_name());
results.push(new_card);
} }
} }
for c in results {
account.address_book.add_card(c);
}
} }
for c in results {
account.address_book.add_card(c);
}
}
return true; return true;
} }
let accounts = &context.accounts; let accounts = &context.accounts;
@ -465,11 +462,13 @@ impl Component for MailView {
let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; let envelope: &Envelope = &mailbox.collection[&self.coordinates.2];
let mut entries = Vec::new(); let mut entries = Vec::new();
for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() { for (idx, env) in envelope
entries.push(( .from()
idx.to_ne_bytes().to_vec(), .iter()
format!("{}", env), .chain(envelope.to().iter())
)); .enumerate()
{
entries.push((idx.to_ne_bytes().to_vec(), format!("{}", env)));
} }
self.mode = ViewMode::ContactSelector(Selector::new(entries, true)); self.mode = ViewMode::ContactSelector(Selector::new(entries, true));
self.dirty = true; self.dirty = true;
@ -651,7 +650,9 @@ impl Component for MailView {
} }
self.dirty = true; self.dirty = true;
} }
UIEventType::EnvelopeRename(_, old_hash, new_hash) if old_hash == self.coordinates.2 => { UIEventType::EnvelopeRename(_, old_hash, new_hash)
if old_hash == self.coordinates.2 =>
{
self.coordinates.2 = new_hash; self.coordinates.2 = new_hash;
self.set_dirty(); self.set_dirty();
} }

View File

@ -79,9 +79,11 @@ impl ThreadView {
if self.entries.is_empty() { if self.entries.is_empty() {
return; return;
} }
let old_focused_entry = if self.entries.len() > self.cursor_pos { let old_focused_entry = if self.entries.len() > self.cursor_pos {
Some(self.entries.remove(self.cursor_pos)) Some(self.entries.remove(self.cursor_pos))
} else { None }; } else {
None
};
let old_expanded_entry = if self.entries.len() > self.expanded_pos { let old_expanded_entry = if self.entries.len() > self.expanded_pos {
Some(self.entries.remove(self.expanded_pos)) Some(self.entries.remove(self.expanded_pos))
@ -93,21 +95,24 @@ impl ThreadView {
let expanded_pos = self.expanded_pos; let expanded_pos = self.expanded_pos;
self.initiate(Some(expanded_pos), context); self.initiate(Some(expanded_pos), context);
if let Some(old_focused_entry) = old_focused_entry { if let Some(old_focused_entry) = old_focused_entry {
if let Some(new_entry_idx) = self.entries.iter().position( if let Some(new_entry_idx) = self.entries.iter().position(|e| {
|e| e.msg_idx == old_focused_entry.msg_idx || e.msg_idx == old_focused_entry.msg_idx
(e.index.1 == old_focused_entry.index.1 && e.index.2 == old_focused_entry.index.2)) { || (e.index.1 == old_focused_entry.index.1
&& e.index.2 == old_focused_entry.index.2)
}) {
self.cursor_pos = new_entry_idx; self.cursor_pos = new_entry_idx;
} }
} }
if let Some(old_expanded_entry) = old_expanded_entry { if let Some(old_expanded_entry) = old_expanded_entry {
if let Some(new_entry_idx) = self.entries.iter().position( if let Some(new_entry_idx) = self.entries.iter().position(|e| {
|e| e.msg_idx == old_expanded_entry.msg_idx || e.msg_idx == old_expanded_entry.msg_idx
(e.index.1 == old_expanded_entry.index.1 && e.index.2 == old_expanded_entry.index.2)) { || (e.index.1 == old_expanded_entry.index.1
&& e.index.2 == old_expanded_entry.index.2)
}) {
self.expanded_pos = new_entry_idx; self.expanded_pos = new_entry_idx;
} }
} }
self.set_dirty(); self.set_dirty();
} }
fn initiate(&mut self, expanded_idx: Option<usize>, context: &Context) { fn initiate(&mut self, expanded_idx: Option<usize>, context: &Context) {
/* stack to push thread messages in order in order to pop and print them later */ /* stack to push thread messages in order in order to pop and print them later */
@ -183,12 +188,14 @@ impl ThreadView {
if content[index].ch() == ' ' { if content[index].ch() == ' ' {
let mut ctr = 1; let mut ctr = 1;
while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() { while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() {
if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' { break; } if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' {
break;
}
set_and_join_box( set_and_join_box(
&mut content, &mut content,
(e.index.0 * 4 + ctr, 2 * y - 1), (e.index.0 * 4 + ctr, 2 * y - 1),
HORZ_BOUNDARY, HORZ_BOUNDARY,
); );
ctr += 1; ctr += 1;
} }
set_and_join_box(&mut content, index, HORZ_BOUNDARY); set_and_join_box(&mut content, index, HORZ_BOUNDARY);
@ -197,11 +204,19 @@ impl ThreadView {
write_string_to_grid( write_string_to_grid(
&strings[y], &strings[y],
&mut content, &mut content,
if e.seen { Color::Default } else { Color::Byte(0) }, if e.seen {
if e.seen { Color::Default } else { Color::Byte(251) }, Color::Default
} else {
Color::Byte(0)
},
if e.seen {
Color::Default
} else {
Color::Byte(251)
},
((e.index.0 * 4 + 1, 2 * y), (width - 1, height - 1)), ((e.index.0 * 4 + 1, 2 * y), (width - 1, height - 1)),
true, true,
); );
if let Some(len) = highlight_reply_subjects[y] { if let Some(len) = highlight_reply_subjects[y] {
let index = e.index.0 * 4 + 1 + strings[y].len() - len; let index = e.index.0 * 4 + 1 + strings[y].len() - len;
let area = ((index, 2 * y), (width - 2, 2 * y)); let area = ((index, 2 * y), (width - 2, 2 * y));
@ -225,12 +240,14 @@ impl ThreadView {
if content[index].ch() == ' ' { if content[index].ch() == ' ' {
let mut ctr = 1; let mut ctr = 1;
while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() { while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() {
if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' { break; } if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' {
break;
}
set_and_join_box( set_and_join_box(
&mut content, &mut content,
(e.index.0 * 4 + ctr, 2 * y - 1), (e.index.0 * 4 + ctr, 2 * y - 1),
HORZ_BOUNDARY, HORZ_BOUNDARY,
); );
ctr += 1; ctr += 1;
} }
set_and_join_box(&mut content, index, HORZ_BOUNDARY); set_and_join_box(&mut content, index, HORZ_BOUNDARY);
@ -239,11 +256,19 @@ impl ThreadView {
write_string_to_grid( write_string_to_grid(
&strings[y], &strings[y],
&mut content, &mut content,
if e.seen { Color::Default } else { Color::Byte(0) }, if e.seen {
if e.seen { Color::Default } else { Color::Byte(251) }, Color::Default
} else {
Color::Byte(0)
},
if e.seen {
Color::Default
} else {
Color::Byte(251)
},
((e.index.0 * 4 + 1, 2 * y), (width - 1, height - 1)), ((e.index.0 * 4 + 1, 2 * y), (width - 1, height - 1)),
true, true,
); );
if let Some(len) = highlight_reply_subjects[y] { if let Some(len) = highlight_reply_subjects[y] {
let index = e.index.0 * 4 + 1 + strings[y].len() - len; let index = e.index.0 * 4 + 1 + strings[y].len() - len;
let area = ((index, 2 * y), (width - 2, 2 * y)); let area = ((index, 2 * y), (width - 2, 2 * y));
@ -267,7 +292,12 @@ impl ThreadView {
self.content = content; self.content = content;
} }
fn make_entry(&mut self, i: (usize, usize, usize), msg_idx: EnvelopeHash, seen: bool) -> ThreadEntry { fn make_entry(
&mut self,
i: (usize, usize, usize),
msg_idx: EnvelopeHash,
seen: bool,
) -> ThreadEntry {
let (ind, _, _) = i; let (ind, _, _) = i;
ThreadEntry { ThreadEntry {
index: i, index: i,
@ -466,7 +496,6 @@ impl ThreadView {
for x in get_x(upper_left)..=get_x(bottom_right) { for x in get_x(upper_left)..=get_x(bottom_right) {
set_and_join_box(grid, (x, y - 1), HORZ_BOUNDARY); set_and_join_box(grid, (x, y - 1), HORZ_BOUNDARY);
} }
} }
fn draw_horz(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { fn draw_horz(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
let upper_left = upper_left!(area); let upper_left = upper_left!(area);
@ -577,7 +606,6 @@ impl ThreadView {
self.initiated = true; self.initiated = true;
} }
if self.show_mailview { if self.show_mailview {
self.draw_list( self.draw_list(
grid, grid,

View File

@ -200,7 +200,13 @@ impl Component for VSplit {
} else { } else {
self.left.component.draw( self.left.component.draw(
grid, grid,
(upper_left, (if self.show_divider { mid - 1 } else { mid }, get_y(bottom_right))), (
upper_left,
(
if self.show_divider { mid - 1 } else { mid },
get_y(bottom_right),
),
),
context, context,
); );
self.right self.right

View File

@ -23,13 +23,13 @@
* Account management from user configuration. * Account management from user configuration.
*/ */
use melib::async_workers::{Async, AsyncStatus, AsyncBuilder};
use super::AccountConf; use super::AccountConf;
use melib::async_workers::{Async, AsyncBuilder, AsyncStatus};
use melib::error::Result;
use melib::mailbox::backends::{ use melib::mailbox::backends::{
Backends, Folder, MailBackend, NotifyFn, RefreshEvent, RefreshEventConsumer, RefreshEventKind, Backends, Folder, MailBackend, NotifyFn, RefreshEvent, RefreshEventConsumer, RefreshEventKind,
}; };
use melib::mailbox::*; use melib::mailbox::*;
use melib::error::Result;
use melib::AddressBook; use melib::AddressBook;
use std::fs; use std::fs;
@ -38,7 +38,7 @@ use std::mem;
use std::ops::{Index, IndexMut}; use std::ops::{Index, IndexMut};
use std::result; use std::result;
use std::sync::Arc; use std::sync::Arc;
use types::UIEventType::{self, Notification, EnvelopeUpdate, EnvelopeRename, EnvelopeRemove}; use types::UIEventType::{self, EnvelopeRemove, EnvelopeRename, EnvelopeUpdate, Notification};
pub type Worker = Option<Async<Result<Mailbox>>>; pub type Worker = Option<Async<Result<Mailbox>>>;

View File

@ -282,7 +282,9 @@ impl State {
.send(ThreadEvent::UIEvent(UIEventType::StartupCheck(hash))); .send(ThreadEvent::UIEvent(UIEventType::StartupCheck(hash)));
self.context self.context
.sender .sender
.send(ThreadEvent::UIEvent(UIEventType::MailboxUpdate((idxa, idxm)))); .send(ThreadEvent::UIEvent(UIEventType::MailboxUpdate((
idxa, idxm,
))));
self.context.replies.push_back(UIEvent { self.context.replies.push_back(UIEvent {
id: 0, id: 0,
event_type: notification, event_type: notification,

View File

@ -26,9 +26,9 @@ pub use self::helpers::*;
use super::execute::Action; use super::execute::Action;
use super::terminal::*; use super::terminal::*;
use melib::RefreshEvent;
use melib::EnvelopeHash;
use melib::backends::FolderHash; use melib::backends::FolderHash;
use melib::EnvelopeHash;
use melib::RefreshEvent;
use std; use std;
use std::fmt; use std::fmt;
use std::thread; use std::thread;