-
Notifications
You must be signed in to change notification settings - Fork 3
/
Send.hpp
66 lines (49 loc) · 1.4 KB
/
Send.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef SEND_DOT_HPP
#define SEND_DOT_HPP
#include "DNS.hpp"
#include "Mailbox.hpp"
#include "Sock.hpp"
#include "fs.hpp"
namespace SMTP {
struct Connection {
Connection(int fd_in, int fd_out, std::function<void(void)> read_hook)
: sock(fd_in,
fd_out,
read_hook,
std::chrono::minutes(2),
std::chrono::minutes(2))
{
}
Sock sock;
std::string server_id;
std::string ehlo_keyword;
std::vector<std::string> ehlo_param;
std::unordered_map<std::string, std::vector<std::string>> ehlo_params;
std::string reply_code;
bool greeting_ok{false};
bool ehlo_ok{false};
bool active{false}; // At least one rcp_to for this MX
bool has_extension(char const* name) const
{
return ehlo_params.find(name) != ehlo_params.end();
}
};
} // namespace SMTP
class Send {
public:
Send(fs::path config_path, char const* service);
void set_sender(Domain sender) { sender_ = sender; }
bool mail_from_rcpt_to(DNS::Resolver& res,
Mailbox const& from,
Mailbox const& to,
std::string& error_msg);
bool send(std::string_view msg);
void rset();
void quit();
private:
fs::path config_path_;
std::string service_;
Domain sender_;
std::unique_ptr<SMTP::Connection> conn_;
};
#endif // SEND_DOT_HPP