From: Art Cancro Date: Sat, 18 Mar 2000 18:18:05 +0000 (+0000) Subject: * Support multiline responses from SMTP servers when sending mail X-Git-Tag: v7.86~7251 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=6388ea5e94497e23e79d39e8d4e7dc758cf0e1d6;p=citadel.git * Support multiline responses from SMTP servers when sending mail --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index b720e40fd..b4d4a9d30 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 1.492 2000/03/18 18:18:04 ajc + * Support multiline responses from SMTP servers when sending mail + Revision 1.491 2000/03/17 16:26:57 ajc * Set up a private "Sent/Received Pages" room for each user @@ -1756,3 +1759,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index ba423c435..f645e9261 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -125,6 +125,7 @@ int sock_write(int sock, char *buf, int nbytes) } + /* * Input string from socket - implemented in terms of sock_read() * @@ -158,6 +159,27 @@ int sock_gets(int sock, char *buf) return(strlen(buf)); } +/* + * Multiline version of sock_gets() ... this is a convenience function for + * client side protocol implementations. It only returns the first line of + * a multiline response, discarding the rest. + */ +int ml_sock_gets(int sock, char *buf) { + char bigbuf[1024]; + int g; + + g = sock_gets(sock, buf); + if (g < 0) return(g); + if ( (g < 4) || (buf[3] != '-')) return(g); + + do { + g = sock_gets(sock, bigbuf); + if (g < 0) return(g); + } while ( (g >= 4) && (bigbuf[3] == '-') ); + + return(strlen(buf)); +} + /* * sock_puts() - send line to server - implemented in terms of serv_write() diff --git a/citadel/clientsocket.h b/citadel/clientsocket.h index 9ff18c890..6bbe88db5 100644 --- a/citadel/clientsocket.h +++ b/citadel/clientsocket.h @@ -7,6 +7,7 @@ int sock_connect(char *host, char *service, char *protocol); int sock_read(int sock, char *buf, int bytes); int sock_write(int sock, char *buf, int nbytes); +int ml_sock_gets(int sock, char *buf); int sock_gets(int sock, char *buf); int sock_puts(int sock, char *buf); diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index e75ec50e3..83a7d02b4 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -861,7 +861,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) } /* Process the SMTP greeting from the server */ - if (sock_gets(sock, buf) < 0) { + if (ml_sock_gets(sock, buf) < 0) { *status = 4; strcpy(dsn, "Connection broken during SMTP conversation"); goto bail; @@ -886,7 +886,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) snprintf(buf, sizeof buf, "HELO %s", config.c_fqdn); lprintf(9, ">%s\n", buf); sock_puts(sock, buf); - if (sock_gets(sock, buf) < 0) { + if (ml_sock_gets(sock, buf) < 0) { *status = 4; strcpy(dsn, "Connection broken during SMTP conversation"); goto bail; @@ -910,7 +910,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) snprintf(buf, sizeof buf, "MAIL From: %s", mailfrom); lprintf(9, ">%s\n", buf); sock_puts(sock, buf); - if (sock_gets(sock, buf) < 0) { + if (ml_sock_gets(sock, buf) < 0) { *status = 4; strcpy(dsn, "Connection broken during SMTP conversation"); goto bail; @@ -934,7 +934,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) snprintf(buf, sizeof buf, "RCPT To: %s", addr); lprintf(9, ">%s\n", buf); sock_puts(sock, buf); - if (sock_gets(sock, buf) < 0) { + if (ml_sock_gets(sock, buf) < 0) { *status = 4; strcpy(dsn, "Connection broken during SMTP conversation"); goto bail; @@ -957,7 +957,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) /* RCPT succeeded, now try the DATA command */ lprintf(9, ">DATA\n"); sock_puts(sock, "DATA"); - if (sock_gets(sock, buf) < 0) { + if (ml_sock_gets(sock, buf) < 0) { *status = 4; strcpy(dsn, "Connection broken during SMTP conversation"); goto bail; @@ -992,7 +992,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) } sock_write(sock, ".\r\n", 3); - if (sock_gets(sock, buf) < 0) { + if (ml_sock_gets(sock, buf) < 0) { *status = 4; strcpy(dsn, "Connection broken during SMTP conversation"); goto bail; @@ -1017,7 +1017,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) lprintf(9, ">QUIT\n"); sock_puts(sock, "QUIT"); - sock_gets(sock, buf); + ml_sock_gets(sock, buf); lprintf(9, "<%s\n", buf); bail: if (msg_fp != NULL) fclose(msg_fp);