]> Pileus Git - ~andy/fetchmail/commitdiff
One step towards proper continuation handling.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 16 Jan 1997 03:29:34 +0000 (03:29 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 16 Jan 1997 03:29:34 +0000 (03:29 -0000)
svn path=/trunk/; revision=774

driver.c
socket.c
socket.h

index 531b6f73f5cdbd312407dac4652635ce5a08feb1..c0901c8c0ece03656e15d71c5f74bbaca9cb63c6 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -329,7 +329,7 @@ char *realname;             /* real name of host */
     char buf [MSGBUFSIZE+1]; 
     char *bufp, *headers, *fromhdr,*tohdr,*cchdr,*bcchdr,*received_for,*envto;
     char *fromptr, *toptr;
-    int n, oldlen;
+    int n, oldlen, ch;
     int inheaders,lines,sizeticker;
     FILE *sinkfp;
     RETSIGTYPE (*sigchld)();
@@ -345,10 +345,17 @@ char *realname;           /* real name of host */
     oldlen = 0;
     while (delimited || len > 0)
     {
-       if (!SockGets(buf,sizeof(buf),sockfp))
-           return(PS_SOCKET);
+       buf[0] = '\0';
+       do {
+           if (!SockGets(buf+strlen(buf), sizeof(buf)-strlen(buf)-1, sockfp))
+               return(PS_SOCKET);
+           vtalarm(ctl->server.timeout);
+       } while
+           /* we may need to grab RFC822 continuations */
+           (inheaders && (ch = SockPeek(sockfp)) == ' ' || ch == '\t');
+
+       /* compute length *before* squeezing out CRs */
        n = strlen(buf);
-       vtalarm(ctl->server.timeout);
 
        /* squeeze out all carriage returns */
        for (fromptr = toptr = buf; *fromptr; fromptr++)
index 734321fc42e4a04821e2bd135ed4dca1321e9c65..6b2076e724db5f61d57ca369bc6f3fe38550f29d 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -136,6 +136,18 @@ char *SockGets(char *buf, int len, FILE *sockfp)
     return buf;
 }
 
+int SockPeek(FILE *sockfp)
+/* peek at the next socket character without actually reading it */
+{
+    int n;
+    char ch;
+
+    if ((n = recv(fileno(sockfp), &ch, 1, MSG_PEEK)) == -1)
+       return -1;
+    else
+       return(ch);
+}
+
 #ifdef MAIN
 /*
  * Use the chargen service to test input beuffering directly.
index 6c93c6348e68d8cdfa2187f47bac1f9ce13ce188..f84f5b4dc14de901dbe8f512d1e7156323855313 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -18,6 +18,11 @@ returns buffer on success, NULL on failure.
 */
 char *SockGets(char *buf, int len, FILE *sockfp);
 
+/*
+ * Peek at the next socket character without actually reading it.
+ */
+int SockPeek(FILE *sockfp);
+
 /*
 Write a chunk of bytes to the socket (matches interface of fwrite).
 Returns number of bytes successfully written.