melib: add clear debug prints in email structs

embed
Manos Pitsidianakis 2018-09-22 16:56:50 +03:00
parent b0097574a5
commit 2f3c168aeb
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 44 additions and 8 deletions

View File

@ -61,7 +61,7 @@ pub struct MailboxAddress {
address_spec: StrBuilder,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub enum Address {
Mailbox(MailboxAddress),
Group(GroupAddress),
@ -78,11 +78,11 @@ impl PartialEq for Address {
s.address_spec.display(&s.raw) == o.address_spec.display(&o.raw)
}
(Address::Group(s), Address::Group(o)) => {
s.display_name.display(&s.raw) == o.display_name.display(&o.raw)
&& s.mailbox_list
.iter()
.zip(o.mailbox_list.iter())
.fold(true, |b, (s, o)| b && (s == o))
s.display_name.display(&s.raw) == o.display_name.display(&o.raw) && s
.mailbox_list
.iter()
.zip(o.mailbox_list.iter())
.fold(true, |b, (s, o)| b && (s == o))
}
}
}
@ -112,6 +112,12 @@ impl fmt::Display for Address {
}
}
impl fmt::Debug for Address {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
/// Helper struct to return slices from a struct field on demand.
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
struct StrBuilder {
@ -270,7 +276,7 @@ pub type EnvelopeHash = u64;
/// Access to the underlying email object in the account's backend (for example the file or the
/// entry in an IMAP server) is given through `operation_token`. For more information see
/// `BackendOp`.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct Envelope {
date: String,
from: Vec<Address>,
@ -290,6 +296,19 @@ pub struct Envelope {
flags: Flag,
}
impl fmt::Debug for Envelope {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Envelope {{\ndate: {}\n,from:{:#?}\nto {:#?}\nmessage_id: {},\n references: {:#?}\nhash: {}\n
}}",
self.date,
self.from,
self.to,
self.message_id_display(),
self.references,
self.hash)
}
}
impl Envelope {
pub fn new(hash: EnvelopeHash) -> Self {
Envelope {

View File

@ -43,6 +43,7 @@ use std::option::Option;
#[derive(Debug)]
pub struct Mailbox {
pub folder: Folder,
name: String,
pub collection: Collection,
has_sent: bool,
}
@ -53,6 +54,7 @@ impl Clone for Mailbox {
folder: self.folder.clone(),
collection: self.collection.clone(),
has_sent: self.has_sent,
name: self.name.clone(),
}
}
}
@ -62,6 +64,7 @@ impl Default for Mailbox {
folder: folder_default(),
collection: Collection::default(),
has_sent: false,
name: String::new(),
}
}
}
@ -71,12 +74,19 @@ impl Mailbox {
let mut envelopes: Vec<Envelope> = envelopes?;
envelopes.sort_by(|a, b| a.date().cmp(&b.date()));
let collection = Collection::new(envelopes, &folder);
let name = folder.name().into();
Ok(Mailbox {
folder,
collection,
name: name,
..Default::default()
})
}
pub fn name(&self) -> &str {
&self.name
}
pub fn is_empty(&self) -> bool {
self.collection.is_empty()
}

View File

@ -40,6 +40,7 @@ use self::fnv::{FnvHashMap, FnvHashSet};
use std::cell::{Ref, RefCell};
use std::cmp;
use std::cmp::Ordering;
use std::fmt;
use std::iter::FromIterator;
use std::mem;
use std::ops::Index;
@ -199,12 +200,18 @@ impl FromStr for SortOrder {
/*
* The thread tree holds the sorted state of the thread nodes */
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Deserialize, Serialize)]
struct ThreadTree {
id: usize,
children: Vec<ThreadTree>,
}
impl fmt::Debug for ThreadTree {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "")
}
}
impl ThreadTree {
fn new(id: usize) -> Self {
ThreadTree {