]> Pileus Git - ~andy/fetchmail/blobdiff - smtp.c
More from HH's patch.
[~andy/fetchmail] / smtp.c
diff --git a/smtp.c b/smtp.c
index 0caf0bb730cfe7fe156e6018d23d4872241e0c86..703b10fd4dbb22d951f7af67f84f97da43f2cb3a 100644 (file)
--- a/smtp.c
+++ b/smtp.c
@@ -27,11 +27,22 @@ static struct opt extensions[] =
     {"8BITMIME",       ESMTP_8BITMIME},
     {"SIZE",           ESMTP_SIZE},
     {"ETRN",           ESMTP_ETRN},
+#ifdef ODMR_ENABLE
+    {"ATRN",           ESMTP_ATRN},
+#endif /* ODMR_ENABLE */
     {(char *)NULL, 0},
 };
 
 char smtp_response[MSGBUFSIZE];
 
+static char smtp_mode = 'S';
+
+void SMTP_setmode(char sl)
+/* set whether we are speaking SMTP or LMTP */
+{
+    smtp_mode = sl;
+}
+
 int SMTP_helo(int sock,const char *host)
 /* send a "HELO" message to the SMTP listener */
 {
@@ -39,7 +50,7 @@ int SMTP_helo(int sock,const char *host)
 
   SockPrintf(sock,"HELO %s\r\n", host);
   if (outlevel >= O_MONITOR)
-      error(0, 0, "SMTP> HELO %s", host);
+      report(stdout, "SMTP> HELO %s\n", host);
   ok = SMTP_ok(sock);
   return ok;
 }
@@ -49,9 +60,10 @@ int SMTP_ehlo(int sock, const char *host, int *opt)
 {
   struct opt *hp;
 
-  SockPrintf(sock,"EHLO %s\r\n", host);
+  SockPrintf(sock,"%cHLO %s\r\n", (smtp_mode == 'S') ? 'E' : smtp_mode, host);
   if (outlevel >= O_MONITOR)
-      error(0, 0, "SMTP> EHLO %s", host);
+      report(stdout, "%cMTP> %cHLO %s\n", 
+           smtp_mode, (smtp_mode == 'S') ? 'E' : smtp_mode, host);
   
   *opt = 0;
   while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1)
@@ -66,7 +78,7 @@ int SMTP_ehlo(int sock, const char *host, int *opt)
          return SM_ERROR;
       smtp_response[n] = '\0';
       if (outlevel >= O_MONITOR)
-         error(0, 0, "SMTP< %s", smtp_response);
+         report(stdout, "SMTP< %s\n", smtp_response);
       for (hp = extensions; hp->name; hp++)
          if (!strncasecmp(hp->name, smtp_response+4, strlen(hp->name)))
              *opt |= hp->value;
@@ -92,7 +104,7 @@ int SMTP_from(int sock, const char *from, const char *opts)
        strcat(buf, opts);
     SockPrintf(sock,"%s\r\n", buf);
     if (outlevel >= O_MONITOR)
-       error(0, 0, "SMTP> %s", buf);
+       report(stdout, "%cMTP> %s\n", smtp_mode, buf);
     ok = SMTP_ok(sock);
     return ok;
 }
@@ -104,7 +116,7 @@ int SMTP_rcpt(int sock, const char *to)
 
   SockPrintf(sock,"RCPT TO:<%s>\r\n", to);
   if (outlevel >= O_MONITOR)
-      error(0, 0, "SMTP> RCPT TO:<%s>", to);
+      report(stdout, "%cMTP> RCPT TO:<%s>\n", smtp_mode, to);
   ok = SMTP_ok(sock);
   return ok;
 }
@@ -116,7 +128,7 @@ int SMTP_data(int sock)
 
   SockPrintf(sock,"DATA\r\n");
   if (outlevel >= O_MONITOR)
-      error(0, 0, "SMTP> DATA");
+      report(stdout, "%cMTP> DATA\n", smtp_mode);
   ok = SMTP_ok(sock);
   return ok;
 }
@@ -128,7 +140,7 @@ int SMTP_rset(int sock)
 
   SockPrintf(sock,"RSET\r\n");
   if (outlevel >= O_MONITOR)
-      error(0, 0, "SMTP> RSET");
+      report(stdout, "%cMTP> RSET\n", smtp_mode);
   ok = SMTP_ok(sock);
   return ok;
 }
@@ -140,7 +152,7 @@ int SMTP_quit(int sock)
 
   SockPrintf(sock,"QUIT\r\n");
   if (outlevel >= O_MONITOR)
-      error(0, 0, "SMTP> QUIT");
+      report(stdout, "%cMTP> QUIT\n", smtp_mode);
   ok = SMTP_ok(sock);
   return ok;
 }
@@ -152,8 +164,16 @@ int SMTP_eom(int sock)
 
   SockPrintf(sock,".\r\n");
   if (outlevel >= O_MONITOR)
-      error(0, 0, "SMTP>. (EOM)");
-  ok = SMTP_ok(sock);
+      report(stdout, "%cMTP>. (EOM)\n", smtp_mode);
+
+  /* 
+   * When doing LMTP, must process many of these at the outer level. 
+   */
+  if (smtp_mode == 'S')
+      ok = SMTP_ok(sock);
+  else
+      ok = SM_OK;
+
   return ok;
 }
 
@@ -167,12 +187,12 @@ int SMTP_ok(int sock)
        if (smtp_response[strlen(smtp_response)-1] == '\n')
            smtp_response[strlen(smtp_response)-1] = '\0';
        if (smtp_response[strlen(smtp_response)-1] == '\r')
-           smtp_response[strlen(smtp_response)-1] = '\r';
+           smtp_response[strlen(smtp_response)-1] = '\0';
        if (n < 4)
            return SM_ERROR;
        smtp_response[n] = '\0';
        if (outlevel >= O_MONITOR)
-           error(0, 0, "SMTP< %s", smtp_response);
+           report(stdout, "%cMTP< %s\n", smtp_mode, smtp_response);
        if ((smtp_response[0] == '1' || smtp_response[0] == '2' || smtp_response[0] == '3') && smtp_response[3] == ' ')
            return SM_OK;
        else if (smtp_response[3] != '-')