00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __OASYS_SMTP_H__
00018 #define __OASYS_SMTP_H__
00019
00020 #include "../debug/Logger.h"
00021 #include "../io/BufferedIO.h"
00022 #include "../io/NetUtils.h"
00023
00024 namespace oasys {
00025
00026 class BasicSMTPMsg;
00027 class SMTPHandler;
00028 class SMTPSender;
00029
00030
00034 class SMTP : public Logger {
00035 public:
00036 struct Config {
00038 Config()
00039 : addr_(htonl(INADDR_LOOPBACK)),
00040 port_(25),
00041 timeout_(-1),
00042 domain_("default.domain.com") {}
00043
00045 Config(in_addr_t addr, u_int16_t port,
00046 int timeout, const std::string& domain)
00047 : addr_(addr), port_(port),
00048 timeout_(timeout),
00049 domain_(domain) {}
00050
00051 in_addr_t addr_;
00052 u_int16_t port_;
00053 int timeout_;
00054 std::string domain_;
00055 };
00056
00057 static Config DEFAULT_CONFIG;
00058
00059 SMTP(BufferedInput* in,
00060 BufferedOutput* out,
00061 const Config& config,
00062 const char* logpath);
00063
00064 int client_session(SMTPSender* sender, bool first_session);
00065 int server_session(SMTPHandler* handler);
00066
00067 private:
00068 static const char* nl_;
00069
00070 BufferedInput* in_;
00071 BufferedOutput* out_;
00072 Config config_;
00073
00075 int send_signon();
00076
00078 int process_cmd(SMTPHandler* handler);
00079
00081 int process_response(int expected_code);
00082
00084 int send_response(int code);
00085
00087 const char* response_code(int code) const;
00088 };
00089
00090
00095 class SMTPSender {
00096 public:
00097 virtual ~SMTPSender() {}
00098
00101 virtual void get_HELO_domain(std::string* domain) = 0;
00102 virtual void get_MAIL_from(std::string* from) = 0;
00103 virtual void get_RCPT_list(std::vector<std::string>* to) = 0;
00104 virtual void get_RECEIVED(std::string* received) {(void)received;}
00105 virtual void get_DATA(const std::string** data) = 0;
00107
00109 virtual int smtp_error(int code) = 0;
00110 };
00111
00112
00116 class SMTPHandler {
00117 public:
00118 virtual ~SMTPHandler() {}
00119
00122 virtual int smtp_HELO(const char* domain) = 0;
00123 virtual int smtp_MAIL(const char* from) = 0;
00124 virtual int smtp_RCPT(const char* to) = 0;
00125 virtual int smtp_RSET() = 0;
00126 virtual int smtp_QUIT() = 0;
00128
00130
00135 virtual int smtp_DATA_begin() = 0;
00136 virtual int smtp_DATA_line(const char* line) = 0;
00137 virtual int smtp_DATA_end() = 0;
00139 };
00140
00141 }
00142
00143 #endif