|
|
| version 1.20.2.1, 2003/01/31 12:34:29 | version 1.23, 2003/11/20 16:34:24 |
|---|---|
| Line 7 | Line 7 |
| 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 |
| */ | */ |
| static const char* IDENT_SMTP_C="$Date$"; | static const char * const IDENT_SMTP_C="$Date$"; |
| #include "pa_exception.h" | #include "pa_exception.h" |
| #include "smtp.h" | #include "smtp.h" |
| //#define DEBUG_SHOW | //#define DEBUG_SHOW |
| SMTP::SMTP(Pool& pool, const String& aorigin_string) : Pooled(pool), | SMTP::SMTP() { |
| 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; | u_short our_port; |
| if( !ResolveService(service, &our_port) ) | if( !ResolveService(service, &our_port) ) |
| { | { |
| if( !ResolveHostname(hostname, &sa_in) ) | if( !ResolveHostname(hostname, &sa_in) ) |
| { | { |
| sa_in.sin_family = AF_INET; | sa_in.sin_family = AF_INET; |
| sa_in.sin_port = our_port; | sa_in.sin_port = (unsigned short)our_port; |
| if( !GetAndSetTheSocket(&the_socket) ) | if( !GetAndSetTheSocket(&the_socket) ) |
| { | { |
| 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, | 0, |
| "connect to %s:%s failed", | "connect to %s:%s failed", |
| hostname, service); | hostname, service); |
| } | } |
| Line 71 GetBuffer(int wait) | Line 75 GetBuffer(int wait) |
| { | { |
| int retval; | int retval; |
| int bytes_read = 0; | int bytes_read = 0; |
| unsigned long ready_to_read = 0; | |
| // Use select to see if data is waiting... | // Use select to see if data is waiting... |
| FD_ZERO(&fds); | FD_ZERO(&fds); |
| Line 225 SendLine(const char* data, unsigned long | Line 228 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, | 0, |
| "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 253 SendLine(const char* data, unsigned long |
| default: | default: |
| throw Exception("smtp.execute", | throw Exception("smtp.execute", |
| &origin_string, | 0, |
| "connection::put_data() unexpected error from send(): %d", | "connection::put_data() unexpected error from send(): %d", |
| ws_error); | ws_error); |
| } | } |
| Line 268 SendLine(const char* data, unsigned long | Line 271 SendLine(const char* data, unsigned long |
| void SMTP:: | void SMTP:: |
| SendBuffer(const char* data, unsigned long length) | SendBuffer(const char* data, unsigned long length) |
| { | { |
| DWORD retval = 0; | |
| unsigned int sorta_sent = 0; | |
| while( length ) | while( length ) |
| { | { |
| if( (out_index + length) < SOCKET_BUFFER_SIZE ) | if( (out_index + length) < SOCKET_BUFFER_SIZE ) |
| Line 324 SendSmtpError(const char* message) | Line 324 SendSmtpError(const char* message) |
| CloseConnect(); | CloseConnect(); |
| throw Exception("smtp.execute", | throw Exception("smtp.execute", |
| &origin_string, | 0, |
| "failed: %s", message); | "failed: %s", message); |
| } | } |
| Line 408 open_socket( const char* server, const c | Line 408 open_socket( const char* server, const c |
| if( gethostname(my_hostname, sizeof(my_hostname)) ) | if( gethostname(my_hostname, sizeof(my_hostname)) ) |
| throw Exception("smtp.connect", | throw Exception("smtp.connect", |
| &origin_string, | 0, |
| "lookup of '%s' failed", my_hostname); | "lookup of '%s' failed", my_hostname); |
| } | } |
| Line 459 prepare_message(char *from, char *to, co | Line 459 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, | 0, |
| "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); |