#[non_exhaustive]pub struct EmailAddress {
pub name: Option<String>,
pub address: Option<String>,
}Expand description
A single RFC 5322 mailbox parsed from an address-list.
Mirrors the JMAP EmailAddress object defined in RFC 8621 §4.1.2.3.
name is the optional display name. address is the addr-spec. Both
are populated best-effort; either may be None if the original header
is malformed.
§Equality semantics
The derived PartialEq/Eq/Hash is byte-exact on both fields. In
particular, address comparison is case-sensitive across the entire
addr-spec, even though RFC 5321 §2.4 defines the domain part of an
addr-spec as case-insensitive — so alice@example.com and
alice@EXAMPLE.COM compare as not equal and hash differently. Callers
that need RFC-5321-conformant equality (HashSet dedup of recipient
lists, etc.) MUST canonicalise the domain part themselves before
comparing or hashing.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: Option<String>Display name from the mailbox, RFC 2047 encoded-words already
decoded.
Parser-produced values are RFC 8621 §4.1.2.3 normalised:
surrounding ASCII whitespace is trimmed from the decoded
display name. A name that is empty after trimming is mapped to
None (a lone empty quoted-string never surfaces as
Some(String::new())).
address: Option<String>addr-spec of the mailbox.
Implementations§
Source§impl EmailAddress
impl EmailAddress
Sourcepub fn new(name: Option<String>, address: Option<String>) -> Self
pub fn new(name: Option<String>, address: Option<String>) -> Self
Construct an EmailAddress from optional display name and
addr-spec.
EmailAddress is #[non_exhaustive] so external callers cannot
use struct expression syntax. Use this constructor — or
Default::default() followed by field assignment — instead.
Sourcepub fn is_addressable(&self) -> bool
pub fn is_addressable(&self) -> bool
Whether this EmailAddress carries an addr-spec.
parse_header_typed produces EmailAddress values with
address == None for malformed mailboxes (most commonly,
display-name-only mailboxes from non-spec-conformant clients —
e.g. a draft saved with just a typed-but-incomplete To:).
Such entries are unusable for sending mail, address comparison,
or addr-spec-keyed lookup.
Use this helper to filter parsed address lists down to the usable subset:
use mime_tree::EmailAddress;
let parsed = vec![
EmailAddress::new(
Some("Alice".to_owned()),
Some("alice@example.com".to_owned()),
),
EmailAddress::new(Some("Display-Name Only".to_owned()), None),
];
let usable: Vec<EmailAddress> = parsed
.into_iter()
.filter(EmailAddress::is_addressable)
.collect();
assert_eq!(usable.len(), 1);
assert_eq!(usable[0].address.as_deref(), Some("alice@example.com"));Trait Implementations§
Source§impl Clone for EmailAddress
impl Clone for EmailAddress
Source§fn clone(&self) -> EmailAddress
fn clone(&self) -> EmailAddress
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EmailAddress
impl Debug for EmailAddress
Source§impl Default for EmailAddress
impl Default for EmailAddress
Source§fn default() -> EmailAddress
fn default() -> EmailAddress
Source§impl<'de> Deserialize<'de> for EmailAddress
impl<'de> Deserialize<'de> for EmailAddress
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for EmailAddress
impl Display for EmailAddress
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Render in RFC 5322 §3.4 mailbox-ish form.
- Both
nameandaddresspresent:Display Name <addr@host>. addressonly:addr@host(bare addr-spec, no angle brackets).nameonly:Display Name(degenerate; not a valid RFC 5322 mailbox, but the best a Display impl can do).- Neither present: the empty string.
Names are emitted verbatim. This Display impl prioritises human
readability over RFC 5322 round-trippability — names containing
<, >, ,, or other RFC 5322 specials are not quoted. Callers
that need byte-stable round-trip into a header field MUST roll
their own serializer with proper quoting.
impl Eq for EmailAddress
Source§impl Hash for EmailAddress
impl Hash for EmailAddress
Source§impl PartialEq for EmailAddress
impl PartialEq for EmailAddress
Source§fn eq(&self, other: &EmailAddress) -> bool
fn eq(&self, other: &EmailAddress) -> bool
self and other values to be equal, and is used by ==.