34 string applyPunycodeToDomain(
string const& address) {
36 if (partsOfAddr.size() != 2) {
40 return partsOfAddr[0] +
"@" + partsOfAddr[1];
44struct mail::EmailAddress::Data {
62 data->
address = std::move(address);
65mail::EmailAddress::EmailAddress(std::string name, std::string address) :
EmailAddress() {
67 data->address = std::move(
address);
72 if (includeName && !data->name.empty()) {
73 ret << data->name <<
" ";
75 string address = data->address;
77 address = applyPunycodeToDomain(address);
79 ret << '<' << address << '>
';
83bool mail::EmailAddress::isValid() const {
84 string address = applyPunycodeToDomain(data->address);
85 if (address.empty()) {
88 regex emCheck(R"([a-z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-z0-9.-]+)
", regex::icase);
89 return regex_match(address, emCheck);
92NAWA_COMPLEX_DATA_ACCESSORS_IMPL(mail::EmailAddress, name, string)
94NAWA_COMPLEX_DATA_ACCESSORS_IMPL(mail::EmailAddress, address, string)
Structure representing an email address.
std::string get(bool includeName=true, bool applyPunycode=true) const
std::string & address() noexcept
std::string & name() noexcept
Namespace containing functions for text encoding and decoding.
#define NAWA_MOVE_CONSTRUCTOR_IMPL_WITH_NS(Namespace, Class)
#define NAWA_DEFAULT_CONSTRUCTOR_IMPL_WITH_NS(Namespace, Class)
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_COPY_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_COPY_CONSTRUCTOR_IMPL_WITH_NS(Namespace, Class)
#define NAWA_DEFAULT_DESTRUCTOR_IMPL_WITH_NS(Namespace, Class)
std::string punycodeEncode(std::string const &input)
std::vector< std::string > splitString(std::string str, char delimiter, bool ignoreEmpty=false)
Contains useful functions that improve the readability and facilitate maintenance of the NAWA code.