better with obs forms
[ghsmtp.git] / jnk / Send.hpp
bloba7d792d78fcca89079a84067126b851bb41b7c05
1 #ifndef SEND_DOT_HPP
2 #define SEND_DOT_HPP
4 #include "DNS.hpp"
5 #include "Mailbox.hpp"
6 #include "Sock.hpp"
7 #include "fs.hpp"
9 namespace SMTP {
10 struct Connection {
11 Connection(int fd_in, int fd_out, std::function<void(void)> read_hook)
12 : sock(fd_in,
13 fd_out,
14 read_hook,
15 std::chrono::minutes(2),
16 std::chrono::minutes(2))
20 Sock sock;
22 std::string server_id;
24 Mailbox mail_from;
25 std::vector<Mailbox> rcpt_to;
27 std::string ehlo_keyword;
28 std::vector<std::string> ehlo_param;
29 std::unordered_map<std::string, std::vector<std::string>> ehlo_params;
31 std::string reply_code;
33 bool greeting_ok{false};
34 bool ehlo_ok{false};
35 bool active{false}; // At least one rcp_to for this MX
37 bool has_extension(char const* name) const
39 return ehlo_params.find(name) != ehlo_params.end();
42 } // namespace SMTP
44 class Send {
45 public:
46 Send(fs::path config_path, char const* service);
48 void set_sender(Domain sender) { sender_ = sender; }
50 bool mail_from(Mailbox const& from);
51 bool rcpt_to(DNS::Resolver& res, Mailbox const& to, std::string& error_msg);
53 bool send(std::string_view msg);
55 void rset();
56 void quit();
58 private:
59 fs::path config_path_;
60 std::string service_;
62 Domain sender_;
64 Mailbox mail_from_;
65 std::vector<Mailbox> rcpt_to_;
67 // MX hostname or address => connection
68 std::unordered_map<Domain, std::unique_ptr<SMTP::Connection>> exchangers_;
70 // @domain => MX hostname or address
71 std::unordered_map<Domain, Domain> receivers_;
74 #endif // SEND_DOT_HPP