]> Pileus Git - ~andy/fetchmail/blobdiff - smtp.c
Fix typo repsonsible -> responsible.
[~andy/fetchmail] / smtp.c
diff --git a/smtp.c b/smtp.c
index 603c40147a32336de7a32ef15bc48b1ae1830169..d831249243192b401831e4ce1ed7f93a0ce0f560 100644 (file)
--- a/smtp.c
+++ b/smtp.c
@@ -18,7 +18,7 @@
 #include <signal.h>
 #include "socket.h"
 #include "smtp.h"
-#include "i18n.h"
+#include "gettext.h"
 
 struct opt
 {
@@ -171,22 +171,24 @@ int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *pass
 {
   struct opt *hp;
   char auth_response[511];
+  SIGHANDLERTYPE alrmsave;
   const int tmout = (mytimeout >= TIMEOUT_HELO ? mytimeout : TIMEOUT_HELO);
 
-  if (SockTimeout(sock, tmout) != 0)
-      return SM_UNRECOVERABLE;
-
   SockPrintf(sock,"%cHLO %s\r\n", (smtp_mode == 'S') ? 'E' : smtp_mode, host);
   if (outlevel >= O_MONITOR)
       report(stdout, "%cMTP> %cHLO %s\n", 
            smtp_mode, (smtp_mode == 'S') ? 'E' : smtp_mode, host);
 
+  alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
+  set_timeout(tmout);
+
   *opt = 0;
   while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1)
   {
       size_t n;
 
       set_timeout(0);
+      (void)set_signal_handler(SIGALRM, alrmsave);
 
       n = strlen(smtp_response);
       if (n > 0 && smtp_response[n-1] == '\n')
@@ -212,6 +214,9 @@ int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *pass
       }
       else if (smtp_response[3] != '-')
          return SM_ERROR;
+
+      alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
+      set_timeout(tmout);
   }
   return SM_UNRECOVERABLE;
 }
@@ -306,18 +311,23 @@ int SMTP_ok(int sock, char smtp_mode, int mintimeout)
  * smtp_response, without trailing [CR]LF, but with normalized CRLF
  * between multiple lines of multi-line replies */
 {
+    SIGHANDLERTYPE alrmsave;
     char reply[MSGBUFSIZE], *i;
-    int tmo = mytimeout >= mintimeout ? mytimeout : mintimeout;
 
-    smtp_response[0] = '\0';
+    /* set an alarm for smtp ok */
+    alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
+    set_timeout(mytimeout >= mintimeout ? mytimeout : mintimeout);
 
-    if (SockTimeout(sock, tmo))
-       return SM_UNRECOVERABLE;
+    smtp_response[0] = '\0';
 
     while ((SockRead(sock, reply, sizeof(reply)-1)) != -1)
     {
        size_t n;
 
+       /* restore alarm */
+       set_timeout(0);
+       set_signal_handler(SIGALRM, alrmsave);
+
        n = strlen(reply);
        if (n > 0 && reply[n-1] == '\n')
            reply[--n] = '\0';
@@ -353,8 +363,16 @@ int SMTP_ok(int sock, char smtp_mode, int mintimeout)
            return SM_ERROR;
 
        strlcat(smtp_response, "\r\n", sizeof(smtp_response));
+
+       /* set an alarm for smtp ok */
+       set_signal_handler(SIGALRM, null_signal_handler);
+       set_timeout(mytimeout);
     }
 
+    /* restore alarm */
+    set_timeout(0);
+    set_signal_handler(SIGALRM, alrmsave);
+
     if (outlevel >= O_MONITOR)
        report(stderr, GT_("smtp listener protocol error\n"));
     return SM_UNRECOVERABLE;