Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

SMTPSocket Class Reference

#include <SMTPSocket.h>

Collaboration diagram for SMTPSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SMTPSocket (SocketHandler &)
 ~SMTPSocket ()
void OnLine (const std::string &)
void OnDelete ()
void OnAccept ()
std::string get_email (const std::string &)
void SetFake (bool x=true)

Private Attributes

FwdSocketm_remote
std::string m_cmd_mail
std::string m_cmd_rcpt
bool m_cmd_data
bool m_cmd_quit
std::string m_header_from
std::string m_header_to
std::string m_header_subject
std::string m_data
bool m_fake

Constructor & Destructor Documentation

SMTPSocket::SMTPSocket SocketHandler &   ) 
 

Definition at line 53 of file SMTPSocket.cpp.

References SMTPSocket().

Referenced by SMTPSocket().

00054 :TcpSocket(h) 00055 ,m_remote(NULL) 00056 ,m_cmd_data(false) 00057 ,m_cmd_quit(false) 00058 { 00059 SetLineProtocol(); 00060 }

SMTPSocket::~SMTPSocket  ) 
 

Definition at line 63 of file SMTPSocket.cpp.

References m_remote.

00064 { 00065 if (m_remote && Handler().Valid(m_remote) ) 00066 { 00067 // m_remote -> SetCloseAndDelete(); 00068 } 00069 }


Member Function Documentation

std::string SMTPSocket::get_email const std::string &   ) 
 

Definition at line 191 of file SMTPSocket.cpp.

References get_email().

Referenced by get_email(), and OnLine().

00192 { 00193 char *tmp = new char[em.size() + 1]; 00194 strcpy(tmp, em.c_str()); 00195 char *p = strstr(tmp,"<"); 00196 if (p) 00197 { 00198 char *p2 = strstr(p,">"); 00199 if (p2) 00200 { 00201 *p2 = 0; 00202 std::string str = p + 1; 00203 delete tmp; 00204 return str; 00205 } 00206 } 00207 delete tmp; 00208 return em; 00209 }

void SMTPSocket::OnAccept  ) 
 

Definition at line 174 of file SMTPSocket.cpp.

References m_remote.

