--- man/procmail.man	Tue Sep 11 06:54:43 2001
+++ man/procmail.man	Sun Mar 30 21:13:44 2003
@@ -166,7 +166,8 @@
 accept an unlimited number of arguments.@ETCRCS_desc@
 For some advanced usage of this option you should look in the
 .B EXAMPLES
-section below.@LMTPOPTdesc@.SH ARGUMENTS
+section below.@LMTPOPTdesc@
+.SH ARGUMENTS
 Any arguments containing an '=' are considered to be environment variable
 assignments, they will
 .I all
@@ -720,6 +721,15 @@
 .na
 .nf
 @FW_content@
+.fi
+.ad
+.PP
+Some mailers (notably exim) do not currently accept the above syntax.
+In such case use this instead:
+.PP
+.na
+.nf
+|/usr/bin/procmail
 .fi
 .ad
 .PP
--- man/procmailrc.man	Tue Sep 11 06:55:03 2001
+++ man/procmailrc.man	Sun Mar 30 21:13:44 2003
@@ -779,7 +779,7 @@
 .PP
 Some non-optimal and non-obvious regexps set MATCH to an incorrect
 value.  The regexp can be made to work by removing one or more unneeded
-'*', '+', or '?' operator on the left-hand side of the \e/ token.
+\&'*', '+', or '?' operator on the left-hand side of the \e/ token.
 .SH MISCELLANEOUS
 If the regular expression contains `\fB@TO_key@\fP' it will be substituted by
 .na
--- new/mailstat.1	Thu Jan  1 01:00:00 1970
+++ new/mailstat.1	Sun Mar 30 21:13:44 2003
@@ -0,0 +1,40 @@
+.TH MAILSTAT 1
+.SH NAME
+mailstat \- shows mail-arrival statistics
+.SH SYNOPSIS
+.B mailstat
+[\-klmots] [logfile]
+.SH DESCRIPTION
+.B mailstat
+parses a procmail-generated $LOGFILE and displays
+a summary about the messages delivered to all folders
+(total size, average size, nr of messages).
+The $LOGFILE is truncated to zero length, unless the
+.B -k
+option is used.
+Exit code 0 if mail arrived, 1 if no mail arrived.
+.SH OPTIONS
+.TP
+.I \-k
+keep logfile intact
+.TP
+.I \-l
+long display format
+.TP
+.I \-m
+merge any errors into one line
+.TP
+.I \-o
+use the old logfile
+.TP
+.I \-t
+terse display format
+.TP
+.I \-s
+silent in case of no mail
+.SH NOTES
+Customise to your heart's content, this program is only provided as a
+guideline.
+.SH AUTHOR
+This manual page was written by Santiago Vila <sanvila@debian.org>
+for the Debian GNU/Linux distribution (but may be used by others).
--- src/comsat.c	Tue Sep 11 06:55:46 2001
+++ src/comsat.c	Sun Mar 30 21:13:45 2003
@@ -92,7 +92,7 @@
    }
   if(newvalid)						  /* so far, so good */
    { int s;
-     if(!*chp)						       /* no service */
+     if(!chad||!*chp)					       /* no service */
 	chp=BIFF_serviceport;				/* new balls please! */
      s=strtol(chp,&chad,10);
      if(chp!=chad)			       /* the service is not numeric */
@@ -120,7 +120,7 @@
 { int s;const char*p;
   if(!csvalid||!buf)		  /* is comat on and set to a valid address? */
      return;
-  if(!*cslgname||strlen(cslgname)+2>linebuf)	       /* is $LOGNAME bogus? */
+  if(!cslgname||!*cslgname||strlen(cslgname)+2>linebuf)/* is $LOGNAME bogus? */
      return;
   if(!(p=folder?folder:cslastf))		     /* do we have a folder? */
      return;
--- src/foldinfo.h	Tue Dec  5 07:34:25 2000
+++ src/foldinfo.h	Sun Mar 30 21:13:45 2003
@@ -10,7 +10,7 @@
 
 #define ft_lock(type)	   ((type)>ft_MAILDIR)		   /* kernel lock fd */
 #define ft_atime(type)	   ((type)==ft_FILE)	      /* force atime < mtime */
-#define ft_dotlock(type)   ((type)==ft_FILE)		 /* dotlock $DEFAULT */
+#define ft_dotlock(type)   ((type)>ft_MAILDIR)		 /* dotlock $DEFAULT */
 #define ft_delim(type)	   ((type)==ft_FILE)		   /* add MMDF delim */
 #define ft_checkcloser(type) ((type)>ft_MH)
 #define ft_forceblank(type) ((type)!=ft_MAILDIR)  /* force blank line at end */
--- src/mailfold.c	Tue Sep 11 06:58:34 2001
+++ src/mailfold.c	Sun Mar 30 21:13:45 2003
@@ -378,7 +378,8 @@
 	dfilled=mailread=0;
      else if(rhead)				/* only read in a new header */
       { memblk new;
-	dfilled=mailread=0;makeblock(&new,0);readdyn(&new,&dfilled,0);
+	dfilled=mailread=0;makeblock(&new,0);
+	readdyn(&new,&dfilled,thebody-themail.p);
 	if(tobesent>dfilled&&isprivate)		     /* put it in place here */
 	 { tmemmove(themail.p+dfilled,thebody,filled-=tobesent);
 	   tmemmove(themail.p,new.p,dfilled);
--- src/manconf.c	Tue Sep 11 06:58:34 2001
+++ src/manconf.c	Sun Mar 30 21:13:44 2003
@@ -139,7 +139,7 @@
 sh before procmail ever sees it; it is however a necessary kludge against\1\
 overoptimising sendmail programs:\1");
 #else
-  ps("FW_content","\"|exec @BINDIR@/procmail\"");
+  ps("FW_content","\"|exec @BINDIR@/procmail || exit 75\"");
   ps("FW_comment","");
 #endif
 #else
@@ -233,7 +233,7 @@
  \2-@PRESERVOPT@\1and\1.BR \2-@FROMWHOPT@ .\1");
   pc("LMTPOPT",LMTPOPT);
 #else
-  ps("LMTPOPTdesc","");ps("LMTPusage","");
+  ps("LMTPOPTdesc","");ps("LMTPusage","\1");
 #endif
   pname("INIT_UMASK",0);printf("0%lo/g\n",(unsigned long)INIT_UMASK);lines--;
   pn("DEFlinebuf",DEFlinebuf);
--- src/memblk.c	Fri Jun 29 04:20:56 2001
+++ src/memblk.c	Sun Mar 30 21:13:44 2003
@@ -51,11 +51,11 @@
 {
 #ifdef USE_MMAP
   if(mb->fd>=0)
-   { long len=mb->len+1;
-     if(munmap(mb->p,len))
-	mmapfailed(len);		      /* don't want to continue here */
-     if((mb->p=mmap(0,len,PROT_READ,MAP_PRIVATE,mb->fd,(off_t)0))==MAP_FAILED)
-	mmapfailed(len);
+   { long mlen=mb->len+1;
+     if(munmap(mb->p,mlen))
+	mmapfailed(mlen);		      /* don't want to continue here */
+     if((mb->p=mmap(0,mlen,PROT_READ,MAP_PRIVATE,mb->fd,(off_t)0))==MAP_FAILED)
+	mmapfailed(mlen);
      close(mb->fd);
      mb->fd=ropen(devnull,O_RDWR,0);		/* XXX Perhaps -1 is better? */
    }
@@ -77,8 +77,8 @@
      strcpy(filename,MMAP_DIR);
      if(unique(filename,strchr(filename,'\0'),MMAP_FILE_LEN,MMAP_PERM,0,0)&&
 	(mb->fd=ropen(filename,O_RDWR,MMAP_PERM),unlink(filename),mb->fd>=0))
-      { mb->filelen=len;
-	if(lseek(mb->fd,mb->filelen-1,SEEK_SET)<0||1!=rwrite(mb->fd,empty,1))
+      { mb->filelen=len+1;
+	if(lseek(mb->fd,len,SEEK_SET)<0||1!=rwrite(mb->fd,empty,1))
 dropf:	 { close(mb->fd);mb->fd= -1;
 	   if(verbose)nlog("Unable to extend or use tempfile");
 	 }
@@ -98,9 +98,9 @@
       }
    }
   if(mb->fd>=0)
-   { if(len>mb->filelen)				  /* need to extend? */
-      { mb->filelen=len;
-	if(lseek(mb->fd,mb->filelen-1,SEEK_SET)<0||1!=rwrite(mb->fd,empty,1))
+   { if(len>=mb->filelen)				  /* need to extend? */
+      { mb->filelen=len+1;
+	if(lseek(mb->fd,len,SEEK_SET)<0||1!=rwrite(mb->fd,empty,1))
 	 { char*p=malloc(len+1);	   /* can't extend, switch to malloc */
 	   tmemmove(p,mb->p,mb->len);
 	   munmap(mb->p,mb->len+1);
@@ -124,9 +124,9 @@
    }
   else
      mb->p=realloc(mb->p,len+1);
-  mb->len=len+1;
-  mb->p[len]='\0';
+  mb->len=len;
 ret1:
+  mb->p[len]='\0';
   return 1;
 }
 
--- src/memblk.h	Sat Jun 30 06:12:18 2001
+++ src/memblk.h	Sun Mar 30 21:13:44 2003
@@ -1,6 +1,6 @@
 typedef struct memblk {
     char*p;						  /* where it starts */
-    long len;					 /* currently allocated size */
+    long len;			 /* current size, not including trailing NUL */
 #ifdef USE_MMAP
     off_t filelen;				     /* how long is the file */
     int fd;					   /* file which is mmap()ed */
--- src/pipes.c	Tue Sep 11 06:58:44 2001
+++ src/pipes.c	Sun Mar 30 21:13:45 2003
@@ -145,7 +145,9 @@
   if(Stdout)
    { *(eq=strchr(Stdout,'\0')-1)='\0';			     /* chop the '=' */
      if(!(backblock=getenv(Stdout)))			/* no current value? */
-	PRDB=PWRB= -1;
+      { PRDB=PWRB= -1;
+	backlen=0;
+      }
      else
       { backlen=strlen(backblock);
 	goto pip;
@@ -155,9 +157,7 @@
 pip: rpipe(pbackfd);
   rpipe(pinfd);						 /* main pipes setup */
   if(!(pidchild=sfork()))			/* create a sending procmail */
-   { if(Stdout&&backblock)
-	backlen=strlen(backblock);
-     else
+   { if(!Stdout)
 	backblock=source,backlen=len;
      childsetup();rclose(PRDI);rclose(PRDB);
      rpipe(poutfd);rclose(STDOUT);
@@ -194,7 +194,7 @@
      makeblock(&temp,Stdfilled);
      tmemmove(temp.p,Stdout,Stdfilled);
      readdyn(&temp,&Stdfilled,Stdfilled+backlen+1);
-     Stdout=realloc(Stdout,&Stdfilled+1);
+     Stdout=realloc(Stdout,Stdfilled+1);
      tmemmove(Stdout,temp.p,Stdfilled+1);
      freeblock(&temp);
      retStdout(Stdout,pwait&&pipw,!backblock);
--- src/procmail.c	Tue Sep 11 06:59:14 2001
+++ src/procmail.c	Sun Mar 30 21:13:45 2003
@@ -652,8 +652,7 @@
 	      nrcond= -1;
 	   if(tolock)		 /* clear temporary buffer for lockfile name */
 	      free(tolock);
-	   for(i=maxindex(flags);i;i--)			  /* clear the flags */
-	      flags[i]=0;
+	   bbzero(flags,sizeof(flags));		  /* clear the flags */
 	   for(tolock=0,locknext=0;;)
 	    { chp=skpspace(chp);
 	      switch(i= *chp++)
