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]
|
||||
members = ["melib", "ui"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
debug_log = []
|
||||
|
|
|
@ -28,8 +28,8 @@ use std::error::Error;
|
|||
use std::fmt;
|
||||
use std::io;
|
||||
use std::result;
|
||||
use std::string;
|
||||
use std::str;
|
||||
use std::string;
|
||||
|
||||
use nom;
|
||||
|
||||
|
|
|
@ -120,12 +120,14 @@ impl Mailbox {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, envelope_hash: EnvelopeHash) {
|
||||
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 {
|
||||
let map = self.hash_index.lock().unwrap();
|
||||
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) {
|
||||
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() {
|
||||
eprintln!("{:#?}", e);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("{:#?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
map.get(&self.hash).unwrap().clone()
|
||||
|
|
|
@ -142,7 +142,9 @@ fn move_to_cur(p: PathBuf) -> PathBuf {
|
|||
new.push(file_name);
|
||||
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();
|
||||
new
|
||||
}
|
||||
|
@ -163,7 +165,9 @@ impl MailBackend for MaildirType {
|
|||
if f.is_valid().is_err() {
|
||||
continue;
|
||||
}
|
||||
eprintln!("watching {:?}", f);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("watching {:?}", f);
|
||||
}
|
||||
let mut p = PathBuf::from(&f.path);
|
||||
p.push("cur");
|
||||
watcher.watch(&p, RecursiveMode::NonRecursive).unwrap();
|
||||
|
@ -208,7 +212,9 @@ impl MailBackend for MaildirType {
|
|||
&cache_dir,
|
||||
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 {
|
||||
hash: folder_hash,
|
||||
kind: Create(Box::new(env)),
|
||||
|
@ -257,7 +263,9 @@ impl MailBackend for MaildirType {
|
|||
if index_lock.get_mut(&new_hash).is_none() {
|
||||
let op = Box::new(MaildirOp::new(new_hash, hash_indexes.clone(), folder_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);
|
||||
|
||||
/* Send Write notice */
|
||||
|
@ -267,7 +275,9 @@ impl MailBackend for MaildirType {
|
|||
kind: Update(old_hash, Box::new(env)),
|
||||
});
|
||||
} 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();
|
||||
path.push("cur");
|
||||
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 mut writer = io::BufWriter::new(file);
|
||||
writer.write_all(&message.into_bytes())?;
|
||||
|
@ -545,7 +557,9 @@ impl MaildirType {
|
|||
}
|
||||
local_r.push(e);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -592,12 +606,16 @@ fn add_path_to_index(
|
|||
map.len()
|
||||
);
|
||||
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));
|
||||
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) {
|
||||
/* place result in cache directory */
|
||||
let f = match fs::File::create(cached) {
|
||||
|
|
|
@ -56,24 +56,26 @@ 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;
|
||||
if cfg!(feature = "debug_log") {
|
||||
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(),
|
||||
|
@ -93,7 +95,9 @@ impl Collection {
|
|||
}
|
||||
|
||||
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.threads.remove(envelope_hash, &mut self.envelopes);
|
||||
}
|
||||
|
@ -132,7 +136,9 @@ impl Collection {
|
|||
|
||||
pub fn insert(&mut self, envelope: Envelope) {
|
||||
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);
|
||||
let env = self.envelopes.entry(hash).or_default() as *mut Envelope;
|
||||
unsafe {
|
||||
|
@ -142,10 +148,12 @@ impl Collection {
|
|||
pub(crate) fn insert_reply(&mut self, _envelope: &Envelope) {
|
||||
return;
|
||||
/*
|
||||
//self.insert(envelope);
|
||||
//self.insert(envelope);
|
||||
if cfg!(feature = "debug_log") {
|
||||
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() {
|
||||
Ok(v) => v,
|
||||
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.");
|
||||
return Err(MeliError::new(error_msg));
|
||||
}
|
||||
|
@ -538,7 +540,9 @@ impl Envelope {
|
|||
let (headers, body) = match parser::mail(bytes).to_full_result() {
|
||||
Ok(v) => v,
|
||||
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 mut builder = AttachmentBuilder::new(error_msg);
|
||||
return builder.build();
|
||||
|
@ -560,34 +564,42 @@ impl Envelope {
|
|||
pub fn headers<'a>(&self, bytes: &'a [u8]) -> Result<Vec<(&'a str, &'a str)>> {
|
||||
let ret = parser::headers(bytes).to_full_result()?;
|
||||
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 {
|
||||
let file = operation.as_bytes();
|
||||
self.body_bytes(file.unwrap())
|
||||
/*
|
||||
let (headers, body) = match parser::mail(file.unwrap()).to_full_result() {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
eprintln!("2error in parsing mail\n");
|
||||
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);
|
||||
}
|
||||
let (headers, body) = match parser::mail(file.unwrap()).to_full_result() {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("2error in parsing mail\n");
|
||||
}
|
||||
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> {
|
||||
match self.subject {
|
||||
|
|
|
@ -68,7 +68,9 @@ impl<'a> From<&'a [u8]> for Charset {
|
|||
b"BIG5" | b"big5" => Charset::BIG5,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,7 +143,9 @@ impl AttachmentBuilder {
|
|||
}
|
||||
}
|
||||
Err(v) => {
|
||||
eprintln!("parsing error in content_type: {:?} {:?}", value, v);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("parsing error in content_type: {:?} {:?}", value, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
self
|
||||
|
@ -209,10 +211,18 @@ impl AttachmentBuilder {
|
|||
let (headers, body) = match parser::attachment(&a).to_full_result() {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
eprintln!("error in parsing attachment");
|
||||
eprintln!("\n-------------------------------");
|
||||
eprintln!("{}\n", ::std::string::String::from_utf8_lossy(a));
|
||||
eprintln!("-------------------------------\n");
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("error in parsing attachment");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -384,18 +394,22 @@ fn decode_rfc822(_raw: &[u8]) -> Attachment {
|
|||
builder.build()
|
||||
|
||||
/*
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("raw is\n{:?}", str::from_utf8(raw).unwrap());
|
||||
let e = match Envelope::from_bytes(raw) {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
eprintln!("error in parsing mail");
|
||||
let error_msg = b"Mail cannot be shown because of errors.";
|
||||
let mut builder = AttachmentBuilder::new(error_msg);
|
||||
return builder.build();
|
||||
}
|
||||
};
|
||||
e.body(None)
|
||||
*/
|
||||
}
|
||||
let e = match Envelope::from_bytes(raw) {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("error in parsing mail");
|
||||
}
|
||||
let error_msg = b"Mail cannot be shown because of errors.";
|
||||
let mut builder = AttachmentBuilder::new(error_msg);
|
||||
return builder.build();
|
||||
}
|
||||
};
|
||||
e.body(None)
|
||||
*/
|
||||
}
|
||||
|
||||
type Filter = Box<Fn(&Attachment, &mut Vec<u8>) -> ()>;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::*;
|
||||
use mailbox::backends::BackendOp;
|
||||
use chrono::{DateTime, Local};
|
||||
use data_encoding::BASE64_MIME;
|
||||
use mailbox::backends::BackendOp;
|
||||
use std::str;
|
||||
|
||||
mod mime;
|
||||
|
@ -95,18 +95,16 @@ impl str::FromStr for Draft {
|
|||
|
||||
impl Draft {
|
||||
pub fn edit(envelope: &Envelope, mut op: Box<BackendOp>) -> Self {
|
||||
|
||||
let mut ret = Draft::default();
|
||||
//TODO: Inform user if error
|
||||
{
|
||||
let bytes = op.as_bytes().unwrap_or(&[]);
|
||||
for (h, v) in envelope.headers(bytes).unwrap_or_else(|_| Vec::new()) {
|
||||
ret.header_order.push(h.into());
|
||||
ret.headers_mut()
|
||||
.insert(h.into(), v.into());
|
||||
ret.headers_mut().insert(h.into(), v.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ret.body = envelope.body(op).text();
|
||||
|
||||
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";
|
||||
let __s = b"=?utf-8?q?Thu=2C_31_Aug_2017_13=3A43=3A37_-0000?=";
|
||||
eprintln!("{:?}, {:?}", date(s), date(_s));
|
||||
eprintln!("{:?}", date(__s));
|
||||
if cfg!(feature = "debug_log") {
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -578,23 +578,39 @@ impl Threads {
|
|||
t.create_root_set(collection);
|
||||
t.build_collection(collection);
|
||||
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() {
|
||||
eprintln!("{:?}", _t.children);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("{:?}", _t.children);
|
||||
}
|
||||
}
|
||||
if let Some(m) = _t.message {
|
||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||
}
|
||||
} 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() {
|
||||
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 {
|
||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("\tmessage: {}", collection[&m].subject());
|
||||
}
|
||||
} else {
|
||||
eprintln!("\tNo message");
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("\tNo message");
|
||||
}
|
||||
}
|
||||
}
|
||||
t
|
||||
|
@ -834,7 +850,9 @@ impl Threads {
|
|||
// .iter()
|
||||
// .position(|n| n.message.map(|n| n == envelope_hash).unwrap_or(false))
|
||||
// .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;
|
||||
|
@ -893,7 +911,9 @@ impl Threads {
|
|||
let difference: Vec<EnvelopeHash> =
|
||||
new_hash_set.difference(&self.hash_set).cloned().collect();
|
||||
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;
|
||||
unsafe {
|
||||
// `collection` is borrowed immutably and `insert` only changes the envelope's
|
||||
|
|
|
@ -94,7 +94,9 @@ impl AccountMenu {
|
|||
context: &mut Context,
|
||||
) -> usize {
|
||||
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 bottom_right = bottom_right!(area);
|
||||
|
@ -290,6 +292,9 @@ impl Component for AccountMenu {
|
|||
self.dirty = true;
|
||||
}
|
||||
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 width = width - 80;
|
||||
let mid = if self.reply_context.is_some() {
|
||||
get_x(upper_left) + width!(area) / 2
|
||||
get_x(upper_left) + width!(area) / 2
|
||||
} else {
|
||||
width / 2
|
||||
};
|
||||
|
@ -305,28 +305,56 @@ impl Component for Composer {
|
|||
}
|
||||
|
||||
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), (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)
|
||||
(
|
||||
set_x(upper_left, mid + 1),
|
||||
set_y(bottom_right, get_y(upper_left) + header_height + 1),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
pos_inc(upper_left, (mid + 1, header_height + 2)),
|
||||
pos_dec(bottom_right, (mid, 0)),
|
||||
)
|
||||
set_x(upper_left, mid + 1),
|
||||
(
|
||||
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(
|
||||
if self.reply_context.is_some() { "COMPOSING REPLY" } else { "COMPOSING MESSAGE" },
|
||||
grid,
|
||||
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));
|
||||
|
||||
if self.reply_context.is_some() {
|
||||
"COMPOSING REPLY"
|
||||
} else {
|
||||
"COMPOSING MESSAGE"
|
||||
},
|
||||
grid,
|
||||
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 */
|
||||
self.form.draw(grid, header_area, context);
|
||||
|
||||
|
@ -459,9 +487,13 @@ impl Component for Composer {
|
|||
('y', ViewMode::Discard(u)) => {
|
||||
let account = &context.accounts[self.account_cursor];
|
||||
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());
|
||||
//}
|
||||
context.replies.push_back(UIEvent {
|
||||
id: 0,
|
||||
event_type: UIEventType::Action(Tab(Kill(*u))),
|
||||
|
|
|
@ -165,13 +165,17 @@ impl CompactListing {
|
|||
threads.thread_nodes()[iter_ptr].message().unwrap()
|
||||
};
|
||||
if !mailbox.collection.contains_key(&i) {
|
||||
eprintln!("key = {}", i);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("key = {}", i);
|
||||
}
|
||||
eprintln!(
|
||||
"name = {} {}",
|
||||
mailbox.name(),
|
||||
context.accounts[self.cursor_pos.0].name()
|
||||
);
|
||||
eprintln!("{:#?}", context.accounts);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("{:#?}", context.accounts);
|
||||
}
|
||||
|
||||
panic!();
|
||||
}
|
||||
|
@ -494,13 +498,17 @@ impl Component for CompactListing {
|
|||
return true;
|
||||
}
|
||||
Action::SubSort(field, order) => {
|
||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||
}
|
||||
self.subsort = (*field, *order);
|
||||
self.refresh_mailbox(context);
|
||||
return true;
|
||||
}
|
||||
Action::Sort(field, order) => {
|
||||
eprintln!("Sort {:?} , {:?}", field, order);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("Sort {:?} , {:?}", field, order);
|
||||
}
|
||||
self.sort = (*field, *order);
|
||||
self.refresh_mailbox(context);
|
||||
return true;
|
||||
|
|
|
@ -532,14 +532,18 @@ impl Component for PlainListing {
|
|||
return true;
|
||||
}
|
||||
Action::SubSort(field, order) => {
|
||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||
}
|
||||
self.subsort = (*field, *order);
|
||||
self.dirty = true;
|
||||
self.refresh_mailbox(context);
|
||||
return true;
|
||||
}
|
||||
Action::Sort(field, order) => {
|
||||
eprintln!("Sort {:?} , {:?}", field, order);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("Sort {:?} , {:?}", field, order);
|
||||
}
|
||||
self.sort = (*field, *order);
|
||||
self.dirty = true;
|
||||
self.refresh_mailbox(context);
|
||||
|
|
|
@ -473,7 +473,9 @@ impl Component for ThreadListing {
|
|||
let account = &mut context.accounts[self.cursor_pos.0];
|
||||
let (hash, is_seen) = {
|
||||
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 =
|
||||
&mailbox.collection[&self.locations[self.cursor_pos.2]];
|
||||
(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 {
|
||||
self.dirty = true;
|
||||
self.refresh_mailbox(context);
|
||||
eprintln!("mailboxupdate");
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("mailboxupdate");
|
||||
}
|
||||
}
|
||||
}
|
||||
UIEventType::ChangeMode(UIMode::Normal) => {
|
||||
|
@ -670,14 +674,18 @@ impl Component for ThreadListing {
|
|||
return true;
|
||||
}
|
||||
Action::SubSort(field, order) => {
|
||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("SubSort {:?} , {:?}", field, order);
|
||||
}
|
||||
self.subsort = (*field, *order);
|
||||
self.dirty = true;
|
||||
self.refresh_mailbox(context);
|
||||
return true;
|
||||
}
|
||||
Action::Sort(field, order) => {
|
||||
eprintln!("Sort {:?} , {:?}", field, order);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("Sort {:?} , {:?}", field, order);
|
||||
}
|
||||
self.sort = (*field, *order);
|
||||
self.dirty = true;
|
||||
self.refresh_mailbox(context);
|
||||
|
@ -699,8 +707,7 @@ impl Component for ThreadListing {
|
|||
self.dirty = true;
|
||||
}
|
||||
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
||||
self
|
||||
.view
|
||||
self.view
|
||||
.as_ref()
|
||||
.map(|p| p.get_shortcuts(context))
|
||||
.unwrap_or_default()
|
||||
|
|
|
@ -395,13 +395,15 @@ impl Component for MailView {
|
|||
match event.event_type {
|
||||
UIEventType::Input(Key::Char('c')) => {
|
||||
/*
|
||||
let mut new_card: Card = Card::new();
|
||||
new_card.set_email(&envelope.from()[0].get_email());
|
||||
new_card.set_firstname(&envelope.from()[0].get_display_name());
|
||||
let mut new_card: Card = Card::new();
|
||||
new_card.set_email(&envelope.from()[0].get_email());
|
||||
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(s) =
|
||||
std::mem::replace(&mut self.mode, ViewMode::Normal)
|
||||
|
@ -415,7 +417,9 @@ impl Component for MailView {
|
|||
.address_book
|
||||
.add_card(new_card);
|
||||
}
|
||||
//if cfg!(feature = "debug_log") {
|
||||
//eprintln!("{:?}", s.collect());
|
||||
//}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -573,7 +573,13 @@ impl Component for ThreadView {
|
|||
let op = context.accounts[self.coordinates.0]
|
||||
.backend
|
||||
.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 {
|
||||
id: 0,
|
||||
|
@ -631,16 +637,10 @@ impl Component for ThreadView {
|
|||
self.mailview.set_dirty();
|
||||
}
|
||||
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
||||
let mut map = self
|
||||
.mailview
|
||||
.get_shortcuts(context);
|
||||
let mut map = self.mailview.get_shortcuts(context);
|
||||
|
||||
map.insert(
|
||||
"reply", Key::Char('R')
|
||||
);
|
||||
map.insert(
|
||||
"toggle_mailview", Key::Char('p')
|
||||
);
|
||||
map.insert("reply", Key::Char('R'));
|
||||
map.insert("toggle_mailview", Key::Char('p'));
|
||||
|
||||
map
|
||||
}
|
||||
|
|
|
@ -125,7 +125,9 @@ impl Component for NotificationFilter {
|
|||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
{
|
||||
eprintln!("{:?}", v);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("{:?}", v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ impl Component for VSplit {
|
|||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mid = get_x(bottom_right) - right_entity_width;
|
||||
|
||||
if get_y(upper_left) > 1 {
|
||||
|
@ -194,17 +194,15 @@ impl Component for VSplit {
|
|||
}
|
||||
|
||||
if right_entity_width == total_cols {
|
||||
self.right
|
||||
.component
|
||||
.draw(grid, area, context);
|
||||
self.right.component.draw(grid, area, context);
|
||||
} else if right_entity_width == 0 {
|
||||
self.left
|
||||
.component
|
||||
.draw(grid, area, context);
|
||||
self.left.component.draw(grid, area, context);
|
||||
} else {
|
||||
self.left
|
||||
.component
|
||||
.draw(grid, (upper_left, ((mid - 1), get_y(bottom_right))), context);
|
||||
self.left.component.draw(
|
||||
grid,
|
||||
(upper_left, ((mid - 1), get_y(bottom_right))),
|
||||
context,
|
||||
);
|
||||
self.right
|
||||
.component
|
||||
.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 {
|
||||
let pinned = children.len();
|
||||
Tabbed {
|
||||
pinned,
|
||||
pinned,
|
||||
children: children.into_iter().map(Entity::from).collect(),
|
||||
cursor_pos: 0,
|
||||
show_shortcuts: false,
|
||||
|
|
|
@ -157,7 +157,9 @@ impl Account {
|
|||
mailbox!(idx, self.folders).rename(old_hash, new_hash);
|
||||
}
|
||||
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 ref_folders: Vec<Folder> = self.backend.folders();
|
||||
return Some(Notification(
|
||||
|
@ -200,7 +202,9 @@ impl Account {
|
|||
pub fn list_folders(&self) -> Vec<Folder> {
|
||||
let mut folders = self.backend.folders();
|
||||
if let Some(folder_confs) = self.settings.conf().folders() {
|
||||
//if cfg!(feature = "debug_log") {
|
||||
//eprintln!("folder renames: {:?}", folder_renames);
|
||||
//}
|
||||
for f in &mut folders {
|
||||
if let Some(r) = folder_confs.get(&f.name().to_ascii_lowercase()) {
|
||||
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.
|
||||
pub struct CompactListingShortcuts {
|
||||
open_thread: Key |> "Open thread.",
|
||||
|
|
|
@ -241,10 +241,14 @@ impl State {
|
|||
)
|
||||
.unwrap();
|
||||
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 (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));
|
||||
}
|
||||
let sender = s.context.sender.clone();
|
||||
|
@ -507,7 +511,9 @@ impl State {
|
|||
let flag = match &mut self.context.accounts[account_idx][folder_idx] {
|
||||
Ok(_) => true,
|
||||
Err(e) => {
|
||||
eprintln!("error {:?}", e);
|
||||
if cfg!(feature = "debug_log") {
|
||||
eprintln!("error {:?}", e);
|
||||
}
|
||||
false
|
||||
}
|
||||
};
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
Define a (x, y) point in the terminal display as a holder of a character, foreground/background
|
||||
colors and attributes.
|
||||
*/
|
||||
use super::position::*;
|
||||
use super::grapheme_clusters::*;
|
||||
use super::position::*;
|
||||
use std::convert::From;
|
||||
use std::fmt;
|
||||
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 (cols, rows) = grid_src.size();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -674,11 +676,15 @@ pub fn change_colors(grid: &mut CellBuffer, area: Area, fg_color: Color, bg_colo
|
|||
|| y >= get_y(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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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)
|
||||
|| 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);
|
||||
}
|
||||
'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();
|
||||
if graphemes.len() > width {
|
||||
// use grapheme indices and find position of " " graphemes
|
||||
if let Some(next_idx) = graphemes[..width]
|
||||
.iter()
|
||||
.rposition(|(_, g)| *g == " ")
|
||||
{
|
||||
if let Some(next_idx) = graphemes[..width].iter().rposition(|(_, g)| *g == " ") {
|
||||
let next_idx = graphemes[next_idx].0;
|
||||
ret.push(&s[..next_idx]);
|
||||
s = &s[next_idx + 1..];
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
|
||||
pub trait Graphemes: UnicodeSegmentation + CodePointsIter {
|
||||
fn split_graphemes<'a>(&'a self) -> Vec<&'a 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_END: &[u8] = b"\x1B[201~";
|
||||
|
|
|
@ -226,7 +226,9 @@ impl WorkController {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
|
Loading…
Reference in New Issue