diff -Naur vpopmail-5.2.orig/Makefile.am vpopmail-5.2/Makefile.am
--- vpopmail-5.2.orig/Makefile.am	Wed Jan 23 15:02:21 2002
+++ vpopmail-5.2/Makefile.am	Thu Feb 14 12:46:30 2002
@@ -4,7 +4,7 @@
 
 noinst_LIBRARIES=libvpopmail.a
 
-COMMONSOURCES=vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c
+COMMONSOURCES=vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c seek.c
 CONFIG_CLEAN_FILES=vauth.c
 
 libvpopmail_a_SOURCES=$(COMMONSOURCES) 
diff -Naur vpopmail-5.2.orig/Makefile.in vpopmail-5.2/Makefile.in
--- vpopmail-5.2.orig/Makefile.in	Mon Feb  4 18:34:24 2002
+++ vpopmail-5.2/Makefile.in	Thu Feb 14 12:46:30 2002
@@ -76,7 +76,7 @@
 
 noinst_LIBRARIES = libvpopmail.a
 
-COMMONSOURCES = vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c
+COMMONSOURCES = vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c seek.c
 CONFIG_CLEAN_FILES = vauth.c
 
 libvpopmail_a_SOURCES = $(COMMONSOURCES) 
@@ -165,7 +165,7 @@
 LIBS = @LIBS@
 libvpopmail_a_DEPENDENCIES =  cdb/*.o
 libvpopmail_a_OBJECTS =  vpopmail.o md5.o bigdir.o vauth.o file_lock.o \
-vpalias.o
+vpalias.o seek.o
 AR = ar
 PROGRAMS =  $(vpopmailbin_PROGRAMS)
 
diff -Naur vpopmail-5.2.orig/seek.c vpopmail-5.2/seek.c
--- vpopmail-5.2.orig/seek.c	Thu Jan  1 01:00:00 1970
+++ vpopmail-5.2/seek.c	Thu Feb 14 12:46:30 2002
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 1987 University of Maryland Computer Science Department.
+ * All rights reserved.
+ * Permission to copy for any purpose is hereby granted so long as this
+ * copyright notice remains intact.
+ *
+ * Changed MakeSeekable to use tmpfile() - marcus@quintic.co.uk
+ */
+
+/*
+ * Seekable is a predicate which returns true iff a Unix fd is seekable.
+ *
+ * MakeSeekable forces an input stdio file to be seekable, by copying to
+ * a temporary file if necessary.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+
+long	lseek();
+char	*getenv();
+
+int
+Seekable(fd)
+	int fd;
+{
+
+	return (lseek(fd, 0L, 1) >= 0 && !isatty(fd));
+}
+
+int
+MakeSeekable(f)
+	register FILE *f;
+{
+	register int tf, n;
+	FILE *tmpf;
+	int blksize;
+#ifdef MAXBSIZE
+	char buf[MAXBSIZE];
+	struct stat st;
+#else
+	char buf[BUFSIZ];
+#endif
+
+	if (Seekable(fileno(f)))
+		return (0);
+
+	tmpf = tmpfile(); /* tmpfile() is not safe on all systems */
+        tf = fileno(tmpf);
+
+	/* copy from input file to temp file */
+#ifdef MAXBSIZE
+	if (fstat(tf, &st))	/* how can this ever fail? */
+		blksize = MAXBSIZE;
+	else
+		blksize = MIN(MAXBSIZE, st.st_blksize);
+#else
+	blksize = BUFSIZ;
+#endif
+	while ((n = fread(buf, 1, blksize, f)) > 0) {
+		if (write(tf, buf, n) != n) {
+			(void) close(tf);
+			return (-1);
+		}
+	}
+	/* ferror() is broken in Ultrix 1.2; hence the && */
+	if (ferror(f) && !feof(f)) {
+		(void) close(tf);
+		return (-1);
+	}
+
+	/*
+	 * Now switch f to point at the temp file.  Since we hit EOF, there
+	 * is nothing in f's stdio buffers, so we can play a dirty trick: 
+	 */
+	clearerr(f);
+	if (dup2(tf, fileno(f))) {
+		(void) close(tf);
+		return (-1);
+	}
+	(void) close(tf);
+	return (0);
+}
diff -Naur vpopmail-5.2.orig/seek.h vpopmail-5.2/seek.h
--- vpopmail-5.2.orig/seek.h	Thu Jan  1 01:00:00 1970
+++ vpopmail-5.2/seek.h	Thu Feb 14 12:46:30 2002
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 1987 University of Maryland Computer Science Department.
+ * All rights reserved.
+ * Permission to copy for any purpose is hereby granted so long as this
+ * copyright notice remains intact.
+ */
+
+/*
+ * Seekable is a predicate which returns true iff a Unix fd is seekable.
+ *
+ * MakeSeekable forces an input stdio file to be seekable, by copying to
+ * a temporary file if necessary.
+ */
+
+int Seekable(int fd);
+int MakeSeekable(register FILE *f);
diff -Naur vpopmail-5.2.orig/vdelivermail.c vpopmail-5.2/vdelivermail.c
--- vpopmail-5.2.orig/vdelivermail.c	Sat Feb  2 05:41:56 2002
+++ vpopmail-5.2/vdelivermail.c	Thu Feb 14 12:46:30 2002
@@ -36,6 +36,7 @@
 #include "vpopmail.h"
 #include "vauth.h"
 #include "maildirquota.h"
+#include "seek.h"
 
 /* Globals */
 #define AUTH_SIZE 300
@@ -401,6 +402,10 @@
         printf("message is looping %s\n", address );
         return(-3);
     }
+    
+    /* at this point we know the message size - if its 0 drop out silently */
+    if (message_size==0)
+        return(0);
 
     /* Contains /Maildir/ ? Then it must be a full or relative
      * path to a Maildir 
@@ -504,6 +509,9 @@
                 "%sDelivered-To: %s\n", getenv("RPLINE"), dtline);
     }
 
+    if (!Seekable(0))
+        MakeSeekable(stdin);
+
     if ( lseek(0, 0L, SEEK_SET) < 0 ) {
         printf("lseek errno=%d\n", errno);
         return(errno);
@@ -685,6 +693,9 @@
  while (*prog==' ') ++prog;
  while (*prog=='|') ++prog;
 
+    if (!Seekable(0))
+        MakeSeekable(stdin);
+
     if ( lseek(0, 0L, SEEK_SET) < 0 ) {
         printf("lseek errno=%d\n", errno);
         return;
@@ -735,6 +746,9 @@
       return(1);
     }
 
+    if (!Seekable(0))
+        MakeSeekable(stdin);
+
     lseek(0,0L,SEEK_SET);
     while(fgets(loop_buf,sizeof(loop_buf),stdin)!=NULL){
 
@@ -801,6 +815,9 @@
 {
  ssize_t message_size;
  ssize_t bytes;
+
+    if (!Seekable(0))
+        MakeSeekable(stdin);
 
     if ( lseek(0, 0L,SEEK_SET) < 0 ) {
         printf("lseek error %d\n", errno);

