diff -Naur mlmmj-1.2.13.org/src/do_all_the_voodo_here.c mlmmj-1.2.13/src/do_all_the_voodo_here.c
--- mlmmj-1.2.13.org/src/do_all_the_voodo_here.c	2007-02-26 09:55:32.000000000 +0100
+++ mlmmj-1.2.13/src/do_all_the_voodo_here.c	2007-02-26 12:26:57.000000000 +0100
@@ -75,28 +75,64 @@
 	}
 }
 
+/* append a string to a stringlist */
+static void append_strtolist(struct strlist *list, char* str)
+{
+	list->count++;
+	list->strs = myrealloc(list->strs,
+		sizeof(char *) * (list->count + 1));
+	list->strs[list->count-1] = mystrdup(str);
+	list->strs[list->count] = NULL;  /* XXX why, why, why? */
+}
+
+
+/* get a copy of all headers */
+static int gethdrs(int infd, struct strlist *allhdrs)
+{
+	char* hdrline;
+	while((hdrline = gethdrline(infd))) {
+
+		/* Done with headers?*/
+		if((strlen(hdrline) == 1) && (hdrline[0] == '\n')) {
+			myfree(hdrline);
+			break;
+		}
+
+		/* Snatch a copy of the header */
+		append_strtolist(allhdrs,hdrline);
+
+		myfree(hdrline);
+
+	}
+	return 0;
+}
+
+
+
 int do_all_the_voodo_here(int infd, int outfd, int hdrfd, int footfd,
 		 const char **delhdrs, struct mailhdr *readhdrs,
 		 struct strlist *allhdrs, const char *prefix)
 {
-	char *hdrline, *subject, *unqp;
+	char *subject, *unqp;
 	int hdrsadded = 0;
 	int subject_present = 0;
+	int i;
 
 	allhdrs->count = 0;
 	allhdrs->strs = NULL;
 
-	while((hdrline = gethdrline(infd))) {
-		/* Done with headers? Then add extra if wanted*/
-		if((strncasecmp(hdrline, "mime", 4) == 0) ||
-			((strlen(hdrline) == 1) && (hdrline[0] == '\n'))){
+	/* copy headers */
+	gethdrs(infd,allhdrs);
 
+	/* write headers */
+	for(i = 0 ; i < allhdrs->count ; i++) {
+		char* hdrline = allhdrs->strs[i];
+		if(strncasecmp(hdrline, "mime", 4) == 0) {
 			/* add extra headers */
 			if(!hdrsadded && hdrfd >= 0) {
 				if(dumpfd2fd(hdrfd, outfd) < 0) {
 					log_error(LOG_ARGS, "Could not "
 						"add extra headers");
-					myfree(hdrline);
 					return -1;
 				} else
 					hdrsadded = 1;
@@ -104,41 +140,11 @@
 			
 			fsync(outfd);
 
-			/* end of headers, write single LF */ 
-			if(hdrline[0] == '\n') {
-				/* but first add Subject if none is present
-				 * and a prefix is defined */
-				if (prefix && !subject_present)
-				{
-					subject = concatstr(3, "Subject: ", 
-								prefix, "\n");
-					writen(outfd, subject, strlen(subject));
-					myfree(subject);
-					subject_present = 1;
-				}
-
-				if(writen(outfd, hdrline, strlen(hdrline))
-						< 0) {
-					myfree(hdrline);
-					log_error(LOG_ARGS,
-							"Error writing hdrs.");
-					return -1;
-				}
-				myfree(hdrline);
-				break;
-			}
 		}
 		/* Do we want info from hdrs? Get it before it's gone */
 		if(readhdrs)
 			getinfo(hdrline, readhdrs);
 
-		/* Snatch a copy of the header */
-		allhdrs->count++;
-		allhdrs->strs = myrealloc(allhdrs->strs,
-					sizeof(char *) * (allhdrs->count + 1));
-		allhdrs->strs[allhdrs->count-1] = mystrdup(hdrline);
-		allhdrs->strs[allhdrs->count] = NULL;  /* XXX why, why, why? */
-
 		/* Add Subject: prefix if wanted */
 		if(prefix) {
 			if(strncasecmp(hdrline, "Subject:", 8) == 0) {
@@ -152,7 +158,6 @@
 					writen(outfd, subject,
 							strlen(subject));
 					myfree(subject);
-					myfree(hdrline);
 					myfree(unqp);
 					continue;
 				}
@@ -166,9 +171,36 @@
 				writen(outfd, hdrline, strlen(hdrline));
 		} else
 			writen(outfd, hdrline, strlen(hdrline));
+	}
 
 
-		myfree(hdrline);
+	/* add extra headers */
+	if(!hdrsadded && hdrfd >= 0) {
+		if(dumpfd2fd(hdrfd, outfd) < 0) {
+			log_error(LOG_ARGS, "Could not "
+                                            "add extra headers");
+			return -1;
+		} else
+			hdrsadded = 1;
+	}
+
+	fsync(outfd);
+
+	/* end of headers, write single LF */
+	/* but first add Subject if none is present
+	 * and a prefix is defined */
+	if (prefix && !subject_present)
+	{
+		subject = concatstr(3, "Subject: ",
+       					prefix, "\n");
+		writen(outfd, subject, strlen(subject));
+		myfree(subject);
+		subject_present = 1;
+	}
+
+	if(writen(outfd, "\n", 1) < 0) {
+		log_error(LOG_ARGS,"Error writing hdrs.");
+			return -1;
 	}
 
 	/* Just print the rest of the mail */


