]> Pileus Git - ~andy/fetchmail/commitdiff
Improved RFC822 conformance in SMTP code.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 24 Sep 1996 14:35:08 +0000 (14:35 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 24 Sep 1996 14:35:08 +0000 (14:35 -0000)
svn path=/trunk/; revision=116

NEWS
driver.c
smtp.c
smtp.h

diff --git a/NEWS b/NEWS
index 8ed9085a1153ec5591e11d6e18bc569d4468fa7e..e27697649ba2ff27cdfe4fb5effccce5e118fa7b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,9 @@ fetchmail-1.0 (Mon Sep 23 19:54:01 EDT 1996):
 
 * Name change (it ain't just for POP3 any more).
 
+* Stricter RFC822 conformance, so SMTP to qmail works.  Thanks to
+  Cameron MacPherson <unsound@oz.net> for these changes.
+
 popclient-3.2 (Mon Sep 23 13:29:46 EDT 1996):
 
 * RPOP support (coded at a user's request but untested).
index 6ab0dd0f831e25d494426a2a0704091a2bb431b7..177f67b9961863bc0b7fd1a6fa63c9aa06eeed8e 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -223,8 +223,10 @@ closeUp:
        if (closeuserfolder(mboxfd) < 0 && ok == 0)
            ok = PS_IOERR;
     }
-    else if (queryctl->output == TO_SMTP && mboxfd  > 0)
+    else if (queryctl->output == TO_SMTP && mboxfd > 0) {
+       SMTP_quit(mboxfd);
        close(mboxfd);
+    }
 
     if (ok == PS_IOERR || ok == PS_SOCKET) 
        perror("do_protocol: cleanUp");
@@ -598,7 +600,7 @@ int rewrite;
            if (delimited && *bufp == 0)
                break;  /* end of message */
        }
-       strcat(bufp,"\n");
+       strcat(bufp, output == TO_SMTP && !inheaders ? "\r\n" : "\n");
      
        if (inheaders)
         {
diff --git a/smtp.c b/smtp.c
index d96e324860ea5ef6701d2b526d994a49d6ae26d3..657d9373f3f4fc71cc96173e7e4ad66178952f92 100644 (file)
--- a/smtp.c
+++ b/smtp.c
@@ -7,6 +7,7 @@
   module:       smtp.c
   project:      fetchmail
   programmer:   Harry Hochheiser
+                cleaned up and made rfc821 compliant by Cameron MacPherson
   description:  Handling of SMTP connections, and processing of mail 
                  to be forwarded via SMTP connections.
 
 int SMTP_helo(int socket,char *host)
 {
   int ok;
-  char buf[SMTPBUFSIZE+1];
 
-  sprintf(buf,"HELO %s",host);
-  SockPuts(socket, buf);
+  SockPrintf(socket,"HELO %s\r\n", host);
   if (outlevel == O_VERBOSE)
-      fprintf(stderr, "SMTP> %s\n", buf);
-  ok = SMTP_ok(socket,buf);
+      fprintf(stderr, "SMTP> HELO %s\n", host);
+  ok = SMTP_ok(socket,NULL);
   return ok;
 }
 
-
 /*********************************************************************
   function:      SMTP_from
   description:   Send a "MAIL FROM:" message to the SMTP server.
@@ -61,17 +59,15 @@ int SMTP_helo(int socket,char *host)
  *********************************************************************/
 int SMTP_from(int socket, char *from)
 {
-  char buf[SMTPBUFSIZE+1];  /* it's as good as size as any... */
   int ok;
-  SockPrintf(socket, "MAIL FROM: %s\n", from);
-  if (outlevel == O_VERBOSE)
-      fprintf(stderr, "SMTP> MAIL FROM: %s\n", from);
-  ok = SMTP_ok(socket,buf);
 
+  SockPrintf(socket,"MAIL FROM:<%s>\r\n", from);
+  if (outlevel == O_VERBOSE)
+      fprintf(stderr, "SMTP> MAIL FROM:<%s>\n", from);
+  ok = SMTP_ok(socket,NULL);
   return ok;
 }
 
-
 /*********************************************************************
   function:      SMTP_rcpt
   description:   Send a "RCPT TO:" message to the SMTP server.
@@ -86,18 +82,15 @@ int SMTP_from(int socket, char *from)
  *********************************************************************/
 int SMTP_rcpt(int socket,char *to)
 {
-  char buf[SMTPBUFSIZE+1];  /* it's as good as size as any... */
   int ok;
 
-  SockPrintf(socket, "RCPT TO: %s\n", to);
+  SockPrintf(socket,"RCPT TO:<%s>\r\n", to);
   if (outlevel == O_VERBOSE)
-      fprintf(stderr, "SMTP> RCPT TO: %s\n", to);
-  ok = SMTP_ok(socket,buf);
-  
+      fprintf(stderr, "SMTP> RCPT TO:<%s>\n", to);
+  ok = SMTP_ok(socket,NULL);
   return ok;
 }
 
-
 /*********************************************************************
   function:      SMTP_data
   description:   Send a "DATA" message to the SMTP server.
@@ -110,11 +103,31 @@ int SMTP_data(int socket)
 {
   int ok;
 
-  SockPrintf(socket,"DATA\n");
+  SockPrintf(socket,"DATA\r\n");
   if (outlevel == O_VERBOSE)
       fprintf(stderr, "SMTP> DATA\n");
-  ok = SMTP_ok(socket, NULL);
-  
+  ok = SMTP_ok(socket,NULL);
+  return ok;
+}
+
+/*********************************************************************
+  function:      SMTP_quit
+  description:   Send a "QUIT" message to the SMTP server.
+
+  arguments:     
+    socket       TCP/IP socket for connection to SMTP
+
+  return value:  Result of SMTP_OK: based on codes in fetchmail.h.
+
+ *********************************************************************/
+int SMTP_quit(int socket)
+{
+  int ok;
+
+  SockPrintf(socket,"QUIT\r\n");
+  if (outlevel == O_VERBOSE)
+      fprintf(stderr, "SMTP> QUIT\n");
+  ok = SMTP_ok(socket,NULL);
   return ok;
 }
 
@@ -132,7 +145,7 @@ int SMTP_eom(int socket)
 {
   int ok;
 
-  SockPuts(socket,".");
+  SockPrintf(socket,".\r\n");
   if (outlevel == O_VERBOSE)
       fprintf(stderr, "SMTP> (EOM)\n");
   ok = SMTP_ok(socket,NULL);
@@ -141,7 +154,7 @@ int SMTP_eom(int socket)
 
 /*********************************************************************
   function:      SMTP_rset
-  description:   Send an "RSET" message to the SMTP server.
+  description:   Send a "RSET" message to the SMTP server.
 
   arguments:     
     socket       TCP/IP socket for connection to SMTP
@@ -149,7 +162,7 @@ int SMTP_eom(int socket)
  *********************************************************************/
 void SMTP_rset(int socket)
 {
-  SockPrintf(socket,"RSET\n");
+  SockPrintf(socket,"RSET\r\n");
   if (outlevel == O_VERBOSE)
       fprintf(stderr, "SMTP> RSET\n");
 }
@@ -193,7 +206,6 @@ static int SMTP_check(int socket,char *argbuf)
 int SMTP_ok(int socket,char *argbuf)
 {
   int  ok;  
-  char buf[SMTPBUFSIZE+1];
 
   /* I can tell that the SMTP server connection is ok if I can read a
      status message that starts with "1xx" ,"2xx" or "3xx".
@@ -230,4 +242,3 @@ int SMTP_Gets(int socket,char *buf,int sz)
 {
   return read(socket,buf,sz);
 }
-
diff --git a/smtp.h b/smtp.h
index 10a3bb7dbabffebdd73f2132191a3bba506e1f87..7ee1893d090be237aa7d33db765d0667098837c2 100644 (file)
--- a/smtp.h
+++ b/smtp.h
@@ -26,6 +26,7 @@ int SMTP_from(int socket,char *from);
 int SMTP_rcpt(int socket,char *to);
 int SMTP_data(int socket);
 int SMTP_eom(int socket);
+int SMTP_quit(int socket);
 int SMTP_ok(int socket,char *argbuf);
 int SMTP_Gets(int socket,char *buf,int sz);
 void SMTP_rset(int socket);