Address

Struct Address 

Source
pub struct Address {
    pub name: Option<String>,
    pub email: String,
}
Expand description

An email address with an optional display name.

§Examples

use missive::Address;

// From email string
let addr: Address = "user@example.com".into();
assert_eq!(addr.email, "user@example.com");
assert_eq!(addr.name, None);

// From tuple (name, email)
let addr: Address = ("Alice", "alice@example.com").into();
assert_eq!(addr.email, "alice@example.com");
assert_eq!(addr.name, Some("Alice".to_string()));

Fields§

§name: Option<String>

Optional display name (e.g., “Alice Smith”)

§email: String

Email address (e.g., “alice@example.com”)

Implementations§

Source§

impl Address

Source

pub fn new(email: impl Into<String>) -> Self

Create a new address with just an email.

This performs a basic sanity check (non-empty, contains @) and logs a warning if the email looks invalid. For strict validation, use Address::parse instead.

Source

pub fn with_name(name: impl Into<String>, email: impl Into<String>) -> Self

Create a new address with a name and email.

This performs a basic sanity check (non-empty, contains @) and logs a warning if the email looks invalid. For strict validation, use Address::parse_with_name instead.

Source

pub fn name(self, name: impl Into<String>) -> Self

Set the display name.

Source

pub fn parse(email: &str) -> Result<Self, MailError>

Parse and validate an email address.

Uses RFC 5321/5322 compliant validation. Returns an error if the email address is invalid.

§Examples
use missive::Address;

// Valid address
let addr = Address::parse("user@example.com").unwrap();
assert_eq!(addr.email, "user@example.com");

// Invalid address
assert!(Address::parse("not-an-email").is_err());
assert!(Address::parse("").is_err());
Source

pub fn parse_with_name(name: &str, email: &str) -> Result<Self, MailError>

Parse and validate an email address with a display name.

§Examples
use missive::Address;

let addr = Address::parse_with_name("Alice", "alice@example.com").unwrap();
assert_eq!(addr.email, "alice@example.com");
assert_eq!(addr.name, Some("Alice".to_string()));

// Invalid email
assert!(Address::parse_with_name("Alice", "not-valid").is_err());
Source

pub fn to_ascii(&self) -> Result<String, MailError>

Convert the domain part of the email address to ASCII (Punycode).

This is useful for international domain names (IDN) that contain non-ASCII characters. The local part (before @) is preserved as-is.

§Examples
use missive::Address;

// Japanese domain
let addr = Address::new("user@例え.jp");
assert_eq!(addr.to_ascii().unwrap(), "user@xn--r8jz45g.jp");

// Already ASCII domain
let addr = Address::new("user@example.com");
assert_eq!(addr.to_ascii().unwrap(), "user@example.com");
Source

pub fn formatted_ascii(&self) -> Result<String, MailError>

Format with ASCII-encoded domain (Punycode for IDN).

Like formatted() but converts international domain names to ASCII. Use this when sending emails through SMTP or other protocols that require ASCII domain names.

§Examples
use missive::Address;

let addr = Address::with_name("User", "user@例え.jp");
assert_eq!(addr.formatted_ascii().unwrap(), "User <user@xn--r8jz45g.jp>");
Source

pub fn formatted_rfc5322_ascii(&self) -> Result<String, MailError>

Format according to RFC 5322 with ASCII-encoded domain.

Combines RFC 5322 escaping with IDN/Punycode conversion.

Source

pub fn formatted(&self) -> String

Format as “Name ” or just “email” if no name.

For simple names without special characters, returns Name <email>. For names with special chars, use formatted_rfc5322() for proper quoting.

Source

pub fn formatted_rfc5322(&self) -> String

Format according to RFC 5322 with proper escaping.

This method:

  • Escapes backslashes: \\\
  • Escapes double quotes: "\"
  • Wraps the name in double quotes: "Name" <email>

This is the format that should be used in email headers.

Trait Implementations§

Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Address

Source§

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

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

impl<'de> Deserialize<'de> for Address

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 Address

Source§

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

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

impl From<&str> for Address

Source§

fn from(email: &str) -> Self

Converts to this type from the input type.
Source§

impl From<(&str, &str)> for Address

Source§

fn from((name, email): (&str, &str)) -> Self

Converts to this type from the input type.
Source§

impl From<(&str, String)> for Address

Source§

fn from((name, email): (&str, String)) -> Self

Converts to this type from the input type.
Source§

impl From<(String, &str)> for Address

Source§

fn from((name, email): (String, &str)) -> Self

Converts to this type from the input type.
Source§

impl From<(String, String)> for Address

Source§

fn from((name, email): (String, String)) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Address

Source§

fn from(email: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Address

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Address

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 ToAddress for Address

Source§

impl Eq for Address

Source§

impl StructuralPartialEq for Address

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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