Botan 3.13.0
Crypto and TLS for C&
Botan::EmailAddress Class Referencefinal

#include <email.h>

Public Member Functions

const DNSNamedomain () const
const std::string & local_part () const
 The local-part, ASCII only.
auto operator<=> (const EmailAddress &) const =default
bool operator== (const EmailAddress &) const =default
std::string to_string () const

Static Public Member Functions

static std::optional< EmailAddress > from_string (std::string_view addr)

Detailed Description

A parsed email address in mailbox form: "local-part@domain".

This is specifically modeling RFC 5280's rfc822Name GeneralName type. In this type, the local-part of the email address must be an ASCII subset.

This type and SmtpUTF8Mailbox are very similar in that both express mailbox names. However they are modeled as distinct and unrelated types, as certain name constraint processing rules are applied differently to the two name forms, so it is important that they not be confusable. In addition, by a strict reading of the RFCs, the names expressed by EmailAddress and by SmtpUTF8Mailbox are completely disjoint; EmailAddress as encoded can only express ASCII local-part names, and SmtpUTF8Mailbox is RFC MUST required to be used only for names with a non-ASCII local-part.

Definition at line 33 of file email.h.

Member Function Documentation

◆ domain()

const DNSName & Botan::EmailAddress::domain ( ) const
inline

The domain part of the address

Returns
the domain of the address

Definition at line 47 of file email.h.

47{ return m_domain; }

Referenced by operator==().

◆ from_string()

std::optional< EmailAddress > Botan::EmailAddress::from_string ( std::string_view addr)
static

Parse an rfc822Name mailbox

Parameters
addrthe address to parse
Returns
the parsed address, or nullopt if addr is not a valid rfc822Name

Definition at line 78 of file email.cpp.

78 {
79 auto parsed = parse_email_address(addr);
80
81 if(parsed) {
82 // Verify the local-part is all ASCII
83 for(const char c : parsed->first) {
84 if(static_cast<uint8_t>(c) >= 0x80) {
85 return {};
86 }
87 }
88 return EmailAddress(std::move(parsed->first), std::move(parsed->second));
89 } else {
90 return {};
91 }
92}

Referenced by Botan::AlternativeName::add_email(), Botan::NameConstraints::is_excluded(), Botan::NameConstraints::is_permitted(), and Botan::X509_Certificate::subject_email_addresses().

◆ local_part()

const std::string & Botan::EmailAddress::local_part ( ) const
inline

The local-part, ASCII only.

Definition at line 43 of file email.h.

43{ return m_local_part; }

Referenced by operator==().

◆ operator<=>()

auto Botan::EmailAddress::operator<=> ( const EmailAddress & ) const
default

Order two addresses

Returns
the ordering of this address relative to the other

◆ operator==()

bool Botan::EmailAddress::operator== ( const EmailAddress & ) const
default

Compare two addresses

Returns
true if the two addresses are equal

References domain(), and local_part().

◆ to_string()

std::string Botan::EmailAddress::to_string ( ) const

Format the address as "local-part@domain"

Returns
the text form of the address

Definition at line 73 of file email.cpp.

73 {
74 return fmt("{}@{}", m_local_part, m_domain.to_string());
75}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt().


The documentation for this class was generated from the following files: