From 5f449714f58557f50d3ade8ab63f267d89ad8b36 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sun, 23 Jul 2023 19:14:42 +0200 Subject: [PATCH] add debug logic for MessageID --- src/rfc5322/identification.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/rfc5322/identification.rs b/src/rfc5322/identification.rs index 5d71f45..d6e510a 100644 --- a/src/rfc5322/identification.rs +++ b/src/rfc5322/identification.rs @@ -1,3 +1,4 @@ +use std::fmt; use nom::{ branch::alt, bytes::complete::{tag, take_while}, @@ -11,13 +12,24 @@ use crate::rfc5322::mailbox::is_dtext; use crate::text::whitespace::cfws; use crate::text::words::dot_atom_text; -#[derive(Debug, PartialEq, Clone)] +#[derive(PartialEq, Clone)] pub struct MessageID<'a> { pub left: &'a [u8], pub right: &'a [u8], } +impl<'a> ToString for MessageID<'a> { + fn to_string(&self) -> String { + format!("{}@{}", String::from_utf8_lossy(self.left), String::from_utf8_lossy(self.right)) + } +} +impl<'a> fmt::Debug for MessageID<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_tuple("MessageID").field(&format_args!("\"{}\"", self.to_string())).finish() + } +} pub type MessageIDList<'a> = Vec>; + /// Message identifier /// /// ```abnf