1 #ifndef MAILBOX_DOT_HPP
2 #define MAILBOX_DOT_HPP
14 Mailbox(std::string_view mailbox
);
15 Mailbox(std::string_view local_part
, std::string_view domain
)
17 set_local(local_part
);
20 Mailbox(std::string_view local_part
, Domain domain
)
22 set_local(local_part
);
26 void set_local(std::string_view local_part
) { local_part_
= local_part
; }
27 void set_domain(std::string_view d
) { domain_
.set(d
); }
28 void set_domain(Domain d
) { domain_
= d
; }
34 std::string
const& local_part() const { return local_part_
; }
35 Domain
const& domain() const { return domain_
; }
37 enum class domain_encoding
: bool { ascii
, utf8
};
39 size_t length(domain_encoding enc
= domain_encoding::utf8
) const;
41 bool empty() const { return length() == 0; }
43 std::string
as_string(domain_encoding enc
= domain_encoding::utf8
) const;
45 operator std::string() const { return as_string(domain_encoding::utf8
); }
47 bool operator==(Mailbox
const& rhs
) const
49 return (local_part_
== rhs
.local_part_
) && (domain_
== rhs
.domain_
);
51 bool operator!=(Mailbox
const& rhs
) const { return !(*this == rhs
); }
53 enum class local_types
: uint8_t {
59 enum class domain_types
: uint8_t {
65 struct parse_results
{
66 std::string_view local
;
67 std::string_view domain
;
68 local_types local_type
= local_types::unknown
;
69 domain_types domain_type
= domain_types::unknown
;
72 static std::optional
<parse_results
> parse(std::string_view mailbox
);
74 static bool validate(std::string_view mailbox
);
75 static bool validate_strict_lengths(std::string_view mailbox
);
78 std::string local_part_
;
82 inline std::ostream
& operator<<(std::ostream
& s
, Mailbox
const& mb
)
84 return s
<< static_cast<std::string
>(mb
);
87 #endif // MAILBOX_DOT_HPP