1 #ifndef MAILBOX_DOT_HPP
2 #define MAILBOX_DOT_HPP
13 Mailbox(std::string_view mailbox
);
14 Mailbox(std::string_view local_part
, std::string_view domain
)
16 set_local(local_part
);
19 Mailbox(std::string_view local_part
, Domain domain
)
21 set_local(local_part
);
25 void set_local(std::string_view local_part
) { local_part_
= local_part
; }
26 void set_domain(std::string_view d
) { domain_
.set(d
); }
27 void set_domain(Domain d
) { domain_
= d
; }
33 std::string
const& local_part() const { return local_part_
; }
34 Domain
const& domain() const { return domain_
; }
36 enum class domain_encoding
: bool { ascii
, utf8
};
38 size_t length(domain_encoding enc
= domain_encoding::utf8
) const;
40 bool empty() const { return length() == 0; }
42 std::string
as_string(domain_encoding enc
= domain_encoding::utf8
) const;
44 operator std::string() const { return as_string(domain_encoding::utf8
); }
46 bool operator==(Mailbox
const& rhs
) const
48 return (local_part_
== rhs
.local_part_
) && (domain_
== rhs
.domain_
);
50 bool operator!=(Mailbox
const& rhs
) const { return !(*this == rhs
); }
52 enum class local_types
: uint8_t {
58 enum class domain_types
: uint8_t {
64 struct parse_results
{
65 std::string_view local
;
66 std::string_view domain
;
67 local_types local_type
= local_types::unknown
;
68 domain_types domain_type
= domain_types::unknown
;
71 static std::optional
<parse_results
> parse(std::string_view mailbox
);
73 static bool validate(std::string_view mailbox
);
74 static bool validate_strict_lengths(std::string_view mailbox
);
77 std::string local_part_
;
81 inline std::ostream
& operator<<(std::ostream
& s
, Mailbox
const& mb
)
83 return s
<< static_cast<std::string
>(mb
);
86 #endif // MAILBOX_DOT_HPP