a735c0
--- procmail-3.22/src/mailfold.c.truncate	2007-03-27 13:24:05.000000000 +0200
a735c0
+++ procmail-3.22/src/mailfold.c	2007-03-27 13:25:06.000000000 +0200
a735c0
@@ -30,6 +30,7 @@
a735c0
 
a735c0
 int logopened,rawnonl;
a735c0
 off_t lasttell;
a735c0
+static int trunced;
a735c0
 static long lastdump;
a735c0
 static volatile int mailread;	/* if the mail is completely read in already */
a735c0
 static struct dyna_array confield;		  /* escapes, concatenations */
a735c0
@@ -81,6 +82,7 @@
a735c0
  long len;
a735c0
 { int i;long part;
a735c0
   lasttell=i= -1;SETerrno(EBADF);
a735c0
+  trunced=0;
a735c0
   if(s>=0)
a735c0
    { if(ft_lock(type)&&(lseek(s,(off_t)0,SEEK_END),fdlock(s)))
a735c0
 	nlog("Kernel-lock failed\n");
a735c0
@@ -120,13 +122,18 @@
a735c0
       }
a735c0
 writefin:
a735c0
      i=type!=ft_PIPE&&fsync(s)&&errno!=EINVAL;	  /* EINVAL => wasn't a file */
a735c0
+     if ((i||len)&&lasttell>=0)
a735c0
+      { int serrno=errno;
a735c0
+	if(!ftruncate(s,lasttell)) trunced=1;
a735c0
+	SETerrno(serrno);
a735c0
+      }
a735c0
      if(ft_lock(type))
a735c0
       { int serrno=errno;		       /* save any error information */
a735c0
 	if(fdunlock())
a735c0
 	   nlog("Kernel-unlock failed\n");
a735c0
 	SETerrno(serrno);
a735c0
       }
a735c0
-     i=rclose(s)||i;
a735c0
+     i=rclose(s)||i; /* if this fails, we should truncate, but it's too late */
a735c0
    }			   /* return an error even if nothing was to be sent */
a735c0
   return i&&!len?-1:len;
a735c0
 }
a735c0
@@ -237,7 +244,7 @@
a735c0
 #endif
a735c0
 	      default:writeerr(buf);
a735c0
 	    }
a735c0
-	   if(lasttell>=0&&!truncate(boxname,lasttell)&&(logopened||verbose))
a735c0
+	   if(lasttell>=0&&trunced&&(logopened||verbose))
a735c0
 	      nlog("Truncated file to former size\n");	    /* undo garbage */
a735c0
 ret0:	   return 0;
a735c0
 	 }