BasicSMTP.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _OASYS_BASIC_SMTP_H_
00018 #define _OASYS_BASIC_SMTP_H_
00019 
00020 #include "SMTP.h"
00021 #include "util/StringUtils.h"
00022 
00023 namespace oasys {
00024 
00025 //----------------------------------------------------------------------------
00029 class BasicSMTPMsg {
00030 public:
00031     std::string              from_;
00032     std::vector<std::string> to_;
00033     std::string              msg_;
00034 
00035     BasicSMTPMsg() {}
00036     BasicSMTPMsg(const std::string& from,
00037                  const std::string& to,
00038                  const std::string& msg)
00039     {
00040         from_ = from;
00041         tokenize(to, ", ", &to_);
00042         msg_  = msg;
00043     }
00044     
00045     bool valid() {
00046         return (from_.size() > 0 &&
00047                 to_.size()   > 0 &&
00048                 msg_.size()  > 0);
00049     }
00050     
00051     void clear() {
00052         from_.clear();
00053         to_.clear();
00054         msg_.clear();
00055     }
00056 };
00057 
00058 //----------------------------------------------------------------------------
00063 class BasicSMTPSender : public SMTPSender {
00064 public:
00065     BasicSMTPSender(const std::string& helo_domain, BasicSMTPMsg* msg);
00066     virtual ~BasicSMTPSender() {}
00067     
00068 protected:
00070     void get_HELO_domain(std::string* domain);
00071     void get_MAIL_from(std::string* from);
00072     void get_RCPT_list(std::vector<std::string>* to);
00073     void get_DATA(const std::string** data);
00074     int smtp_error(int code);
00076 
00077     std::string   helo_domain_;
00078     BasicSMTPMsg* msg_;
00079 };
00080 
00081 //----------------------------------------------------------------------------
00085 class BasicSMTPHandler : public SMTPHandler {
00086 public:
00087     BasicSMTPHandler();
00088 
00090     int smtp_HELO(const char* domain);
00091     int smtp_MAIL(const char* from);
00092     int smtp_RCPT(const char* to);
00093     int smtp_DATA_begin();
00094     int smtp_DATA_line(const char* line);
00095     int smtp_DATA_end();
00096     int smtp_RSET();
00097     int smtp_QUIT();
00099 
00100     virtual void message_recvd(const BasicSMTPMsg& msg) = 0;
00101 
00102 private:
00104     BasicSMTPMsg cur_msg_;
00105 };
00106 
00107 } // namespace oasys 
00108 
00109 #endif /* _OASYS_BASIC_SMTP_H_ */

Generated on Thu Jun 7 12:54:25 2007 for DTN Reference Implementation by  doxygen 1.5.1