meli: add debug_logs feature
Conditional print of debug logs in stderr. Previously they were always printedembed
parent
d50c201776
commit
4629e6a22f
|
@ -21,3 +21,7 @@ lto = true
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["melib", "ui"]
|
members = ["melib", "ui"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
debug_log = []
|
||||||
|
|
|
@ -28,8 +28,8 @@ use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::string;
|
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::string;
|
||||||
|
|
||||||
use nom;
|
use nom;
|
||||||
|
|
||||||
|
|
|
@ -120,12 +120,14 @@ impl Mailbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_reply(&mut self, envelope: &Envelope) {
|
pub fn insert_reply(&mut self, envelope: &Envelope) {
|
||||||
eprintln!("mailbox insert reply {}", self.name);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("mailbox insert reply {}", self.name);
|
||||||
|
}
|
||||||
self.collection.insert_reply(envelope);
|
self.collection.insert_reply(envelope);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, envelope_hash: EnvelopeHash) {
|
pub fn remove(&mut self, envelope_hash: EnvelopeHash) {
|
||||||
self.collection.remove(envelope_hash);
|
self.collection.remove(envelope_hash);
|
||||||
// eprintln!("envelope_hash: {}\ncollection:\n{:?}", envelope_hash, self.collection);
|
// if cfg!(feature = "debug_log") { eprintln!("envelope_hash: {}\ncollection:\n{:?}", envelope_hash, self.collection); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,11 +67,17 @@ impl MaildirOp {
|
||||||
fn path(&self) -> PathBuf {
|
fn path(&self) -> PathBuf {
|
||||||
let map = self.hash_index.lock().unwrap();
|
let map = self.hash_index.lock().unwrap();
|
||||||
let map = &map[&self.folder_hash];
|
let map = &map[&self.folder_hash];
|
||||||
eprintln!("looking for {} in {} map", self.hash, self.folder_hash);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("looking for {} in {} map", self.hash, self.folder_hash);
|
||||||
|
}
|
||||||
if !map.contains_key(&self.hash) {
|
if !map.contains_key(&self.hash) {
|
||||||
eprintln!("doesn't contain it though len = {}\n{:#?}", map.len(), map);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("doesn't contain it though len = {}\n{:#?}", map.len(), map);
|
||||||
|
}
|
||||||
for e in map.iter() {
|
for e in map.iter() {
|
||||||
eprintln!("{:#?}", e);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:#?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
map.get(&self.hash).unwrap().clone()
|
map.get(&self.hash).unwrap().clone()
|
||||||
|
|
|
@ -142,7 +142,9 @@ fn move_to_cur(p: PathBuf) -> PathBuf {
|
||||||
new.push(file_name);
|
new.push(file_name);
|
||||||
new.set_extension(":2,");
|
new.set_extension(":2,");
|
||||||
}
|
}
|
||||||
eprintln!("moved to cur: {}", new.display());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("moved to cur: {}", new.display());
|
||||||
|
}
|
||||||
fs::rename(p, &new).unwrap();
|
fs::rename(p, &new).unwrap();
|
||||||
new
|
new
|
||||||
}
|
}
|
||||||
|
@ -163,7 +165,9 @@ impl MailBackend for MaildirType {
|
||||||
if f.is_valid().is_err() {
|
if f.is_valid().is_err() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
eprintln!("watching {:?}", f);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("watching {:?}", f);
|
||||||
|
}
|
||||||
let mut p = PathBuf::from(&f.path);
|
let mut p = PathBuf::from(&f.path);
|
||||||
p.push("cur");
|
p.push("cur");
|
||||||
watcher.watch(&p, RecursiveMode::NonRecursive).unwrap();
|
watcher.watch(&p, RecursiveMode::NonRecursive).unwrap();
|
||||||
|
@ -208,7 +212,9 @@ impl MailBackend for MaildirType {
|
||||||
&cache_dir,
|
&cache_dir,
|
||||||
file_name,
|
file_name,
|
||||||
) {
|
) {
|
||||||
eprintln!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display());
|
||||||
|
}
|
||||||
sender.send(RefreshEvent {
|
sender.send(RefreshEvent {
|
||||||
hash: folder_hash,
|
hash: folder_hash,
|
||||||
kind: Create(Box::new(env)),
|
kind: Create(Box::new(env)),
|
||||||
|
@ -257,7 +263,9 @@ impl MailBackend for MaildirType {
|
||||||
if index_lock.get_mut(&new_hash).is_none() {
|
if index_lock.get_mut(&new_hash).is_none() {
|
||||||
let op = Box::new(MaildirOp::new(new_hash, hash_indexes.clone(), folder_hash));
|
let op = Box::new(MaildirOp::new(new_hash, hash_indexes.clone(), folder_hash));
|
||||||
if let Some(env) = Envelope::from_token(op, new_hash) {
|
if let Some(env) = Envelope::from_token(op, new_hash) {
|
||||||
eprintln!("{}\t{}", new_hash, pathbuf.display());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{}\t{}", new_hash, pathbuf.display());
|
||||||
|
}
|
||||||
index_lock.insert(new_hash, pathbuf);
|
index_lock.insert(new_hash, pathbuf);
|
||||||
|
|
||||||
/* Send Write notice */
|
/* Send Write notice */
|
||||||
|
@ -267,7 +275,9 @@ impl MailBackend for MaildirType {
|
||||||
kind: Update(old_hash, Box::new(env)),
|
kind: Update(old_hash, Box::new(env)),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,7 +349,9 @@ impl MailBackend for MaildirType {
|
||||||
let mut path = f.path.clone();
|
let mut path = f.path.clone();
|
||||||
path.push("cur");
|
path.push("cur");
|
||||||
path.push("draft:2,");
|
path.push("draft:2,");
|
||||||
eprintln!("saving at {}", path.display());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("saving at {}", path.display());
|
||||||
|
}
|
||||||
let file = fs::File::create(path)?;
|
let file = fs::File::create(path)?;
|
||||||
let mut writer = io::BufWriter::new(file);
|
let mut writer = io::BufWriter::new(file);
|
||||||
writer.write_all(&message.into_bytes())?;
|
writer.write_all(&message.into_bytes())?;
|
||||||
|
@ -545,7 +557,9 @@ impl MaildirType {
|
||||||
}
|
}
|
||||||
local_r.push(e);
|
local_r.push(e);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, file.as_path().display());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, file.as_path().display());
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -592,12 +606,16 @@ fn add_path_to_index(
|
||||||
map.len()
|
map.len()
|
||||||
);
|
);
|
||||||
for e in map.iter() {
|
for e in map.iter() {
|
||||||
eprintln!("{:#?}", e);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:#?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let op = Box::new(MaildirOp::new(hash, hash_index.clone(), folder_hash));
|
let op = Box::new(MaildirOp::new(hash, hash_index.clone(), folder_hash));
|
||||||
if let Some(e) = Envelope::from_token(op, hash) {
|
if let Some(e) = Envelope::from_token(op, hash) {
|
||||||
eprintln!("add_path_to_index gen {}\t{}", hash, file_name.display());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("add_path_to_index gen {}\t{}", hash, file_name.display());
|
||||||
|
}
|
||||||
if let Ok(cached) = cache_dir.place_cache_file(file_name) {
|
if let Ok(cached) = cache_dir.place_cache_file(file_name) {
|
||||||
/* place result in cache directory */
|
/* place result in cache directory */
|
||||||
let f = match fs::File::create(cached) {
|
let f = match fs::File::create(cached) {
|
||||||
|
|
|
@ -56,24 +56,26 @@ impl Collection {
|
||||||
let threads = Threads::new(&mut envelopes);
|
let threads = Threads::new(&mut envelopes);
|
||||||
|
|
||||||
/*let cache_dir =
|
/*let cache_dir =
|
||||||
xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash()))
|
xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if let Some(cached) = cache_dir.find_cache_file("threads") {
|
if let Some(cached) = cache_dir.find_cache_file("threads") {
|
||||||
let reader = io::BufReader::new(fs::File::open(cached).unwrap());
|
let reader = io::BufReader::new(fs::File::open(cached).unwrap());
|
||||||
let result: result::Result<Threads, _> = bincode::deserialize_from(reader);
|
let result: result::Result<Threads, _> = bincode::deserialize_from(reader);
|
||||||
let ret = if let Ok(mut cached_t) = result {
|
let ret = if let Ok(mut cached_t) = result {
|
||||||
use std::iter::FromIterator;
|
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);
|
if cfg!(feature = "debug_log") {
|
||||||
cached_t.amend(&mut envelopes);
|
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
|
}
|
||||||
} else {
|
cached_t.amend(&mut envelopes);
|
||||||
Threads::new(&mut envelopes)
|
cached_t
|
||||||
};
|
} else {
|
||||||
ret
|
Threads::new(&mut envelopes)
|
||||||
} else {
|
};
|
||||||
Threads::new(&mut envelopes)
|
ret
|
||||||
};
|
} else {
|
||||||
*/
|
Threads::new(&mut envelopes)
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
Collection {
|
Collection {
|
||||||
folder: folder.clone(),
|
folder: folder.clone(),
|
||||||
|
@ -93,7 +95,9 @@ impl Collection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, envelope_hash: EnvelopeHash) {
|
pub fn remove(&mut self, envelope_hash: EnvelopeHash) {
|
||||||
eprintln!("DEBUG: Removing {}", envelope_hash);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("DEBUG: Removing {}", envelope_hash);
|
||||||
|
}
|
||||||
self.envelopes.remove(&envelope_hash);
|
self.envelopes.remove(&envelope_hash);
|
||||||
self.threads.remove(envelope_hash, &mut self.envelopes);
|
self.threads.remove(envelope_hash, &mut self.envelopes);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +136,9 @@ impl Collection {
|
||||||
|
|
||||||
pub fn insert(&mut self, envelope: Envelope) {
|
pub fn insert(&mut self, envelope: Envelope) {
|
||||||
let hash = envelope.hash();
|
let hash = envelope.hash();
|
||||||
eprintln!("DEBUG: Inserting hash {} in {}", hash, self.folder.name());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("DEBUG: Inserting hash {} in {}", hash, self.folder.name());
|
||||||
|
}
|
||||||
self.envelopes.insert(hash, envelope);
|
self.envelopes.insert(hash, envelope);
|
||||||
let env = self.envelopes.entry(hash).or_default() as *mut Envelope;
|
let env = self.envelopes.entry(hash).or_default() as *mut Envelope;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -142,10 +148,12 @@ impl Collection {
|
||||||
pub(crate) fn insert_reply(&mut self, _envelope: &Envelope) {
|
pub(crate) fn insert_reply(&mut self, _envelope: &Envelope) {
|
||||||
return;
|
return;
|
||||||
/*
|
/*
|
||||||
//self.insert(envelope);
|
//self.insert(envelope);
|
||||||
|
if cfg!(feature = "debug_log") {
|
||||||
eprintln!("insert_reply in collections");
|
eprintln!("insert_reply in collections");
|
||||||
self.threads.insert_reply(envelope, &mut self.envelopes);
|
}
|
||||||
*/
|
self.threads.insert_reply(envelope, &mut self.envelopes);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,9 @@ impl Envelope {
|
||||||
let (headers, _) = match parser::mail(bytes).to_full_result() {
|
let (headers, _) = match parser::mail(bytes).to_full_result() {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("error in parsing mail\n{:?}\n", e);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("error in parsing mail\n{:?}\n", e);
|
||||||
|
}
|
||||||
let error_msg = String::from("Mail cannot be shown because of errors.");
|
let error_msg = String::from("Mail cannot be shown because of errors.");
|
||||||
return Err(MeliError::new(error_msg));
|
return Err(MeliError::new(error_msg));
|
||||||
}
|
}
|
||||||
|
@ -538,7 +540,9 @@ impl Envelope {
|
||||||
let (headers, body) = match parser::mail(bytes).to_full_result() {
|
let (headers, body) = match parser::mail(bytes).to_full_result() {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
eprintln!("error in parsing mail\n");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("error in parsing mail\n");
|
||||||
|
}
|
||||||
let error_msg = b"Mail cannot be shown because of errors.";
|
let error_msg = b"Mail cannot be shown because of errors.";
|
||||||
let mut builder = AttachmentBuilder::new(error_msg);
|
let mut builder = AttachmentBuilder::new(error_msg);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
@ -560,34 +564,42 @@ impl Envelope {
|
||||||
pub fn headers<'a>(&self, bytes: &'a [u8]) -> Result<Vec<(&'a str, &'a str)>> {
|
pub fn headers<'a>(&self, bytes: &'a [u8]) -> Result<Vec<(&'a str, &'a str)>> {
|
||||||
let ret = parser::headers(bytes).to_full_result()?;
|
let ret = parser::headers(bytes).to_full_result()?;
|
||||||
let len = ret.len();
|
let len = ret.len();
|
||||||
ret.into_iter().try_fold(Vec::with_capacity(len), |mut acc, (a, b)| Ok({acc.push((std::str::from_utf8(a)?, std::str::from_utf8(b)?)); acc }))
|
ret.into_iter()
|
||||||
|
.try_fold(Vec::with_capacity(len), |mut acc, (a, b)| {
|
||||||
|
Ok({
|
||||||
|
acc.push((std::str::from_utf8(a)?, std::str::from_utf8(b)?));
|
||||||
|
acc
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pub fn body(&self, mut operation: Box<BackendOp>) -> Attachment {
|
pub fn body(&self, mut operation: Box<BackendOp>) -> Attachment {
|
||||||
let file = operation.as_bytes();
|
let file = operation.as_bytes();
|
||||||
self.body_bytes(file.unwrap())
|
self.body_bytes(file.unwrap())
|
||||||
/*
|
/*
|
||||||
let (headers, body) = match parser::mail(file.unwrap()).to_full_result() {
|
let (headers, body) = match parser::mail(file.unwrap()).to_full_result() {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
eprintln!("2error in parsing mail\n");
|
if cfg!(feature = "debug_log") {
|
||||||
let error_msg = b"Mail cannot be shown because of errors.";
|
eprintln!("2error in parsing mail\n");
|
||||||
let mut builder = AttachmentBuilder::new(error_msg);
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let mut builder = AttachmentBuilder::new(body);
|
|
||||||
for (name, value) in headers {
|
|
||||||
if value.len() == 1 && value.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if name.eq_ignore_ascii_case(b"content-transfer-encoding") {
|
|
||||||
builder.content_transfer_encoding(value);
|
|
||||||
} else if name.eq_ignore_ascii_case(b"content-type") {
|
|
||||||
builder.content_type(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
builder.build()
|
let error_msg = b"Mail cannot be shown because of errors.";
|
||||||
*/
|
let mut builder = AttachmentBuilder::new(error_msg);
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut builder = AttachmentBuilder::new(body);
|
||||||
|
for (name, value) in headers {
|
||||||
|
if value.len() == 1 && value.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if name.eq_ignore_ascii_case(b"content-transfer-encoding") {
|
||||||
|
builder.content_transfer_encoding(value);
|
||||||
|
} else if name.eq_ignore_ascii_case(b"content-type") {
|
||||||
|
builder.content_type(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.build()
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
pub fn subject(&self) -> Cow<str> {
|
pub fn subject(&self) -> Cow<str> {
|
||||||
match self.subject {
|
match self.subject {
|
||||||
|
|
|
@ -68,7 +68,9 @@ impl<'a> From<&'a [u8]> for Charset {
|
||||||
b"BIG5" | b"big5" => Charset::BIG5,
|
b"BIG5" | b"big5" => Charset::BIG5,
|
||||||
b"ISO-2022-JP" | b"iso-2022-JP" => Charset::ISO2022JP,
|
b"ISO-2022-JP" | b"iso-2022-JP" => Charset::ISO2022JP,
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("unknown tag is {:?}", str::from_utf8(b));
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("unknown tag is {:?}", str::from_utf8(b));
|
||||||
|
}
|
||||||
Charset::Ascii
|
Charset::Ascii
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,9 @@ impl AttachmentBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(v) => {
|
Err(v) => {
|
||||||
eprintln!("parsing error in content_type: {:?} {:?}", value, v);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("parsing error in content_type: {:?} {:?}", value, v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
|
@ -209,10 +211,18 @@ impl AttachmentBuilder {
|
||||||
let (headers, body) = match parser::attachment(&a).to_full_result() {
|
let (headers, body) = match parser::attachment(&a).to_full_result() {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
eprintln!("error in parsing attachment");
|
if cfg!(feature = "debug_log") {
|
||||||
eprintln!("\n-------------------------------");
|
eprintln!("error in parsing attachment");
|
||||||
eprintln!("{}\n", ::std::string::String::from_utf8_lossy(a));
|
}
|
||||||
eprintln!("-------------------------------\n");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("\n-------------------------------");
|
||||||
|
}
|
||||||
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{}\n", ::std::string::String::from_utf8_lossy(a));
|
||||||
|
}
|
||||||
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("-------------------------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -384,18 +394,22 @@ fn decode_rfc822(_raw: &[u8]) -> Attachment {
|
||||||
builder.build()
|
builder.build()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
if cfg!(feature = "debug_log") {
|
||||||
eprintln!("raw is\n{:?}", str::from_utf8(raw).unwrap());
|
eprintln!("raw is\n{:?}", str::from_utf8(raw).unwrap());
|
||||||
let e = match Envelope::from_bytes(raw) {
|
}
|
||||||
Some(e) => e,
|
let e = match Envelope::from_bytes(raw) {
|
||||||
None => {
|
Some(e) => e,
|
||||||
eprintln!("error in parsing mail");
|
None => {
|
||||||
let error_msg = b"Mail cannot be shown because of errors.";
|
if cfg!(feature = "debug_log") {
|
||||||
let mut builder = AttachmentBuilder::new(error_msg);
|
eprintln!("error in parsing mail");
|
||||||
return builder.build();
|
}
|
||||||
}
|
let error_msg = b"Mail cannot be shown because of errors.";
|
||||||
};
|
let mut builder = AttachmentBuilder::new(error_msg);
|
||||||
e.body(None)
|
return builder.build();
|
||||||
*/
|
}
|
||||||
|
};
|
||||||
|
e.body(None)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
type Filter = Box<Fn(&Attachment, &mut Vec<u8>) -> ()>;
|
type Filter = Box<Fn(&Attachment, &mut Vec<u8>) -> ()>;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use mailbox::backends::BackendOp;
|
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use data_encoding::BASE64_MIME;
|
use data_encoding::BASE64_MIME;
|
||||||
|
use mailbox::backends::BackendOp;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
mod mime;
|
mod mime;
|
||||||
|
@ -95,18 +95,16 @@ impl str::FromStr for Draft {
|
||||||
|
|
||||||
impl Draft {
|
impl Draft {
|
||||||
pub fn edit(envelope: &Envelope, mut op: Box<BackendOp>) -> Self {
|
pub fn edit(envelope: &Envelope, mut op: Box<BackendOp>) -> Self {
|
||||||
|
|
||||||
let mut ret = Draft::default();
|
let mut ret = Draft::default();
|
||||||
//TODO: Inform user if error
|
//TODO: Inform user if error
|
||||||
{
|
{
|
||||||
let bytes = op.as_bytes().unwrap_or(&[]);
|
let bytes = op.as_bytes().unwrap_or(&[]);
|
||||||
for (h, v) in envelope.headers(bytes).unwrap_or_else(|_| Vec::new()) {
|
for (h, v) in envelope.headers(bytes).unwrap_or_else(|_| Vec::new()) {
|
||||||
ret.header_order.push(h.into());
|
ret.header_order.push(h.into());
|
||||||
ret.headers_mut()
|
ret.headers_mut().insert(h.into(), v.into());
|
||||||
.insert(h.into(), v.into());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.body = envelope.body(op).text();
|
ret.body = envelope.body(op).text();
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -766,8 +766,12 @@ mod tests {
|
||||||
let s = b"Thu, 31 Aug 2017 13:43:37 +0000 (UTC)";
|
let s = b"Thu, 31 Aug 2017 13:43:37 +0000 (UTC)";
|
||||||
let _s = b"Thu, 31 Aug 2017 13:43:37 +0000";
|
let _s = b"Thu, 31 Aug 2017 13:43:37 +0000";
|
||||||
let __s = b"=?utf-8?q?Thu=2C_31_Aug_2017_13=3A43=3A37_-0000?=";
|
let __s = b"=?utf-8?q?Thu=2C_31_Aug_2017_13=3A43=3A37_-0000?=";
|
||||||
eprintln!("{:?}, {:?}", date(s), date(_s));
|
if cfg!(feature = "debug_log") {
|
||||||
eprintln!("{:?}", date(__s));
|
eprintln!("{:?}, {:?}", date(s), date(_s));
|
||||||
|
}
|
||||||
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:?}", date(__s));
|
||||||
|
}
|
||||||
assert_eq!(date(s).unwrap(), date(_s).unwrap());
|
assert_eq!(date(s).unwrap(), date(_s).unwrap());
|
||||||
assert_eq!(date(_s).unwrap(), date(__s).unwrap());
|
assert_eq!(date(_s).unwrap(), date(__s).unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -578,23 +578,39 @@ impl Threads {
|
||||||
t.create_root_set(collection);
|
t.create_root_set(collection);
|
||||||
t.build_collection(collection);
|
t.build_collection(collection);
|
||||||
for (i, _t) in t.thread_nodes.iter().enumerate() {
|
for (i, _t) in t.thread_nodes.iter().enumerate() {
|
||||||
eprintln!("Thread #{}, children {}", i, _t.children.len());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("Thread #{}, children {}", i, _t.children.len());
|
||||||
|
}
|
||||||
if !_t.children.is_empty() {
|
if !_t.children.is_empty() {
|
||||||
eprintln!("{:?}", _t.children);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:?}", _t.children);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(m) = _t.message {
|
if let Some(m) = _t.message {
|
||||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\tNo message");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("\tNo message");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eprintln!("\n");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("\n");
|
||||||
|
}
|
||||||
for (i, _t) in t.tree.borrow().iter().enumerate() {
|
for (i, _t) in t.tree.borrow().iter().enumerate() {
|
||||||
eprintln!("Tree #{} id {}, children {}", i, _t.id, _t.children.len());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("Tree #{} id {}, children {}", i, _t.id, _t.children.len());
|
||||||
|
}
|
||||||
if let Some(m) = t.thread_nodes[_t.id].message {
|
if let Some(m) = t.thread_nodes[_t.id].message {
|
||||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("\tNo message");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("\tNo message");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t
|
t
|
||||||
|
@ -834,7 +850,9 @@ impl Threads {
|
||||||
// .iter()
|
// .iter()
|
||||||
// .position(|n| n.message.map(|n| n == envelope_hash).unwrap_or(false))
|
// .position(|n| n.message.map(|n| n == envelope_hash).unwrap_or(false))
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
// eprintln!("DEBUG: {} in threads is idx= {}", envelope_hash, pos);
|
// if cfg!(feature = "debug_log") {
|
||||||
|
// eprintln!("DEBUG: {} in threads is idx= {}", envelope_hash, pos);
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
let t_id: usize;
|
let t_id: usize;
|
||||||
|
@ -893,7 +911,9 @@ impl Threads {
|
||||||
let difference: Vec<EnvelopeHash> =
|
let difference: Vec<EnvelopeHash> =
|
||||||
new_hash_set.difference(&self.hash_set).cloned().collect();
|
new_hash_set.difference(&self.hash_set).cloned().collect();
|
||||||
for h in difference {
|
for h in difference {
|
||||||
eprintln!("inserting {}", collection[&h].subject());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("inserting {}", collection[&h].subject());
|
||||||
|
}
|
||||||
let env = collection.entry(h).or_default() as *mut Envelope;
|
let env = collection.entry(h).or_default() as *mut Envelope;
|
||||||
unsafe {
|
unsafe {
|
||||||
// `collection` is borrowed immutably and `insert` only changes the envelope's
|
// `collection` is borrowed immutably and `insert` only changes the envelope's
|
||||||
|
|
|
@ -94,7 +94,9 @@ impl AccountMenu {
|
||||||
context: &mut Context,
|
context: &mut Context,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
if !is_valid_area!(area) {
|
if !is_valid_area!(area) {
|
||||||
eprintln!("BUG: invalid area in print_account");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("BUG: invalid area in print_account");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let upper_left = upper_left!(area);
|
let upper_left = upper_left!(area);
|
||||||
let bottom_right = bottom_right!(area);
|
let bottom_right = bottom_right!(area);
|
||||||
|
@ -290,6 +292,9 @@ impl Component for AccountMenu {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
fn get_shortcuts(&self, _context: &Context) -> ShortcutMap {
|
fn get_shortcuts(&self, _context: &Context) -> ShortcutMap {
|
||||||
[("Toggle account menu visibility", Key::Char('\t'))].iter().cloned().collect()
|
[("Toggle account menu visibility", Key::Char('\t'))]
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,7 +269,7 @@ impl Component for Composer {
|
||||||
let mid = if width > 80 {
|
let mid = if width > 80 {
|
||||||
let width = width - 80;
|
let width = width - 80;
|
||||||
let mid = if self.reply_context.is_some() {
|
let mid = if self.reply_context.is_some() {
|
||||||
get_x(upper_left) + width!(area) / 2
|
get_x(upper_left) + width!(area) / 2
|
||||||
} else {
|
} else {
|
||||||
width / 2
|
width / 2
|
||||||
};
|
};
|
||||||
|
@ -305,28 +305,56 @@ impl Component for Composer {
|
||||||
}
|
}
|
||||||
|
|
||||||
let header_area = if self.reply_context.is_some() {
|
let header_area = if self.reply_context.is_some() {
|
||||||
(set_x(upper_left, mid + 1), set_y(bottom_right, get_y(upper_left) + header_height + 1))
|
(
|
||||||
} else {
|
set_x(upper_left, mid + 1),
|
||||||
(set_x(upper_left, mid + 1), (get_x(bottom_right).saturating_sub(mid), get_y(upper_left) + header_height + 1),)
|
set_y(bottom_right, get_y(upper_left) + header_height + 1),
|
||||||
};
|
)
|
||||||
let body_area = if self.reply_context.is_some() {
|
|
||||||
((mid + 1, get_y(upper_left) + header_height + 1), bottom_right)
|
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
pos_inc(upper_left, (mid + 1, header_height + 2)),
|
set_x(upper_left, mid + 1),
|
||||||
pos_dec(bottom_right, (mid, 0)),
|
(
|
||||||
)
|
get_x(bottom_right).saturating_sub(mid),
|
||||||
|
get_y(upper_left) + header_height + 1,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
let body_area = if self.reply_context.is_some() {
|
||||||
|
(
|
||||||
|
(mid + 1, get_y(upper_left) + header_height + 1),
|
||||||
|
bottom_right,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
pos_inc(upper_left, (mid + 1, header_height + 2)),
|
||||||
|
pos_dec(bottom_right, (mid, 0)),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (x, y) = write_string_to_grid(
|
let (x, y) = write_string_to_grid(
|
||||||
if self.reply_context.is_some() { "COMPOSING REPLY" } else { "COMPOSING MESSAGE" },
|
if self.reply_context.is_some() {
|
||||||
grid,
|
"COMPOSING REPLY"
|
||||||
Color::Byte(189),
|
} else {
|
||||||
Color::Byte(167),
|
"COMPOSING MESSAGE"
|
||||||
(pos_dec(upper_left!(header_area), (0, 1)), bottom_right!(header_area)),
|
},
|
||||||
false);
|
grid,
|
||||||
change_colors(grid, (set_x(pos_dec(upper_left!(header_area), (0, 1)), x), set_y(bottom_right!(header_area), y)), Color::Byte(189), Color::Byte(167));
|
Color::Byte(189),
|
||||||
|
Color::Byte(167),
|
||||||
|
(
|
||||||
|
pos_dec(upper_left!(header_area), (0, 1)),
|
||||||
|
bottom_right!(header_area),
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
change_colors(
|
||||||
|
grid,
|
||||||
|
(
|
||||||
|
set_x(pos_dec(upper_left!(header_area), (0, 1)), x),
|
||||||
|
set_y(bottom_right!(header_area), y),
|
||||||
|
),
|
||||||
|
Color::Byte(189),
|
||||||
|
Color::Byte(167),
|
||||||
|
);
|
||||||
|
|
||||||
/* Regardless of view mode, do the following */
|
/* Regardless of view mode, do the following */
|
||||||
self.form.draw(grid, header_area, context);
|
self.form.draw(grid, header_area, context);
|
||||||
|
|
||||||
|
@ -459,9 +487,13 @@ impl Component for Composer {
|
||||||
('y', ViewMode::Discard(u)) => {
|
('y', ViewMode::Discard(u)) => {
|
||||||
let account = &context.accounts[self.account_cursor];
|
let account = &context.accounts[self.account_cursor];
|
||||||
let draft = std::mem::replace(&mut self.draft, Draft::default());
|
let draft = std::mem::replace(&mut self.draft, Draft::default());
|
||||||
eprintln!("{:?}", account.save_draft(draft));
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:?}", account.save_draft(draft));
|
||||||
|
}
|
||||||
|
|
||||||
|
//if cfg!(feature = "debug_log") {
|
||||||
//eprintln!("{:?}", self.draft.to_string());
|
//eprintln!("{:?}", self.draft.to_string());
|
||||||
|
//}
|
||||||
context.replies.push_back(UIEvent {
|
context.replies.push_back(UIEvent {
|
||||||
id: 0,
|
id: 0,
|
||||||
event_type: UIEventType::Action(Tab(Kill(*u))),
|
event_type: UIEventType::Action(Tab(Kill(*u))),
|
||||||
|
|
|
@ -165,13 +165,17 @@ impl CompactListing {
|
||||||
threads.thread_nodes()[iter_ptr].message().unwrap()
|
threads.thread_nodes()[iter_ptr].message().unwrap()
|
||||||
};
|
};
|
||||||
if !mailbox.collection.contains_key(&i) {
|
if !mailbox.collection.contains_key(&i) {
|
||||||
eprintln!("key = {}", i);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("key = {}", i);
|
||||||
|
}
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"name = {} {}",
|
"name = {} {}",
|
||||||
mailbox.name(),
|
mailbox.name(),
|
||||||
context.accounts[self.cursor_pos.0].name()
|
context.accounts[self.cursor_pos.0].name()
|
||||||
);
|
);
|
||||||
eprintln!("{:#?}", context.accounts);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:#?}", context.accounts);
|
||||||
|
}
|
||||||
|
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
|
@ -494,13 +498,17 @@ impl Component for CompactListing {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::SubSort(field, order) => {
|
Action::SubSort(field, order) => {
|
||||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||||
|
}
|
||||||
self.subsort = (*field, *order);
|
self.subsort = (*field, *order);
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::Sort(field, order) => {
|
Action::Sort(field, order) => {
|
||||||
eprintln!("Sort {:?} , {:?}", field, order);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("Sort {:?} , {:?}", field, order);
|
||||||
|
}
|
||||||
self.sort = (*field, *order);
|
self.sort = (*field, *order);
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -532,14 +532,18 @@ impl Component for PlainListing {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::SubSort(field, order) => {
|
Action::SubSort(field, order) => {
|
||||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||||
|
}
|
||||||
self.subsort = (*field, *order);
|
self.subsort = (*field, *order);
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::Sort(field, order) => {
|
Action::Sort(field, order) => {
|
||||||
eprintln!("Sort {:?} , {:?}", field, order);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("Sort {:?} , {:?}", field, order);
|
||||||
|
}
|
||||||
self.sort = (*field, *order);
|
self.sort = (*field, *order);
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
|
|
|
@ -473,7 +473,9 @@ impl Component for ThreadListing {
|
||||||
let account = &mut context.accounts[self.cursor_pos.0];
|
let account = &mut context.accounts[self.cursor_pos.0];
|
||||||
let (hash, is_seen) = {
|
let (hash, is_seen) = {
|
||||||
let mailbox = &mut account[self.cursor_pos.1].as_mut().unwrap();
|
let mailbox = &mut account[self.cursor_pos.1].as_mut().unwrap();
|
||||||
eprintln!("key is {}", self.locations[dbg!(self.cursor_pos).2]);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("key is {}", self.locations[dbg!(self.cursor_pos).2]);
|
||||||
|
}
|
||||||
let envelope: &Envelope =
|
let envelope: &Envelope =
|
||||||
&mailbox.collection[&self.locations[self.cursor_pos.2]];
|
&mailbox.collection[&self.locations[self.cursor_pos.2]];
|
||||||
(envelope.hash(), envelope.is_seen())
|
(envelope.hash(), envelope.is_seen())
|
||||||
|
@ -653,7 +655,9 @@ impl Component for ThreadListing {
|
||||||
if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 {
|
if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
eprintln!("mailboxupdate");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("mailboxupdate");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UIEventType::ChangeMode(UIMode::Normal) => {
|
UIEventType::ChangeMode(UIMode::Normal) => {
|
||||||
|
@ -670,14 +674,18 @@ impl Component for ThreadListing {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::SubSort(field, order) => {
|
Action::SubSort(field, order) => {
|
||||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||||
|
}
|
||||||
self.subsort = (*field, *order);
|
self.subsort = (*field, *order);
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Action::Sort(field, order) => {
|
Action::Sort(field, order) => {
|
||||||
eprintln!("Sort {:?} , {:?}", field, order);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("Sort {:?} , {:?}", field, order);
|
||||||
|
}
|
||||||
self.sort = (*field, *order);
|
self.sort = (*field, *order);
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
|
@ -699,8 +707,7 @@ impl Component for ThreadListing {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
||||||
self
|
self.view
|
||||||
.view
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| p.get_shortcuts(context))
|
.map(|p| p.get_shortcuts(context))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
|
|
@ -395,13 +395,15 @@ impl Component for MailView {
|
||||||
match event.event_type {
|
match event.event_type {
|
||||||
UIEventType::Input(Key::Char('c')) => {
|
UIEventType::Input(Key::Char('c')) => {
|
||||||
/*
|
/*
|
||||||
let mut new_card: Card = Card::new();
|
let mut new_card: Card = Card::new();
|
||||||
new_card.set_email(&envelope.from()[0].get_email());
|
new_card.set_email(&envelope.from()[0].get_email());
|
||||||
new_card.set_firstname(&envelope.from()[0].get_display_name());
|
new_card.set_firstname(&envelope.from()[0].get_display_name());
|
||||||
|
|
||||||
eprintln!("{:?}", new_card);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:?}", new_card);
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
|
@ -415,7 +417,9 @@ impl Component for MailView {
|
||||||
.address_book
|
.address_book
|
||||||
.add_card(new_card);
|
.add_card(new_card);
|
||||||
}
|
}
|
||||||
|
//if cfg!(feature = "debug_log") {
|
||||||
//eprintln!("{:?}", s.collect());
|
//eprintln!("{:?}", s.collect());
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -573,7 +573,13 @@ impl Component for ThreadView {
|
||||||
let op = context.accounts[self.coordinates.0]
|
let op = context.accounts[self.coordinates.0]
|
||||||
.backend
|
.backend
|
||||||
.operation(envelope.hash(), mailbox.folder.hash());
|
.operation(envelope.hash(), mailbox.folder.hash());
|
||||||
eprintln!("sending action edit for {}, {}", envelope.message_id(), op.description());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!(
|
||||||
|
"sending action edit for {}, {}",
|
||||||
|
envelope.message_id(),
|
||||||
|
op.description()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context.replies.push_back(UIEvent {
|
context.replies.push_back(UIEvent {
|
||||||
id: 0,
|
id: 0,
|
||||||
|
@ -631,16 +637,10 @@ impl Component for ThreadView {
|
||||||
self.mailview.set_dirty();
|
self.mailview.set_dirty();
|
||||||
}
|
}
|
||||||
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
||||||
let mut map = self
|
let mut map = self.mailview.get_shortcuts(context);
|
||||||
.mailview
|
|
||||||
.get_shortcuts(context);
|
|
||||||
|
|
||||||
map.insert(
|
map.insert("reply", Key::Char('R'));
|
||||||
"reply", Key::Char('R')
|
map.insert("toggle_mailview", Key::Char('p'));
|
||||||
);
|
|
||||||
map.insert(
|
|
||||||
"toggle_mailview", Key::Char('p')
|
|
||||||
);
|
|
||||||
|
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,9 @@ impl Component for NotificationFilter {
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
{
|
{
|
||||||
eprintln!("{:?}", v);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:?}", v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ impl Component for VSplit {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mid = get_x(bottom_right) - right_entity_width;
|
let mid = get_x(bottom_right) - right_entity_width;
|
||||||
|
|
||||||
if get_y(upper_left) > 1 {
|
if get_y(upper_left) > 1 {
|
||||||
|
@ -194,17 +194,15 @@ impl Component for VSplit {
|
||||||
}
|
}
|
||||||
|
|
||||||
if right_entity_width == total_cols {
|
if right_entity_width == total_cols {
|
||||||
self.right
|
self.right.component.draw(grid, area, context);
|
||||||
.component
|
|
||||||
.draw(grid, area, context);
|
|
||||||
} else if right_entity_width == 0 {
|
} else if right_entity_width == 0 {
|
||||||
self.left
|
self.left.component.draw(grid, area, context);
|
||||||
.component
|
|
||||||
.draw(grid, area, context);
|
|
||||||
} else {
|
} else {
|
||||||
self.left
|
self.left.component.draw(
|
||||||
.component
|
grid,
|
||||||
.draw(grid, (upper_left, ((mid - 1), get_y(bottom_right))), context);
|
(upper_left, ((mid - 1), get_y(bottom_right))),
|
||||||
|
context,
|
||||||
|
);
|
||||||
self.right
|
self.right
|
||||||
.component
|
.component
|
||||||
.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context);
|
.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context);
|
||||||
|
@ -830,7 +828,7 @@ impl Tabbed {
|
||||||
pub fn new(children: Vec<Box<Component>>) -> Self {
|
pub fn new(children: Vec<Box<Component>>) -> Self {
|
||||||
let pinned = children.len();
|
let pinned = children.len();
|
||||||
Tabbed {
|
Tabbed {
|
||||||
pinned,
|
pinned,
|
||||||
children: children.into_iter().map(Entity::from).collect(),
|
children: children.into_iter().map(Entity::from).collect(),
|
||||||
cursor_pos: 0,
|
cursor_pos: 0,
|
||||||
show_shortcuts: false,
|
show_shortcuts: false,
|
||||||
|
|
|
@ -157,7 +157,9 @@ impl Account {
|
||||||
mailbox!(idx, self.folders).rename(old_hash, new_hash);
|
mailbox!(idx, self.folders).rename(old_hash, new_hash);
|
||||||
}
|
}
|
||||||
RefreshEventKind::Create(envelope) => {
|
RefreshEventKind::Create(envelope) => {
|
||||||
eprintln!("create {}", envelope.hash());
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("create {}", envelope.hash());
|
||||||
|
}
|
||||||
let env: &Envelope = mailbox!(idx, self.folders).insert(*envelope);
|
let env: &Envelope = mailbox!(idx, self.folders).insert(*envelope);
|
||||||
let ref_folders: Vec<Folder> = self.backend.folders();
|
let ref_folders: Vec<Folder> = self.backend.folders();
|
||||||
return Some(Notification(
|
return Some(Notification(
|
||||||
|
@ -200,7 +202,9 @@ impl Account {
|
||||||
pub fn list_folders(&self) -> Vec<Folder> {
|
pub fn list_folders(&self) -> Vec<Folder> {
|
||||||
let mut folders = self.backend.folders();
|
let mut folders = self.backend.folders();
|
||||||
if let Some(folder_confs) = self.settings.conf().folders() {
|
if let Some(folder_confs) = self.settings.conf().folders() {
|
||||||
|
//if cfg!(feature = "debug_log") {
|
||||||
//eprintln!("folder renames: {:?}", folder_renames);
|
//eprintln!("folder renames: {:?}", folder_renames);
|
||||||
|
//}
|
||||||
for f in &mut folders {
|
for f in &mut folders {
|
||||||
if let Some(r) = folder_confs.get(&f.name().to_ascii_lowercase()) {
|
if let Some(r) = folder_confs.get(&f.name().to_ascii_lowercase()) {
|
||||||
if let Some(rename) = r.rename() {
|
if let Some(rename) = r.rename() {
|
||||||
|
|
|
@ -45,7 +45,7 @@ macro_rules! shortcut_key_values {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shortcut_key_values! { "compact-listing",
|
shortcut_key_values! { "compact-listing",
|
||||||
/// Shortcut listing for a mail listing in compact mode.
|
/// Shortcut listing for a mail listing in compact mode.
|
||||||
pub struct CompactListingShortcuts {
|
pub struct CompactListingShortcuts {
|
||||||
open_thread: Key |> "Open thread.",
|
open_thread: Key |> "Open thread.",
|
||||||
|
|
|
@ -241,10 +241,14 @@ impl State {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
s.flush();
|
s.flush();
|
||||||
eprintln!("DEBUG: inserting mailbox hashes:");
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("DEBUG: inserting mailbox hashes:");
|
||||||
|
}
|
||||||
for (x, account) in s.context.accounts.iter_mut().enumerate() {
|
for (x, account) in s.context.accounts.iter_mut().enumerate() {
|
||||||
for (y, folder) in account.backend.folders().iter().enumerate() {
|
for (y, folder) in account.backend.folders().iter().enumerate() {
|
||||||
eprintln!("{:?}", folder);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("{:?}", folder);
|
||||||
|
}
|
||||||
s.context.mailbox_hashes.insert(folder.hash(), (x, y));
|
s.context.mailbox_hashes.insert(folder.hash(), (x, y));
|
||||||
}
|
}
|
||||||
let sender = s.context.sender.clone();
|
let sender = s.context.sender.clone();
|
||||||
|
@ -507,7 +511,9 @@ impl State {
|
||||||
let flag = match &mut self.context.accounts[account_idx][folder_idx] {
|
let flag = match &mut self.context.accounts[account_idx][folder_idx] {
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("error {:?}", e);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("error {:?}", e);
|
||||||
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
Define a (x, y) point in the terminal display as a holder of a character, foreground/background
|
Define a (x, y) point in the terminal display as a holder of a character, foreground/background
|
||||||
colors and attributes.
|
colors and attributes.
|
||||||
*/
|
*/
|
||||||
use super::position::*;
|
|
||||||
use super::grapheme_clusters::*;
|
use super::grapheme_clusters::*;
|
||||||
|
use super::position::*;
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::{Deref, DerefMut, Index, IndexMut};
|
use std::ops::{Deref, DerefMut, Index, IndexMut};
|
||||||
|
@ -637,7 +637,9 @@ pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area,
|
||||||
let mut src_y = get_y(upper_left!(src));
|
let mut src_y = get_y(upper_left!(src));
|
||||||
let (cols, rows) = grid_src.size();
|
let (cols, rows) = grid_src.size();
|
||||||
if src_x >= cols || src_y >= rows {
|
if src_x >= cols || src_y >= rows {
|
||||||
eprintln!("DEBUG: src area outside of grid_src in copy_area",);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("DEBUG: src area outside of grid_src in copy_area",);
|
||||||
|
}
|
||||||
return upper_left!(dest);
|
return upper_left!(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,11 +676,15 @@ pub fn change_colors(grid: &mut CellBuffer, area: Area, fg_color: Color, bg_colo
|
||||||
|| y >= get_y(bounds)
|
|| y >= get_y(bounds)
|
||||||
|| x >= get_x(bounds)
|
|| x >= get_x(bounds)
|
||||||
{
|
{
|
||||||
eprintln!("BUG: Invalid area in change_colors:\n area: {:?}", area);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("BUG: Invalid area in change_colors:\n area: {:?}", area);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if !is_valid_area!(area) {
|
if !is_valid_area!(area) {
|
||||||
eprintln!("BUG: Invalid area in change_colors:\n area: {:?}", area);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("BUG: Invalid area in change_colors:\n area: {:?}", area);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for y in get_y(upper_left!(area))..=get_y(bottom_right!(area)) {
|
for y in get_y(upper_left!(area))..=get_y(bottom_right!(area)) {
|
||||||
|
@ -711,7 +717,9 @@ pub fn write_string_to_grid(
|
||||||
|| y > get_y(bounds)
|
|| y > get_y(bounds)
|
||||||
|| x > get_x(bounds)
|
|| x > get_x(bounds)
|
||||||
{
|
{
|
||||||
eprintln!(" Invalid area with string {} and area {:?}", s, area);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!(" Invalid area with string {} and area {:?}", s, area);
|
||||||
|
}
|
||||||
return (x, y);
|
return (x, y);
|
||||||
}
|
}
|
||||||
'char: for c in s.chars() {
|
'char: for c in s.chars() {
|
||||||
|
@ -756,10 +764,7 @@ pub fn word_break_string(mut s: &str, width: usize) -> Vec<&str> {
|
||||||
let graphemes = s.graphemes_indices();
|
let graphemes = s.graphemes_indices();
|
||||||
if graphemes.len() > width {
|
if graphemes.len() > width {
|
||||||
// use grapheme indices and find position of " " graphemes
|
// use grapheme indices and find position of " " graphemes
|
||||||
if let Some(next_idx) = graphemes[..width]
|
if let Some(next_idx) = graphemes[..width].iter().rposition(|(_, g)| *g == " ") {
|
||||||
.iter()
|
|
||||||
.rposition(|(_, g)| *g == " ")
|
|
||||||
{
|
|
||||||
let next_idx = graphemes[next_idx].0;
|
let next_idx = graphemes[next_idx].0;
|
||||||
ret.push(&s[..next_idx]);
|
ret.push(&s[..next_idx]);
|
||||||
s = &s[next_idx + 1..];
|
s = &s[next_idx + 1..];
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
||||||
pub trait Graphemes: UnicodeSegmentation + CodePointsIter {
|
pub trait Graphemes: UnicodeSegmentation + CodePointsIter {
|
||||||
fn split_graphemes<'a>(&'a self) -> Vec<&'a str> {
|
fn split_graphemes<'a>(&'a self) -> Vec<&'a str> {
|
||||||
UnicodeSegmentation::graphemes(self, true).collect::<Vec<&str>>()
|
UnicodeSegmentation::graphemes(self, true).collect::<Vec<&str>>()
|
||||||
|
|
|
@ -196,9 +196,15 @@ macro_rules! derive_csi_sequence {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
derive_csi_sequence!(#[doc="Empty struct with a Display implementation that returns the byte sequence to start [Bracketed Paste Mode](http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode)"] (BracketModeStart, "?2004h"));
|
derive_csi_sequence!(
|
||||||
|
#[doc = "Empty struct with a Display implementation that returns the byte sequence to start [Bracketed Paste Mode](http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode)"]
|
||||||
|
(BracketModeStart, "?2004h")
|
||||||
|
);
|
||||||
|
|
||||||
derive_csi_sequence!(#[doc="Empty struct with a Display implementation that returns the byte sequence to end [Bracketed Paste Mode](http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode)"] (BracketModeEnd, "?2003l"));
|
derive_csi_sequence!(
|
||||||
|
#[doc = "Empty struct with a Display implementation that returns the byte sequence to end [Bracketed Paste Mode](http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode)"]
|
||||||
|
(BracketModeEnd, "?2003l")
|
||||||
|
);
|
||||||
|
|
||||||
pub const BRACKET_PASTE_START: &[u8] = b"\x1B[200~";
|
pub const BRACKET_PASTE_START: &[u8] = b"\x1B[200~";
|
||||||
pub const BRACKET_PASTE_END: &[u8] = b"\x1B[201~";
|
pub const BRACKET_PASTE_END: &[u8] = b"\x1B[201~";
|
||||||
|
|
|
@ -226,7 +226,9 @@ impl WorkController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report the amount of work done.
|
// Report the amount of work done.
|
||||||
eprintln!("Thread {} did {} jobs.", thread_num, work_done);
|
if cfg!(feature = "debug_log") {
|
||||||
|
eprintln!("Thread {} did {} jobs.", thread_num, work_done);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add the handle for the newly spawned thread to the list of handles
|
// Add the handle for the newly spawned thread to the list of handles
|
||||||
|
|
Loading…
Reference in New Issue