00001 /* 00002 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By 00003 * downloading, copying, installing or using the software you agree to 00004 * this license. If you do not agree to this license, do not download, 00005 * install, copy or use the software. 00006 * 00007 * Intel Open Source License 00008 * 00009 * Copyright (c) 2005 Intel Corporation. All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are 00013 * met: 00014 * 00015 * Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * 00018 * Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * 00022 * Neither the name of the Intel Corporation nor the names of its 00023 * contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00027 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00028 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00029 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 00030 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00031 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00032 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00033 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00034 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00035 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00036 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 */ 00038 00039 #include "BasicSMTP.h" 00040 00041 namespace oasys { 00042 00043 //---------------------------------------------------------------------------- 00044 BasicSMTPSender::BasicSMTPSender(const std::string& helo_domain, 00045 BasicSMTPMsg* msg) 00046 : helo_domain_(helo_domain), msg_(msg) 00047 { 00048 } 00049 00050 //---------------------------------------------------------------------------- 00051 void 00052 BasicSMTPSender::get_HELO_domain(std::string* domain) 00053 { 00054 domain->assign(helo_domain_); 00055 } 00056 00057 //---------------------------------------------------------------------------- 00058 void 00059 BasicSMTPSender::get_MAIL_from(std::string* from) 00060 { 00061 from->assign(msg_->from_); 00062 } 00063 00064 //---------------------------------------------------------------------------- 00065 void 00066 BasicSMTPSender::get_RCPT_list(std::vector<std::string>* to) 00067 { 00068 to->insert(to->begin(), msg_->to_.begin(), msg_->to_.end()); 00069 } 00070 00071 //---------------------------------------------------------------------------- 00072 void 00073 BasicSMTPSender::get_DATA(const std::string** data) 00074 { 00075 *data = &msg_->msg_; 00076 } 00077 00078 //---------------------------------------------------------------------------- 00079 int 00080 BasicSMTPSender::smtp_error(int code) 00081 { 00082 log_err("/oasys/smtp-sender", "unexpected error %d", code); 00083 return -1; 00084 } 00085 00086 //---------------------------------------------------------------------------- 00087 BasicSMTPHandler::BasicSMTPHandler() 00088 { 00089 } 00090 00091 //---------------------------------------------------------------------------- 00092 int 00093 BasicSMTPHandler::smtp_HELO(const char* domain) 00094 { 00095 (void)domain; 00096 return 250; 00097 } 00098 00099 //---------------------------------------------------------------------------- 00100 int 00101 BasicSMTPHandler::smtp_MAIL(const char* from) 00102 { 00103 if (strlen(from) == 0) { 00104 return 501; 00105 } 00106 00107 cur_msg_.from_ = from; 00108 return 250; 00109 } 00110 00111 //---------------------------------------------------------------------------- 00112 int 00113 BasicSMTPHandler::smtp_RCPT(const char* to) 00114 { 00115 if (strlen(to) == 0) { 00116 return 501; 00117 } 00118 00119 cur_msg_.to_.push_back(to); 00120 return 250; 00121 } 00122 00123 //---------------------------------------------------------------------------- 00124 int 00125 BasicSMTPHandler::smtp_RSET() 00126 { 00127 return 250; 00128 } 00129 00130 //---------------------------------------------------------------------------- 00131 int 00132 BasicSMTPHandler::smtp_QUIT() 00133 { 00134 return 221; 00135 } 00136 00137 //---------------------------------------------------------------------------- 00138 int 00139 BasicSMTPHandler::smtp_DATA_begin() 00140 { 00141 ASSERT(cur_msg_.msg_.size() == 0); 00142 return 0; 00143 } 00144 00145 //---------------------------------------------------------------------------- 00146 int 00147 BasicSMTPHandler::smtp_DATA_line(const char* line) 00148 { 00149 cur_msg_.msg_.append(line); 00150 cur_msg_.msg_.append("\r\n"); 00151 00152 return 0; 00153 } 00154 00155 //---------------------------------------------------------------------------- 00156 int 00157 BasicSMTPHandler::smtp_DATA_end() 00158 { 00159 if (cur_msg_.valid()) { 00160 message_recvd(cur_msg_); 00161 } 00162 cur_msg_.clear(); 00163 00164 return 250; 00165 } 00166 00167 } // namespace oasys