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 00018 #include "BasicSMTP.h" 00019 00020 namespace oasys { 00021 00022 //---------------------------------------------------------------------------- 00023 BasicSMTPSender::BasicSMTPSender(const std::string& helo_domain, 00024 BasicSMTPMsg* msg) 00025 : helo_domain_(helo_domain), msg_(msg) 00026 { 00027 } 00028 00029 //---------------------------------------------------------------------------- 00030 void 00031 BasicSMTPSender::get_HELO_domain(std::string* domain) 00032 { 00033 domain->assign(helo_domain_); 00034 } 00035 00036 //---------------------------------------------------------------------------- 00037 void 00038 BasicSMTPSender::get_MAIL_from(std::string* from) 00039 { 00040 from->assign(msg_->from_); 00041 } 00042 00043 //---------------------------------------------------------------------------- 00044 void 00045 BasicSMTPSender::get_RCPT_list(std::vector<std::string>* to) 00046 { 00047 to->insert(to->begin(), msg_->to_.begin(), msg_->to_.end()); 00048 } 00049 00050 //---------------------------------------------------------------------------- 00051 void 00052 BasicSMTPSender::get_DATA(const std::string** data) 00053 { 00054 *data = &msg_->msg_; 00055 } 00056 00057 //---------------------------------------------------------------------------- 00058 int 00059 BasicSMTPSender::smtp_error(int code) 00060 { 00061 log_err_p("/oasys/smtp-sender", "unexpected error %d", code); 00062 return -1; 00063 } 00064 00065 //---------------------------------------------------------------------------- 00066 BasicSMTPHandler::BasicSMTPHandler() 00067 { 00068 } 00069 00070 //---------------------------------------------------------------------------- 00071 int 00072 BasicSMTPHandler::smtp_HELO(const char* domain) 00073 { 00074 (void)domain; 00075 return 250; 00076 } 00077 00078 //---------------------------------------------------------------------------- 00079 int 00080 BasicSMTPHandler::smtp_MAIL(const char* from) 00081 { 00082 if (strlen(from) == 0) { 00083 return 501; 00084 } 00085 00086 cur_msg_.from_ = from; 00087 return 250; 00088 } 00089 00090 //---------------------------------------------------------------------------- 00091 int 00092 BasicSMTPHandler::smtp_RCPT(const char* to) 00093 { 00094 if (strlen(to) == 0) { 00095 return 501; 00096 } 00097 00098 cur_msg_.to_.push_back(to); 00099 return 250; 00100 } 00101 00102 //---------------------------------------------------------------------------- 00103 int 00104 BasicSMTPHandler::smtp_RSET() 00105 { 00106 return 250; 00107 } 00108 00109 //---------------------------------------------------------------------------- 00110 int 00111 BasicSMTPHandler::smtp_QUIT() 00112 { 00113 return 221; 00114 } 00115 00116 //---------------------------------------------------------------------------- 00117 int 00118 BasicSMTPHandler::smtp_DATA_begin() 00119 { 00120 ASSERT(cur_msg_.msg_.size() == 0); 00121 return 0; 00122 } 00123 00124 //---------------------------------------------------------------------------- 00125 int 00126 BasicSMTPHandler::smtp_DATA_line(const char* line) 00127 { 00128 cur_msg_.msg_.append(line); 00129 cur_msg_.msg_.append("\r\n"); 00130 00131 return 0; 00132 } 00133 00134 //---------------------------------------------------------------------------- 00135 int 00136 BasicSMTPHandler::smtp_DATA_end() 00137 { 00138 if (cur_msg_.valid()) { 00139 message_recvd(cur_msg_); 00140 } 00141 cur_msg_.clear(); 00142 00143 return 250; 00144 } 00145 00146 } // namespace oasys