diff options
26 files changed, 205 insertions, 409 deletions
diff --git a/melib/src/lib.rs b/melib/src/lib.rs index bf249917..0df248d2 100644 --- a/melib/src/lib.rs +++ b/melib/src/lib.rs @@ -18,6 +18,43 @@ * You should have received a copy of the GNU General Public License * along with meli. If not, see <http://www.gnu.org/licenses/>. */ +#[macro_use] +pub mod dbg { + #[macro_export] + macro_rules! debug { + ($val:expr) => { + if cfg!(debug_assertions) { + eprint!( + "[{:?}] {}:{}_{}: ", + std::thread::current() + .name() + .map(|v| v.to_string()) + .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), + file!(), + line!(), + column!() + ); + eprintln!("{}", $val); + } + }; + ($fmt:literal, $($arg:tt)*) => { + if cfg!(debug_assertions) { + eprint!( + "[{:?}] {}:{}_{}: ", + std::thread::current() + .name() + .map(|v| v.to_string()) + .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), + file!(), + line!(), + column!() + ); + eprintln!($fmt, $($arg)*); + } + }; + } +} + pub mod addressbook; pub mod async_workers; pub mod conf; diff --git a/melib/src/mailbox.rs b/melib/src/mailbox.rs index 7a2c65fa..ac93cc30 100644 --- a/melib/src/mailbox.rs +++ b/melib/src/mailbox.rs @@ -120,16 +120,12 @@ impl Mailbox { } pub fn insert_reply(&mut self, envelope: &Envelope) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("mailbox insert reply {}", self.name); - } + debug!("mailbox insert reply {}", self.name); self.collection.insert_reply(envelope); } pub fn remove(&mut self, envelope_hash: EnvelopeHash) { self.collection.remove(envelope_hash); - // if cfg!(debug_assertions) { eprint!("{}:{}_{}: ", file!(), line!(), column!()); - // eprintln!("envelope_hash: {}\ncollection:\n{:?}", envelope_hash, self.collection); } + // debug!("envelope_hash: {}\ncollection:\n{:?}", envelope_hash, self.collection); } } diff --git a/melib/src/mailbox/backends/maildir.rs b/melib/src/mailbox/backends/maildir.rs index 8b9c210b..6cf11f36 100644 --- a/melib/src/mailbox/backends/maildir.rs +++ b/melib/src/mailbox/backends/maildir.rs @@ -66,20 +66,11 @@ impl MaildirOp { fn path(&self) -> PathBuf { let map = self.hash_index.lock().unwrap(); let map = &map[&self.folder_hash]; - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("looking for {} in {} map", self.hash, self.folder_hash); - } + debug!("looking for {} in {} map", self.hash, self.folder_hash); if !map.contains_key(&self.hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("doesn't contain it though len = {}\n{:#?}", map.len(), map); - } + debug!("doesn't contain it though len = {}\n{:#?}", map.len(), map); for e in map.iter() { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("{:#?}", e); - } + debug!("{:#?}", e); } } map.get(&self.hash).unwrap().clone() @@ -125,8 +116,7 @@ impl<'a> BackendOp for MaildirOp { 'S' => flag |= Flag::SEEN, 'T' => flag |= Flag::TRASHED, _ => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("DEBUG: in fetch_flags, path is {}", path); + debug!("DEBUG: in fetch_flags, path is {}", path); } } } @@ -166,15 +156,9 @@ impl<'a> BackendOp for MaildirOp { new_name.push('T'); } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("renaming {:?} to {:?}", path, new_name); - } + debug!("renaming {:?} to {:?}", path, new_name); fs::rename(&path, &new_name)?; - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("success in rename"); - } + debug!("success in rename"); let old_hash = envelope.hash(); let new_name: PathBuf = new_name.into(); let new_hash = get_file_hash(&new_name); diff --git a/melib/src/mailbox/backends/maildir/backend.rs b/melib/src/mailbox/backends/maildir/backend.rs index 781338dc..b23aab54 100644 --- a/melib/src/mailbox/backends/maildir/backend.rs +++ b/melib/src/mailbox/backends/maildir/backend.rs @@ -137,10 +137,7 @@ fn move_to_cur(p: PathBuf) -> PathBuf { if !file_name.ends_with(":2,") { new.set_extension(":2,"); } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("moved to cur: {}", new.display()); - } + debug!("moved to cur: {}", new.display()); fs::rename(p, &new).unwrap(); new } @@ -161,10 +158,7 @@ impl MailBackend for MaildirType { let root_path = self.path.to_path_buf(); watcher.watch(&root_path, RecursiveMode::Recursive).unwrap(); let cache_dir = xdg::BaseDirectories::with_profile("meli", &self.name).unwrap(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("watching {:?}", root_path); - } + debug!("watching {:?}", root_path); let hash_indexes = self.hash_indexes.clone(); thread::Builder::new() .name("folder watch".to_string()) @@ -186,11 +180,9 @@ impl MailBackend for MaildirType { Ok(event) => match event { /* Create */ DebouncedEvent::Create(mut pathbuf) => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DebouncedEvent::Create(path = {:?}", pathbuf); + debug!("DebouncedEvent::Create(path = {:?}", pathbuf); if path_is_new!(pathbuf) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("path_is_new"); + debug!("path_is_new"); /* This creates a Rename event that we will receive later */ pathbuf = move_to_cur(pathbuf); } @@ -200,8 +192,6 @@ eprintln!("path_is_new"); .strip_prefix(&root_path) .unwrap() .to_path_buf(); - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("cilename is {:?}", file_name); if let Some(env) = add_path_to_index( &hash_indexes, folder_hash, @@ -209,10 +199,7 @@ eprintln!("cilename is {:?}", file_name); &cache_dir, file_name, ) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display()); - } + debug!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display()); sender.send(RefreshEvent { hash: folder_hash, kind: Create(Box::new(env)), @@ -222,8 +209,7 @@ eprintln!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display()) /* Update */ DebouncedEvent::NoticeWrite(pathbuf) | DebouncedEvent::Write(pathbuf) => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DebouncedEvent::Write(path = {:?}", pathbuf); + debug!("DebouncedEvent::Write(path = {:?}", &pathbuf); let folder_hash = get_path_hash!(pathbuf); let mut hash_indexes_lock = hash_indexes.lock().unwrap(); let index_lock = &mut hash_indexes_lock.entry(folder_hash).or_default(); @@ -260,14 +246,11 @@ eprintln!("DebouncedEvent::Write(path = {:?}", pathbuf); }; let new_hash: EnvelopeHash = get_file_hash(pathbuf.as_path()); if index_lock.get_mut(&new_hash).is_none() { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("write notice"); + debug!("write notice"); let op = Box::new(MaildirOp::new(new_hash, hash_indexes.clone(), folder_hash)); if let Some(env) = Envelope::from_token(op, new_hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{}\t{}", new_hash, pathbuf.display()); - } + debug!("{}\t{:?}", new_hash, &pathbuf); + debug!("hash {}, path: {:?} couldn't be parsed in `add_path_to_index`", new_hash, &pathbuf); index_lock.insert(new_hash, pathbuf); /* Send Write notice */ @@ -276,17 +259,13 @@ eprintln!("{}\t{}", new_hash, pathbuf.display()); hash: folder_hash, kind: Update(old_hash, Box::new(env)), }); - } else if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display()); } } } /* Remove */ DebouncedEvent::NoticeRemove(pathbuf) | DebouncedEvent::Remove(pathbuf) => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DebouncedEvent::Remove(path = {:?}", pathbuf); + debug!("DebouncedEvent::Remove(path = {:?}", pathbuf); let folder_hash = get_path_hash!(pathbuf); let mut hash_indexes_lock = hash_indexes.lock().unwrap(); let index_lock = hash_indexes_lock.entry(folder_hash).or_default(); @@ -295,8 +274,7 @@ eprintln!("DebouncedEvent::Remove(path = {:?}", pathbuf); { *k } else { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("removed but not contained in index"); + debug!("removed but not contained in index"); continue; }; index_lock.remove(&hash); @@ -308,10 +286,7 @@ eprintln!("removed but not contained in index"); } /* Envelope hasn't changed */ DebouncedEvent::Rename(src, dest) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("DebouncedEvent::Rename(src = {:?}, dest = {:?})", src, dest); - } + debug!("DebouncedEvent::Rename(src = {:?}, dest = {:?})", src, dest); let folder_hash = get_path_hash!(src); let old_hash: EnvelopeHash = get_file_hash(src.as_path()); let new_hash: EnvelopeHash = get_file_hash(dest.as_path()); @@ -320,10 +295,7 @@ eprintln!("removed but not contained in index"); let index_lock = hash_indexes_lock.entry(folder_hash).or_default(); if index_lock.contains_key(&old_hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("contains_old_key"); - } + debug!("contains_old_key"); sender.send(RefreshEvent { hash: get_path_hash!(dest), kind: Rename(old_hash, new_hash), @@ -332,19 +304,13 @@ eprintln!("removed but not contained in index"); index_lock.insert(new_hash, dest); continue; } else if !index_lock.contains_key(&new_hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("not contains_new_key"); - } + debug!("not contains_new_key"); let file_name = dest .as_path() .strip_prefix(&root_path) .unwrap() .to_path_buf(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("filename = {:?}", file_name); - } + debug!("filename = {:?}", file_name); if let Some(env) = add_path_to_index( &hash_indexes, folder_hash, @@ -352,30 +318,21 @@ eprintln!("removed but not contained in index"); &cache_dir, file_name, ) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("Create event {} {} {}", env.hash(), env.subject(), dest.display()); - } + debug!("Create event {} {} {}", env.hash(), env.subject(), dest.display()); sender.send(RefreshEvent { hash: folder_hash, kind: Create(Box::new(env)), }); continue; } else { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("not valid email"); - } + debug!("not valid email"); } } else { sender.send(RefreshEvent { hash: get_path_hash!(dest), kind: Rename(old_hash, new_hash), }); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("contains_new_key"); - } + debug!("contains_new_key"); } /* Maybe a re-read should be triggered here just to be safe. @@ -393,10 +350,7 @@ eprintln!("removed but not contained in index"); _ => {} }, Err(e) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("watch error: {:?}", e) - } + debug!("watch error: {:?}", e) } } } @@ -436,10 +390,7 @@ eprintln!("removed but not contained in index"); hostn_buf.trim() )); } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("saving at {}", path.display()); - } + debug!("saving at {}", path.display()); let file = fs::File::create(path).unwrap(); let mut writer = io::BufWriter::new(file); writer.write_all(bytes).unwrap(); @@ -672,10 +623,7 @@ impl MaildirType { } local_r.push(e); } else { - if cfg!(debug_assertions) { -eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, file.as_path().display()); -} + debug!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, file.as_path().display()); continue; } } @@ -710,15 +658,13 @@ fn add_path_to_index( file_name: PathBuf, ) -> Option<Envelope> { let env: Envelope; - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("add_path_to_index path {:?} filename{:?}", path, file_name); + debug!("add_path_to_index path {:?} filename{:?}", path, file_name); let hash = get_file_hash(path); { let mut map = hash_index.lock().unwrap(); let map = map.entry(folder_hash).or_default();; map.insert(hash, path.to_path_buf()); - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "inserted {} in {} map, len={}", hash, folder_hash, @@ -727,11 +673,9 @@ fn add_path_to_index( } let op = Box::new(MaildirOp::new(hash, hash_index.clone(), folder_hash)); if let Some(e) = Envelope::from_token(op, hash) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("add_path_to_index gen {}\t{}", hash, file_name.display()); + debug!("add_path_to_index gen {}\t{}", hash, file_name.display()); if let Ok(cached) = cache_dir.place_cache_file(file_name) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("putting in cache"); + debug!("putting in cache"); /* place result in cache directory */ let f = match fs::File::create(cached) { Ok(f) => f, @@ -744,8 +688,7 @@ fn add_path_to_index( } env = e; } else { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, path.display() diff --git a/melib/src/mailbox/collection.rs b/melib/src/mailbox/collection.rs index 7a7f2e33..4dd3ebc0 100644 --- a/melib/src/mailbox/collection.rs +++ b/melib/src/mailbox/collection.rs @@ -52,27 +52,24 @@ impl Collection { let threads = Threads::new(&mut envelopes); /*let cache_dir = - xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash())) - .unwrap(); - if let Some(cached) = cache_dir.find_cache_file("threads") { - let reader = io::BufReader::new(fs::File::open(cached).unwrap()); - let result: result::Result<Threads, _> = bincode::deserialize_from(reader); - let ret = if let Ok(mut cached_t) = result { - use std::iter::FromIterator; - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -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; + debug!("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(), @@ -92,10 +89,7 @@ eprintln!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", Fnv } pub fn remove(&mut self, envelope_hash: EnvelopeHash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: Removing {}", envelope_hash); - } + debug!("DEBUG: Removing {}", envelope_hash); self.envelopes.remove(&envelope_hash); self.threads.remove(envelope_hash, &mut self.envelopes); } @@ -145,10 +139,7 @@ eprintln!("DEBUG: Removing {}", envelope_hash); pub fn insert(&mut self, envelope: Envelope) { let hash = envelope.hash(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: Inserting hash {} in {}", hash, self.folder.name()); - } + debug!("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 { @@ -158,13 +149,10 @@ eprintln!("DEBUG: Inserting hash {} in {}", hash, self.folder.name()); pub(crate) fn insert_reply(&mut self, _envelope: &Envelope) { return; /* - //self.insert(envelope); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("insert_reply in collections"); - } - self.threads.insert_reply(envelope, &mut self.envelopes); - */ + //self.insert(envelope); + debug!("insert_reply in collections"); + self.threads.insert_reply(envelope, &mut self.envelopes); + */ } } diff --git a/melib/src/mailbox/email.rs b/melib/src/mailbox/email.rs index ce7a96b7..9152dcf6 100644 --- a/melib/src/mailbox/email.rs +++ b/melib/src/mailbox/email.rs @@ -394,10 +394,7 @@ impl Envelope { let (headers, _) = match parser::mail(bytes).to_full_result() { Ok(v) => v, Err(e) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("error in parsing mail\n{:?}\n", e); - } + debug!("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)); } @@ -550,10 +547,7 @@ eprintln!("error in parsing mail\n{:?}\n", e); let (headers, body) = match parser::mail(bytes).to_full_result() { Ok(v) => v, Err(_) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("error in parsing mail\n"); - } + debug!("error in parsing mail\n"); let error_msg = b"Mail cannot be shown because of errors."; let builder = AttachmentBuilder::new(error_msg); return builder.build(); @@ -584,36 +578,32 @@ eprintln!("error in parsing mail\n"); }) } pub fn body(&self, mut operation: Box<BackendOp>) -> Attachment { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("searching body for {:?}", self.message_id_display()); + debug!("searching body for {:?}", self.message_id_display()); 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(_) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("2error in parsing mail\n"); + let (headers, body) = match parser::mail(file.unwrap()).to_full_result() { + Ok(v) => v, + Err(_) => { + debug!("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 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() - */ + builder.build() + */ } pub fn subject(&self) -> Cow<str> { match self.subject { diff --git a/melib/src/mailbox/email/attachment_types.rs b/melib/src/mailbox/email/attachment_types.rs index 05b486cd..3a8b8e8c 100644 --- a/melib/src/mailbox/email/attachment_types.rs +++ b/melib/src/mailbox/email/attachment_types.rs @@ -68,10 +68,7 @@ impl<'a> From<&'a [u8]> for Charset { b"BIG5" | b"big5" => Charset::BIG5, b"ISO-2022-JP" | b"iso-2022-JP" => Charset::ISO2022JP, _ => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("unknown tag is {:?}", str::from_utf8(b)); - } + debug!("unknown tag is {:?}", str::from_utf8(b)); Charset::Ascii } } diff --git a/melib/src/mailbox/email/attachments.rs b/melib/src/mailbox/email/attachments.rs index 3f4877d4..5dd7c28f 100644 --- a/melib/src/mailbox/email/attachments.rs +++ b/melib/src/mailbox/email/attachments.rs @@ -143,10 +143,7 @@ impl AttachmentBuilder { } } Err(v) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("parsing error in content_type: {:?} {:?}", value, v); - } + debug!("parsing error in content_type: {:?} {:?}", value, v); } } self @@ -212,22 +209,10 @@ eprintln!("parsing error in content_type: {:?} {:?}", value, v); let (headers, body) = match parser::attachment(&a).to_full_result() { Ok(v) => v, Err(_) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("error in parsing attachment"); - } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("\n-------------------------------"); - } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{}\n", ::std::string::String::from_utf8_lossy(a)); - } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("-------------------------------\n"); - } + debug!("error in parsing attachment"); + debug!("\n-------------------------------"); + debug!("{}\n", ::std::string::String::from_utf8_lossy(a)); + debug!("-------------------------------\n"); continue; } @@ -250,8 +235,7 @@ eprintln!("-------------------------------\n"); vec } a => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!( + debug!( "error {:?}\n\traw: {:?}\n\tboundary: {:?}", a, str::from_utf8(raw).unwrap(), @@ -400,24 +384,18 @@ fn decode_rfc822(_raw: &[u8]) -> Attachment { builder.build() /* - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("raw is\n{:?}", str::from_utf8(raw).unwrap()); - } - let e = match Envelope::from_bytes(raw) { - Some(e) => e, - None => { - if cfg!(debug_assertions) { - eprint!( |