1 #ifndef MAILBOX_DOT_HPP
2 #define MAILBOX_DOT_HPP
15 Mailbox(std::string_view mailbox
);
16 Mailbox(std::string_view local_part
, std::string_view domain
)
18 set_local(local_part
);
21 Mailbox(std::string_view local_part
, Domain domain
)
23 set_local(local_part
);
27 void set_local(std::string_view local_part
) { local_part_
= local_part
; }
28 void set_domain(std::string_view d
) { domain_
.set(d
); }
29 void set_domain(Domain d
) { domain_
= d
; }
35 std::string
const& local_part() const { return local_part_
; }
36 Domain
const& domain() const { return domain_
; }
38 enum class domain_encoding
: bool { ascii
, utf8
};
40 size_t length(domain_encoding enc
= domain_encoding::utf8
) const;
42 bool empty() const { return length() == 0; }
44 std::string
as_string(domain_encoding enc
= domain_encoding::utf8
) const;
46 operator std::string() const { return as_string(domain_encoding::utf8
); }
48 bool operator==(Mailbox
const& rhs
) const
50 return (local_part_
== rhs
.local_part_
) && (domain_
== rhs
.domain_
);
52 bool operator!=(Mailbox
const& rhs
) const { return !(*this == rhs
); }
54 enum class local_types
: uint8_t {
60 enum class domain_types
: uint8_t {
66 struct parse_results
{
67 std::string_view local
;
68 std::string_view domain
;
69 local_types local_type
= local_types::unknown
;
70 domain_types domain_type
= domain_types::unknown
;
73 static std::optional
<parse_results
> parse(std::string_view mailbox
);
75 static bool validate(std::string_view mailbox
)
87 std::string local_part_
;
91 inline std::ostream
& operator<<(std::ostream
& s
, Mailbox
const& mb
)
93 return s
<< static_cast<std::string
>(mb
);
96 #endif // MAILBOX_DOT_HPP