have flexible timouts while reading lines in our client mode connections
[citadel.git] / citadel / modules / smtp / serv_smtp.c
index bd2cb71787116170b537d247b06088fe687fbadf..a4441674e2be1ede48ddec5cd744a3df8c834023 100644 (file)
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <termios.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <pwd.h>
@@ -1120,7 +1121,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        CCC->sPos = NULL;
 
        /* Process the SMTP greeting from the server */
-       if (ml_sock_gets(&sock, buf) < 0) {
+       if (ml_sock_gets(&sock, buf, 5) < 0) {
                *status = 4;
                strcpy(dsn, "Connection broken during SMTP conversation");
                goto bail;
@@ -1145,7 +1146,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        snprintf(buf, sizeof buf, "EHLO %s\r\n", config.c_fqdn);
        CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
        sock_write(&sock, buf, strlen(buf));
-       if (ml_sock_gets(&sock, buf) < 0) {
+       if (ml_sock_gets(&sock, buf, 5) < 0) {
                *status = 4;
                strcpy(dsn, "Connection broken during SMTP HELO");
                goto bail;
@@ -1155,7 +1156,7 @@ void smtp_try(const char *key, const char *addr, int *status,
                snprintf(buf, sizeof buf, "HELO %s\r\n", config.c_fqdn);
                CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
                sock_write(&sock, buf, strlen(buf));
-               if (ml_sock_gets(&sock, buf) < 0) {
+               if (ml_sock_gets(&sock, buf, 5) < 0) {
                        *status = 4;
                        strcpy(dsn, "Connection broken during SMTP HELO");
                        goto bail;
@@ -1182,7 +1183,7 @@ void smtp_try(const char *key, const char *addr, int *status,
                snprintf(buf, sizeof buf, "AUTH PLAIN %s\r\n", encoded);
                CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
                sock_write(&sock, buf, strlen(buf));
-               if (ml_sock_gets(&sock, buf) < 0) {
+               if (ml_sock_gets(&sock, buf, 5) < 0) {
                        *status = 4;
                        strcpy(dsn, "Connection broken during SMTP AUTH");
                        goto bail;
@@ -1206,7 +1207,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        snprintf(buf, sizeof buf, "MAIL FROM:<%s>\r\n", envelope_from);
        CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
        sock_write(&sock, buf, strlen(buf));
-       if (ml_sock_gets(&sock, buf) < 0) {
+       if (ml_sock_gets(&sock, buf, 5) < 0) {
                *status = 4;
                strcpy(dsn, "Connection broken during SMTP MAIL");
                goto bail;
@@ -1229,7 +1230,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        snprintf(buf, sizeof buf, "RCPT TO:<%s@%s>\r\n", user, node);
        CtdlLogPrintf(CTDL_DEBUG, ">%s", buf);
        sock_write(&sock, buf, strlen(buf));
-       if (ml_sock_gets(&sock, buf) < 0) {
+       if (ml_sock_gets(&sock, buf, 5) < 0) {
                *status = 4;
                strcpy(dsn, "Connection broken during SMTP RCPT");
                goto bail;
@@ -1251,7 +1252,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        /* RCPT succeeded, now try the DATA command */
        CtdlLogPrintf(CTDL_DEBUG, ">DATA\n");
        sock_write(&sock, "DATA\r\n", 6);
-       if (ml_sock_gets(&sock, buf) < 0) {
+       if (ml_sock_gets(&sock, buf, 5) < 0) {
                *status = 4;
                strcpy(dsn, "Connection broken during SMTP DATA");
                goto bail;
@@ -1280,7 +1281,8 @@ void smtp_try(const char *key, const char *addr, int *status,
        }
 
        sock_write(&sock, ".\r\n", 3);
-       if (ml_sock_gets(&sock, buf) < 0) {
+       tcdrain(sock);
+       if (ml_sock_gets(&sock, buf, 90) < 0) {
                *status = 4;
                strcpy(dsn, "Connection broken during SMTP message transmit");
                goto bail;
@@ -1305,7 +1307,7 @@ void smtp_try(const char *key, const char *addr, int *status,
 
        CtdlLogPrintf(CTDL_DEBUG, ">QUIT\n");
        sock_write(&sock, "QUIT\r\n", 6);
-       ml_sock_gets(&sock, buf);
+       ml_sock_gets(&sock, buf, 1);
        CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
        CtdlLogPrintf(CTDL_INFO, "SMTP client: delivery to <%s> @ <%s> (%s) succeeded\n",
                user, node, name);