--- parser3/src/classes/smtp/Attic/smtp.C 2001/04/10 06:57:23 1.2 +++ parser3/src/classes/smtp/Attic/smtp.C 2003/01/21 15:51:09 1.20 @@ -1,18 +1,18 @@ /** @file Parser: SMTP sender. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: smtp.C,v 1.2 2001/04/10 06:57:23 paf Exp $ - + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) Parts of the code here is based upon an early gensock and blat */ -#include "smtp.h" +static const char* IDENT_SMTP_C="$Date: 2003/01/21 15:51:09 $"; + #include "pa_exception.h" +#include "smtp.h" + +//#define DEBUG_SHOW SMTP::SMTP(Pool& pool, const String& aorigin_string) : Pooled(pool), origin_string(aorigin_string) { @@ -58,7 +58,7 @@ ConnectToHost(const char *hostname, cons CloseConnect(); - THROW(0, 0, + throw Exception("smtp.connect", &origin_string, "connect to %s:%s failed", hostname, service); @@ -224,7 +224,7 @@ SendLine(const char *data, unsigned long while( length > 0 ) { if( SOCKET_ERROR == select(0, NULL, &fds, NULL, &timeout) ) - THROW(0, 0, + throw Exception("smtp.execute", &origin_string, "connection::put_data() unexpected error from select: %d", WSAGetLastError()); @@ -249,7 +249,7 @@ SendLine(const char *data, unsigned long break; default: - THROW(0, 0, + throw Exception("smtp.execute", &origin_string, "connection::put_data() unexpected error from send(): %d", ws_error); @@ -323,7 +323,7 @@ SendSmtpError(const char * message) SendLine("QUIT\r\n", 6); CloseConnect(); - THROW(0, 0, + throw Exception("smtp.execute", &origin_string, "failed: %s", message); } @@ -336,7 +336,6 @@ void SMTP:: transform_and_send_edit_data(const char * editptr ) { const char *index; - const char *header_end; char previous_char = 'x'; unsigned int send_len; BOOL done = 0; @@ -344,8 +343,6 @@ transform_and_send_edit_data(const char send_len = lstrlen(editptr); index = editptr; - header_end = strstr(editptr, "\r\n\r\n"); - while( !done ) { // room for extra char for double dot on end case @@ -355,22 +352,17 @@ transform_and_send_edit_data(const char { case '.': if( previous_char == '\n' ) - { - /* send _two_ dots... */ - SendBuffer(index, 1); - } + SendBuffer(index, 1); // send _two_ dots... SendBuffer(index, 1); break; - case '\r': - // watch for soft-breaks in the header, and ignore them - if( index < header_end && (strncmp(index, "\r\r\n", 3) == 0) ) - index += 2; - else - if( previous_char != '\r' ) - SendBuffer(index, 1); - // soft line-break (see EM_FMTLINES), skip extra CR */ + case '\n': // x\n -> \r\n + if( previous_char != '\r' ) { + SendBuffer("\r", 1); + SendBuffer(index, 1); + } break; + default: SendBuffer(index, 1); break; @@ -415,7 +407,7 @@ open_socket( const char *server, const c ConnectToHost(server, service); if( gethostname(my_hostname, sizeof(my_hostname)) ) - THROW(0, 0, + throw Exception("smtp.connect", &origin_string, "lookup of '%s' failed", my_hostname); } @@ -466,7 +458,7 @@ prepare_message(char *from, char *to, co SendLine(out_data, lstrlen(out_data) ); if( 250 != get_line() ) - THROW(0, 0, + throw Exception("smtp.execute", &origin_string, "The mail server doesn't like the name %s. Have you set the 'To: ' field correctly?", ptr); @@ -503,12 +495,6 @@ static char *rsplit(char *string, char d } return NULL; } -static char *extractEmail(char *email) { - lsplit(email, '>'); lsplit(email, '\x0D');lsplit(email, '\x0A'); - char *next=rsplit(email, '<'); - if(next) email=next; - return email; -} //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- @@ -518,7 +504,11 @@ static char *extractEmail(char *email) { void SMTP:: Send(const char *server, const char *service, const char *msg, char *from, char *to) { - prepare_message( extractEmail(from), extractEmail(to), server, service); +#ifdef DEBUG_SHOW + throw Exception("paf.debug",0,"from=%s|to=%s|msg=%s", from,to,msg); +#endif + + prepare_message( from, to, server, service); send_data(msg);