* Support multiline responses from SMTP servers when sending mail
authorArt Cancro <ajc@citadel.org>
Sat, 18 Mar 2000 18:18:05 +0000 (18:18 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 18 Mar 2000 18:18:05 +0000 (18:18 +0000)
citadel/ChangeLog
citadel/clientsocket.c
citadel/clientsocket.h
citadel/serv_smtp.c

index b720e40fdd3193b4ab919370817ce1470282814a..b4d4a9d3028922a51b1fcea7dc500b40a5c0548b 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index ba423c4353ad01d91ef9c0bc789d96f42bd3e8c5..f645e9261cd231e205ab6f8ab7449cccb2251063 100644 (file)
@@ -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()
index 9ff18c8902223b2f8a29fd532f25f1361d54609f..6bbe88db57eadd2aefe7908bea23004e874d2cf5 100644 (file)
@@ -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);
 
index e75ec50e34e7bc69a3cacd2a5d1b5a9282062eb3..83a7d02b417a355d670ae39d59266f317ec82627 100644 (file)
@@ -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);