Skip to main content

EmailAddress

Struct EmailAddress 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

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.

Source

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

Source§

fn clone(&self) -> EmailAddress

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EmailAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EmailAddress

Source§

fn default() -> EmailAddress

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for EmailAddress

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for EmailAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Render in RFC 5322 §3.4 mailbox-ish form.

  • Both name and address present: Display Name <addr@host>.
  • address only: addr@host (bare addr-spec, no angle brackets).
  • name only: 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.

Source§

impl Eq for EmailAddress

Source§

impl Hash for EmailAddress

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for EmailAddress

Source§

fn eq(&self, other: &EmailAddress) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for EmailAddress

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for EmailAddress

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.