00175 { 00176 printf(" *** Remote Address: '%s'\n",GetRemoteHostname().c_str()); 00177 if (isip(GetRemoteHostname())) 00178 { 00179 // create a 'Spammer' 00180 SetCloseAndDelete(); 00181 return; 00182 } 00183 m_remote = new FwdSocket(Handler()); 00184 m_remote -> Open("mail.alhem.net",279); 00185 m_remote -> SetDeleteByHandler(); 00186 m_remote -> SetRemote(this); 00187 Handler().Add(m_remote); 00188 }

void SMTPSocket::OnDelete  ) 
 

Definition at line 165 of file SMTPSocket.cpp.

References m_remote.

00166 { 00167 if (m_remote && Handler().Valid(m_remote) ) 00168 { 00169 // m_remote -> SetCloseAndDelete(); 00170 } 00171 }

void SMTPSocket::OnLine const std::string &   ) 
 

Definition at line 72 of file SMTPSocket.cpp.

References get_email(), m_cmd_data, m_cmd_mail, m_cmd_quit, m_cmd_rcpt, m_data, m_fake, m_header_from, m_header_subject, m_header_to, m_remote, OnLine(), and db::Mailinst::save().

Referenced by OnLine().

00073 { 00074 Parse pa(line,":"); 00075 std::string cmd = pa.getword(); 00076 00077 if (m_cmd_data) 00078 { 00079 if (cmd == "From" && line.substr(0,5) == "From:" && !m_header_from.size()) 00080 { 00081 m_header_from = pa.getrest(); 00082 printf(" %s\n",line.c_str()); 00083 } 00084 else 00085 if (cmd == "To" && line.substr(0,3) == "To:" && !m_header_to.size()) 00086 { 00087 m_header_to = pa.getrest(); 00088 printf(" %s\n",line.c_str()); 00089 } 00090 else 00091 if (cmd == "Subject" && line.substr(0,8) == "Subject:" && !m_header_subject.size()) 00092 { 00093 m_header_subject = pa.getrest(); 00094 printf(" %s\n",line.c_str()); 00095 } 00096 else 00097 if (cmd == ".") 00098 { 00099 if (m_fake) 00100 { 00101 printf(" *** FAKE <221\n"); 00102 Send("221 2.0.0 g2.alhem.net closing connection\r\n"); 00103 } 00104 m_cmd_data = false; 00105 } 00106 m_data += line + "\r\n"; 00107 } 00108 else 00109 if (!strcasecmp(cmd.c_str(), "MAIL") ) 00110 { 00111 m_cmd_mail = pa.getrest(); 00112 printf(" %s\n",line.c_str()); 00113 if (!strstr(m_cmd_mail.c_str(),"@") || !strstr(m_cmd_mail.c_str(),".")) 00114 { 00115 SetCloseAndDelete(); 00116 } 00117 } 00118 else 00119 if (!strcasecmp(cmd.c_str(), "RCPT") ) 00120 { 00121 m_cmd_rcpt = pa.getrest(); 00122 printf(" %s\n",line.c_str()); 00123 } 00124 else 00125 if (!strcasecmp(cmd.c_str(), "DATA") ) 00126 { 00127 if (m_fake) 00128 { 00129 printf(" *** FAKE <354\n"); 00130 Send("354 Enter mail, end with \".\" on a line by itself\r\n"); 00131 } 00132 m_cmd_data = true; 00133 } 00134 else 00135 if (!strcasecmp(cmd.c_str(), "QUIT") ) 00136 m_cmd_quit = true; 00137 else 00138 if (!m_cmd_data) 00139 { 00140 printf("Command: %s\n",line.c_str()); 00141 } 00142 if (m_remote && Handler().Valid(m_remote) && !m_fake) 00143 { 00144 m_remote -> Send(line + "\r\n"); 00145 } 00146 if (m_cmd_quit) 00147 { 00148 db::Mailinst mq(*static_cast<NukeHandler&>(Handler()).GetDatabase(), 00149 GetRemoteHostname(), 00150 get_email(m_cmd_mail), 00151 get_email(m_cmd_rcpt), 00152 get_email(m_header_from), 00153 get_email(m_header_to), 00154 m_header_subject); 00155 mq.save(); 00156 // printf(" %s\n %s\n",m_cmd_mail.c_str(),m_header_from.c_str()); 00157 // printf(" %s\n %s\n",m_cmd_rcpt.c_str(),m_header_to.c_str()); 00158 // printf(" %s\n",m_header_subject.c_str()); 00159 // printf("\n"); 00160 SetCloseAndDelete(); 00161 } 00162 }

void SMTPSocket::SetFake bool  x = true  )  [inline]
 

Definition at line 40 of file SMTPSocket.h.

References m_fake, and SetFake().

Referenced by SetFake().

00040 { m_fake = x; }


Member Data Documentation

bool SMTPSocket::m_cmd_data [private]
 

Definition at line 46 of file SMTPSocket.h.

Referenced by OnLine().

std::string SMTPSocket::m_cmd_mail [private]
 

Definition at line 44 of file SMTPSocket.h.

Referenced by OnLine().

bool SMTPSocket::m_cmd_quit [private]
 

Definition at line 47 of file SMTPSocket.h.

Referenced by OnLine().

std::string SMTPSocket::m_cmd_rcpt [private]
 

Definition at line 45 of file SMTPSocket.h.

Referenced by OnLine().

std::string SMTPSocket::m_data [private]
 

Definition at line 51 of file SMTPSocket.h.

Referenced by OnLine().

bool SMTPSocket::m_fake [private]
 

Definition at line 52 of file SMTPSocket.h.

Referenced by OnLine(), and SetFake().

std::string SMTPSocket::m_header_from [private]
 

Definition at line 48 of file SMTPSocket.h.

Referenced by OnLine().

std::string SMTPSocket::m_header_subject [private]
 

Definition at line 50 of file SMTPSocket.h.

Referenced by OnLine().

std::string SMTPSocket::m_header_to [private]
 

Definition at line 49 of file SMTPSocket.h.

Referenced by OnLine().

FwdSocket* SMTPSocket::m_remote [private]
 

Definition at line 43 of file SMTPSocket.h.

Referenced by OnAccept(), OnDelete(), OnLine(), and ~SMTPSocket().


The documentation for this class was generated from the following files:
Generated for C++ Sockets library example: SMTP Proxy by doxygen 1.3.6

www.TV-friendship.com
The matchmaking service with an all new twist.

Quantum 'Teleportation'
Some thoughts
Page, code, and content Copyright (C) 2004 by Anders Hedström