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