Diff for /parser3/src/classes/smtp/Attic/smtp.C between versions 1.17 and 1.20.2.3.2.1

version 1.17, 2002/12/05 13:00:53 version 1.20.2.3.2.1, 2003/03/18 15:14:15
Line 1 Line 1
 /** @file  /** @file
         Parser: SMTP sender.          Parser: SMTP sender.
   
         Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
   
         Parts of the code here is based upon an early gensock and blat          Parts of the code here is based upon an early gensock and blat
Line 14  static const char* IDENT_SMTP_C="$Date$" Line 14  static const char* IDENT_SMTP_C="$Date$"
   
 //#define DEBUG_SHOW  //#define DEBUG_SHOW
   
 SMTP::SMTP(Pool& pool, const String& aorigin_string) : Pooled(pool),  SMTP::SMTP(const String* aorigin_string): origin_string(aorigin_string) {
         origin_string(aorigin_string) {  
     the_socket  = 0;      the_socket  = 0;
     in_index    = 0;      in_index    = 0;
     out_index   = 0;      out_index   = 0;
Line 29  SMTP::SMTP(Pool& pool, const String& aor Line 28  SMTP::SMTP(Pool& pool, const String& aor
     last_winsock_error = 0;      last_winsock_error = 0;
 }  }
   
   SMTP::~SMTP() {
           free(in_buffer);
       free(out_buffer);
   }
   
   
 // ---------------------------------------------------------------------------  // ---------------------------------------------------------------------------
 void SMTP::   void SMTP:: 
 ConnectToHost(const char *hostname, const char *service)  ConnectToHost(const char* hostname, const char* service)
 {  {
     struct sockaddr_in  sa_in;      struct sockaddr_in  sa_in;
     int                         our_port;      int                         our_port;
Line 59  ConnectToHost(const char *hostname, cons Line 63  ConnectToHost(const char *hostname, cons
     CloseConnect();      CloseConnect();
   
     throw Exception("smtp.connect",      throw Exception("smtp.connect",
                 &origin_string,                  origin_string,
                 "connect to %s:%s failed",                   "connect to %s:%s failed", 
                         hostname, service);                          hostname, service);
 }  }
Line 212  get_line( void ) Line 216  get_line( void )
 //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
 // returns 0 if all is OK  // returns 0 if all is OK
 void SMTP::   void SMTP:: 
 SendLine(const char *data, unsigned long length)  SendLine(const char* data, unsigned long length)
 {  {
     int         num_sent;      int         num_sent;
   
Line 225  SendLine(const char *data, unsigned long Line 229  SendLine(const char *data, unsigned long
     {      {
         if( SOCKET_ERROR == select(0, NULL, &fds, NULL, &timeout) )           if( SOCKET_ERROR == select(0, NULL, &fds, NULL, &timeout) ) 
             throw Exception("smtp.execute",              throw Exception("smtp.execute",
                                 &origin_string,                                  origin_string,
                         "connection::put_data() unexpected error from select: %d",                          "connection::put_data() unexpected error from select: %d",
                                         WSAGetLastError());                                          WSAGetLastError());
   
Line 250  SendLine(const char *data, unsigned long Line 254  SendLine(const char *data, unsigned long
   
                 default:                  default:
                                         throw Exception("smtp.execute",                                          throw Exception("smtp.execute",
                                                 &origin_string,                                                  origin_string,
                                 "connection::put_data() unexpected error from send(): %d",                                  "connection::put_data() unexpected error from send(): %d",
                                                         ws_error);                                                          ws_error);
             }              }
Line 266  SendLine(const char *data, unsigned long Line 270  SendLine(const char *data, unsigned long
 //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
 // returns 0 if all is OK  // returns 0 if all is OK
 void SMTP::   void SMTP:: 
 SendBuffer(const char *data, unsigned long length)  SendBuffer(const char* data, unsigned long length)
 {  {
     DWORD             retval = 0;      DWORD             retval = 0;
     unsigned int    sorta_sent = 0;      unsigned int    sorta_sent = 0;
Line 318  CloseConnect() Line 322  CloseConnect()
   
 //----------------------------------------------------------------------  //----------------------------------------------------------------------
 void SMTP::  void SMTP::
 SendSmtpError(const char * message)  SendSmtpError(const char*  message)
 {  {
         SendLine("QUIT\r\n", 6);          SendLine("QUIT\r\n", 6);
         CloseConnect();          CloseConnect();
   
         throw Exception("smtp.execute",          throw Exception("smtp.execute",
                 &origin_string,                  origin_string,
                 "failed: %s", message);                  "failed: %s", message);
 }  }
   
Line 333  SendSmtpError(const char * message) Line 337  SendSmtpError(const char * message)
 // returns 20, 21, 22, 23, 24, 25 if SendBuffer() fails  // returns 20, 21, 22, 23, 24, 25 if SendBuffer() fails
 // returns 26 if FlushBuffer() fails  // returns 26 if FlushBuffer() fails
 void SMTP::  void SMTP::
 transform_and_send_edit_data(const char * editptr )  transform_and_send_edit_data(const char*  editptr )
 {  {
         const char      *index;          const char      *index;
         const char      *header_end;  
         char            previous_char = 'x';          char            previous_char = 'x';
         unsigned int    send_len;          unsigned int    send_len;
         BOOL            done = 0;          BOOL            done = 0;
Line 392  transform_and_send_edit_data(const char Line 395  transform_and_send_edit_data(const char
 // returns 16 if any get_line()'s fail  // returns 16 if any get_line()'s fail
 // returns 20, 21, 22, 23, 24, 25, 26 if transform_and_send_edit_data() fails  // returns 20, 21, 22, 23, 24, 25, 26 if transform_and_send_edit_data() fails
 void SMTP::  void SMTP::
 send_data(const char * message)  send_data(const char*  message)
 {  {
         transform_and_send_edit_data(message);          transform_and_send_edit_data(message);
         if( 250 != get_line() )          if( 250 != get_line() )
Line 403  send_data(const char * message) Line 406  send_data(const char * message)
 // returns 0 if all is OK  // returns 0 if all is OK
 // returns 50, 51, 52 if fails  // returns 50, 51, 52 if fails
 void SMTP::  void SMTP::
 open_socket( const char *server, const char *service )  open_socket( const char* server, const char* service )
 {  {
         ConnectToHost(server, service);          ConnectToHost(server, service);
   
     if( gethostname(my_hostname, sizeof(my_hostname)) )      if( gethostname(my_hostname, sizeof(my_hostname)) )
                 throw Exception("smtp.connect",                  throw Exception("smtp.connect",
                         &origin_string,                          origin_string,
                         "lookup of '%s' failed", my_hostname);                          "lookup of '%s' failed", my_hostname);
 }  }
   
Line 418  open_socket( const char *server, const c Line 421  open_socket( const char *server, const c
 // returns 50, 51, 52 if open_socket() fails  // returns 50, 51, 52 if open_socket() fails
 // returns 10, 11, 12, 13, 14, 15 if any get_line()'s fail  // returns 10, 11, 12, 13, 14, 15 if any get_line()'s fail
 void SMTP::  void SMTP::
 prepare_message(char *from, char *to, const char *server, const char *service)  prepare_message(char *from, char *to, const char* server, const char* service)
 {  {
         char    out_data[MAXOUTLINE];          char    out_data[MAXOUTLINE];
         char    *ptr;          char    *ptr;
Line 460  prepare_message(char *from, char *to, co Line 463  prepare_message(char *from, char *to, co
   
                 if( 250 != get_line() )                  if( 250 != get_line() )
                         throw Exception("smtp.execute",                          throw Exception("smtp.execute",
                                 &origin_string,                                  origin_string,
                                 "The mail server doesn't like the name %s. Have you set the 'To: ' field correctly?",                                   "The mail server doesn't like the name %s. Have you set the 'To: ' field correctly?", 
                                         ptr);                                          ptr);
   
Line 503  static char *rsplit(char *string, char d Line 506  static char *rsplit(char *string, char d
 // returns 1 if MakeSmtpHeader() fails  // returns 1 if MakeSmtpHeader() fails
 // returns 10, 11, 12, 13, 14, 15, 50, 51, 52 if prepare_message() fails  // returns 10, 11, 12, 13, 14, 15, 50, 51, 52 if prepare_message() fails
 void SMTP::  void SMTP::
 Send(const char *server, const char *service, const char *msg, char *from, char *to)  Send(const char* server, const char* service, const char* msg, char *from, char *to)
 {  {
 #ifdef DEBUG_SHOW  #ifdef DEBUG_SHOW
         throw Exception("paf.debug",0,"%s|%s|%s", from, to, msg);          throw Exception("paf.debug",0,"from=%s|to=%s|msg=%s", from,to,msg);
 #endif  #endif
   
     prepare_message( from, to, server, service);      prepare_message( from, to, server, service);

Removed from v.1.17  
changed lines
  Added in v.1.20.2.3.2.1


E-mail: