X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fspool_mbox.c;h=12cf3d43eaf58b7c33ed96575cad8403b1979ef5;hb=ac6652c8a0ac69fc0f46d7f8535aa537cd609c94;hp=42a2fe17176666eb3c96323992e8d6a3d3e04a25;hpb=c5537c6e21da5c92ab74fc567f663becc59d3f07;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/spool_mbox.c b/src/src/spool_mbox.c index 42a2fe171..12cf3d43e 100644 --- a/src/src/spool_mbox.c +++ b/src/src/spool_mbox.c @@ -1,5 +1,3 @@ -/* $Cambridge: exim/src/src/spool_mbox.c,v 1.14 2008/01/16 09:56:55 tom Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ @@ -25,9 +23,10 @@ extern int spam_ok; int spool_mbox_ok = 0; uschar spooled_message_id[17]; -/* returns a pointer to the FILE, and puts the size in bytes into mbox_file_size */ +/* returns a pointer to the FILE, and puts the size in bytes into mbox_file_size + * normally, source_file_override is NULL */ -FILE *spool_mbox(unsigned long *mbox_file_size) { +FILE *spool_mbox(unsigned long *mbox_file_size, uschar *source_file_override) { uschar message_subdir[2]; uschar buffer[16384]; uschar *temp_string; @@ -57,7 +56,7 @@ FILE *spool_mbox(unsigned long *mbox_file_size) { mbox_file = modefopen(mbox_path, "wb", SPOOL_MODE); if (mbox_file == NULL) { log_write(0, LOG_MAIN|LOG_PANIC, "%s", string_open_failed(errno, - "scan file %s", mbox_file)); + "scan file %s", mbox_path)); goto OUT; }; @@ -97,16 +96,24 @@ FILE *spool_mbox(unsigned long *mbox_file_size) { }; /* End headers */ - (void)fwrite("\n", 1, 1, mbox_file); + if (fwrite("\n", 1, 1, mbox_file) != 1) { + log_write(0, LOG_MAIN|LOG_PANIC, "Error/short write while writing \ + message headers to %s", mbox_path); + goto OUT; + } /* copy body file */ - message_subdir[1] = '\0'; - for (i = 0; i < 2; i++) { - message_subdir[0] = (split_spool_directory == (i == 0))? message_id[5] : 0; - temp_string = string_sprintf("%s/input/%s/%s-D", spool_directory, - message_subdir, message_id); - data_file = Ufopen(temp_string, "rb"); - if (data_file != NULL) break; + if (source_file_override == NULL) { + message_subdir[1] = '\0'; + for (i = 0; i < 2; i++) { + message_subdir[0] = (split_spool_directory == (i == 0))? message_id[5] : 0; + temp_string = string_sprintf("%s/input/%s/%s-D", spool_directory, + message_subdir, message_id); + data_file = Ufopen(temp_string, "rb"); + if (data_file != NULL) break; + }; + } else { + data_file = Ufopen(source_file_override, "rb"); }; if (data_file == NULL) { @@ -125,7 +132,8 @@ FILE *spool_mbox(unsigned long *mbox_file_size) { * explicitly, because the one in the file is parted of the locked area. */ - (void)fseek(data_file, SPOOL_DATA_START_OFFSET, SEEK_SET); + if (!source_file_override) + (void)fseek(data_file, SPOOL_DATA_START_OFFSET, SEEK_SET); do { j = fread(buffer, 1, sizeof(buffer), data_file); @@ -151,7 +159,7 @@ FILE *spool_mbox(unsigned long *mbox_file_size) { if (Ustat(mbox_path, &statbuf) != 0 || (yield = Ufopen(mbox_path,"rb")) == NULL) { log_write(0, LOG_MAIN|LOG_PANIC, "%s", string_open_failed(errno, - "scan file %s", mbox_file)); + "scan file %s", mbox_path)); goto OUT; }; @@ -188,6 +196,12 @@ void unspool_mbox(void) { mbox_path = string_sprintf("%s/scan/%s", spool_directory, spooled_message_id); tempdir = opendir(CS mbox_path); + if (!tempdir) { + debug_printf("Unable to opendir(%s): %s\n", mbox_path, strerror(errno)); + /* Just in case we still can: */ + rmdir(CS mbox_path); + return; + } /* loop thru dir & delete entries */ while((entry = readdir(tempdir)) != NULL) { uschar *name = US entry->d_name;