Enum melib::email::address::Address

source ·
pub enum Address {
    Mailbox(MailboxAddress),
    Group(GroupAddress),
}
Expand description

An email address.

Conforms to RFC5322 - Internet Message Format.

§Creating an Address

You can directly create an address with Address::new,

let addr = Address::new(
    Some("Jörg Doe".to_string()),
    "joerg@example.com".to_string(),
);
assert_eq!(addr.to_string().as_str(), "Jörg Doe <joerg@example.com>");

or parse it from a raw value:

let (rest_bytes, addr) = melib::email::parser::address::address(
    "=?utf-8?q?J=C3=B6rg_Doe?= <joerg@example.com>".as_bytes(),
)
.unwrap();
assert!(rest_bytes.is_empty());
assert_eq!(addr.get_display_name(), Some("Jörg Doe".to_string()));
assert_eq!(addr.get_email(), "joerg@example.com".to_string());

Variants§

Implementations§

source§

impl Address

source

pub fn new(display_name: Option<String>, address: String) -> Self

source

pub fn new_group(display_name: String, mailbox_list: Vec<Self>) -> Self

source

pub fn raw(&self) -> &[u8]

source

pub fn get_display_name(&self) -> Option<String>

Get the display name of this address.

If it’s a group, it’s the name of the group. Otherwise it’s the display_name part of the mailbox:

          raw                         raw
┌──────────┴────────────┐   ┌──────────┴────────────────────┐
Name <address@domain.tld>   "Name Name2" <address@domain.tld>
└─┬┘  └──────────┬─────┘     └─────┬──┘   └──────────┬─────┘
display_name     │          display_name             │
                 │                                   │
           address_spec                        address_spec
source

pub fn get_email(&self) -> String

Get the address spec part of this address. A group returns an empty String.

source

pub fn address_spec_raw(&self) -> &[u8]

source

pub fn get_fqdn(&self) -> Option<String>

source

pub fn get_tags(&self, separator: char) -> Vec<String>

source

pub fn list_try_from<T: AsRef<[u8]>>(val: T) -> Result<Vec<Self>>

source

pub fn contains_address(&self, other: &Self) -> bool

source

pub fn subaddress(&self, separator: &str) -> Option<(Self, String)>

Get subaddress out of an address (e.g. ken+subaddress@example.org).

Subaddresses are commonly text following a “+” character in an email address’s local part . They are defined in RFC5233 Sieve Email Filtering: Subaddress Extension

§Examples
let addr = "ken+sieve@example.org";
let (rest, val) = melib::email::parser::address::address(addr.as_bytes()).unwrap();
assert!(rest.is_empty());
assert_eq!(
    val.subaddress("+"),
    Some((
        Address::new(None, "ken@example.org".to_string()),
        "sieve".to_string()
    ))
);
source

pub fn display_name_bytes(&self) -> &[u8]

Get the display name of this address in bytes.

For a string, see the display_name method.

source

pub fn display(&self) -> UIAddress<'_>

Returns a type that prints addresses suitably for UI display, e.g. without quotes.

§Example
let addr = Address::new(
    Some("Jörg T. Doe".to_string()),
    "joerg@example.com".to_string(),
);
assert_eq!(
    addr.to_string().as_str(),
    r#""Jörg T. Doe" <joerg@example.com>"#
);
assert_eq!(
    addr.display().to_string().as_str(),
    "Jörg T. Doe <joerg@example.com>"
);
source

pub fn display_name(&self) -> UINameAddress<'_>

Returns a type that prints the names of addresses (or the e-mail part, if the name is missing) suitably for UI display, e.g. without quotes.

§Example
let addr = Address::new(
    Some("Jörg T. Doe".to_string()),
    "joerg@example.com".to_string(),
);
assert_eq!(
    addr.to_string().as_str(),
    r#""Jörg T. Doe" <joerg@example.com>"#
);
assert_eq!(addr.display_name().to_string().as_str(), "Jörg T. Doe");
source

pub fn display_slice(slice: &[Self]) -> String

Formats a slice of Addresses with their Address::display method, separated by comma or separator if passed.

source

pub fn display_name_slice(slice: &[Self]) -> String

Formats a slice of Addresses with their Address::display_name method, separated by comma or separator if passed.

Trait Implementations§

source§

impl Clone for Address

source§

fn clone(&self) -> Address

Returns a copy 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 Hash for Address

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 Address

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 TryFrom<&str> for Address

§

type Error = Error

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

fn try_from(val: &str) -> Result<Self>

Performs the conversion.
source§

impl Eq 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,

§

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§

default 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>,

§

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>,

§

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>,