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§
Mailbox(MailboxAddress)
Group(GroupAddress)
Implementations§
source§impl Address
impl Address
pub fn new(display_name: Option<String>, address: String) -> Self
pub fn new_group(display_name: String, mailbox_list: Vec<Self>) -> Self
pub fn raw(&self) -> &[u8] ⓘ
sourcepub fn get_display_name(&self) -> Option<String>
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
sourcepub fn get_email(&self) -> String
pub fn get_email(&self) -> String
Get the address spec part of this address. A group returns an empty
String
.
pub fn address_spec_raw(&self) -> &[u8] ⓘ
pub fn get_fqdn(&self) -> Option<String>
pub fn list_try_from<T: AsRef<[u8]>>(val: T) -> Result<Vec<Self>>
pub fn contains_address(&self, other: &Self) -> bool
sourcepub fn subaddress(&self, separator: &str) -> Option<(Self, String)>
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()
))
);
sourcepub fn display_name_bytes(&self) -> &[u8] ⓘ
pub fn display_name_bytes(&self) -> &[u8] ⓘ
Get the display name of this address in bytes.
For a string, see the display_name
method.
sourcepub fn display(&self) -> UIAddress<'_>
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>"
);
sourcepub fn display_name(&self) -> UINameAddress<'_>
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");
sourcepub fn display_slice(slice: &[Self]) -> String
pub fn display_slice(slice: &[Self]) -> String
Formats a slice of Address
es with their Address::display
method,
separated by comma or separator
if passed.
sourcepub fn display_name_slice(slice: &[Self]) -> String
pub fn display_name_slice(slice: &[Self]) -> String
Formats a slice of Address
es with their Address::display_name
method, separated by comma or separator
if passed.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Address
impl<'de> Deserialize<'de> for Address
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 PartialEq for Address
impl PartialEq for Address
impl Eq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnwindSafe for Address
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.