|
|
| version 1.5, 2001/10/19 12:43:30 | version 1.14, 2002/12/05 08:08:59 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: SMTP sender. | Parser: SMTP sender. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| 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 |
| */ | */ |
| #include "smtp.h" | static const char* IDENT_SMTP_C="$Date$"; |
| #include "pa_exception.h" | #include "pa_exception.h" |
| #include "smtp.h" | |
| SMTP::SMTP(Pool& pool, const String& aorigin_string) : Pooled(pool), | SMTP::SMTP(Pool& pool, const String& aorigin_string) : Pooled(pool), |
| origin_string(aorigin_string) { | origin_string(aorigin_string) { |
| Line 56 ConnectToHost(const char *hostname, cons | Line 56 ConnectToHost(const char *hostname, cons |
| CloseConnect(); | CloseConnect(); |
| throw Exception(0, 0, | throw Exception("smtp.connect", |
| &origin_string, | &origin_string, |
| "connect to %s:%s failed", | "connect to %s:%s failed", |
| hostname, service); | hostname, service); |
| Line 222 SendLine(const char *data, unsigned long | Line 222 SendLine(const char *data, unsigned long |
| while( length > 0 ) | while( length > 0 ) |
| { | { |
| if( SOCKET_ERROR == select(0, NULL, &fds, NULL, &timeout) ) | if( SOCKET_ERROR == select(0, NULL, &fds, NULL, &timeout) ) |
| throw Exception(0, 0, | 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 247 SendLine(const char *data, unsigned long | Line 247 SendLine(const char *data, unsigned long |
| break; | break; |
| default: | default: |
| throw Exception(0, 0, | 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 321 SendSmtpError(const char * message) | Line 321 SendSmtpError(const char * message) |
| SendLine("QUIT\r\n", 6); | SendLine("QUIT\r\n", 6); |
| CloseConnect(); | CloseConnect(); |
| throw Exception(0, 0, | throw Exception("smtp.execute", |
| &origin_string, | &origin_string, |
| "failed: %s", message); | "failed: %s", message); |
| } | } |
| Line 342 transform_and_send_edit_data(const char | Line 342 transform_and_send_edit_data(const char |
| send_len = lstrlen(editptr); | send_len = lstrlen(editptr); |
| index = editptr; | index = editptr; |
| header_end = strstr(editptr, "\r\n\r\n"); | |
| while( !done ) | while( !done ) |
| { | { |
| // room for extra char for double dot on end case | // room for extra char for double dot on end case |
| Line 353 transform_and_send_edit_data(const char | Line 351 transform_and_send_edit_data(const char |
| { | { |
| case '.': | case '.': |
| if( previous_char == '\n' ) | if( previous_char == '\n' ) |
| { | SendBuffer(index, 1); // send _two_ dots... |
| /* send _two_ dots... */ | |
| SendBuffer(index, 1); | |
| } | |
| SendBuffer(index, 1); | SendBuffer(index, 1); |
| break; | break; |
| case '\r': | case '\n': // x\n -> \r\n |
| // watch for soft-breaks in the header, and ignore them | if( previous_char != '\r' ) { |
| if( index < header_end && (strncmp(index, "\r\r\n", 3) == 0) ) | SendBuffer("\r", 1); |
| index += 2; | SendBuffer(index, 1); |
| else | } |
| if( previous_char != '\r' ) | |
| SendBuffer(index, 1); | |
| // soft line-break (see EM_FMTLINES), skip extra CR */ | |
| break; | break; |
| default: | default: |
| SendBuffer(index, 1); | SendBuffer(index, 1); |
| break; | break; |
| Line 413 open_socket( const char *server, const c | Line 406 open_socket( const char *server, const c |
| ConnectToHost(server, service); | ConnectToHost(server, service); |
| if( gethostname(my_hostname, sizeof(my_hostname)) ) | if( gethostname(my_hostname, sizeof(my_hostname)) ) |
| throw Exception(0, 0, | throw Exception("smtp.connect", |
| &origin_string, | &origin_string, |
| "lookup of '%s' failed", my_hostname); | "lookup of '%s' failed", my_hostname); |
| } | } |
| Line 464 prepare_message(char *from, char *to, co | Line 457 prepare_message(char *from, char *to, co |
| SendLine(out_data, lstrlen(out_data) ); | SendLine(out_data, lstrlen(out_data) ); |
| if( 250 != get_line() ) | if( 250 != get_line() ) |
| throw Exception(0, 0, | 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 501 static char *rsplit(char *string, char d | Line 494 static char *rsplit(char *string, char d |
| } | } |
| return NULL; | 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; | |
| } | |
| //---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- |
| //---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- |
| Line 516 static char *extractEmail(char *email) { | Line 503 static char *extractEmail(char *email) { |
| 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) |
| { | { |
| prepare_message( extractEmail(from), extractEmail(to), server, service); | prepare_message( from, to, server, service); |
| send_data(msg); | send_data(msg); |