diff options
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | local.c | 15 | ||||
-rw-r--r-- | message.c | 48 | ||||
-rw-r--r-- | message.h | 2 | ||||
-rw-r--r-- | smtp.c | 11 |
6 files changed, 47 insertions, 46 deletions
diff --git a/Makefile.am b/Makefile.am index 2f83b99..746d9ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,15 +20,7 @@ esmtp_SOURCES = \ xmalloc.h EXTRA_DIST = \ - sample.esmtprc \ - debian/changelog \ - debian/compat \ - debian/config \ - debian/control \ - debian/copyright \ - debian/postinst \ - debian/rules \ - debian/templates + sample.esmtprc AM_YFLAGS = -d @@ -1,11 +1,16 @@ News ~~~~ - * Version 0.4.1 (under development): + * Version 0.4.1 (2004-07-14): * Packaging fixes. * Esmtprc man page. + + * Fixed the MDA return status which wasn't being cheked. + + * Fixed a bug the input buffering which when using the '-t' option and + piping the input caused the parsed headers to be lost. * Version 0.4 (2003-07-12): @@ -9,6 +9,7 @@ #include <stdio.h> #include <string.h> #include <signal.h> +#include <sys/wait.h> #include "local.h" #include "main.h" @@ -191,7 +192,19 @@ void local_cleanup(void) { if(mda_fp) { - fclose(mda_fp); + int status; + + if((status = pclose(mda_fp))) + { + if(WIFSIGNALED(status)) + fprintf(stderr, "MDA died of signal %d\n", WTERMSIG(status)); + else if(WIFEXITED(status)) + fprintf(stderr, "MDA returned nonzero status %d\n", WEXITSTATUS(status)); + else + fprintf(stderr, "MDA failed\n"); + exit(EX_OSERR); + } + mda_fp = NULL; if(verbose) @@ -153,23 +153,17 @@ static void message_buffer_fill(message_t *message) FILE *fp = message->fp ? message->fp : stdin; size_t n; - if((n = fread(message->buffer + message->buffer_stop, 1, message->buffer_size - message->buffer_stop, fp))) - { - /* hook for the MDA pipe */ - if(mda_fp) - fwrite(message->buffer + message->buffer_stop, 1, n, mda_fp); - - message->buffer_stop += n; - } + message->buffer_stop += fread(message->buffer + message->buffer_stop, 1, message->buffer_size - message->buffer_stop, fp); } static size_t message_buffer_flush(message_t *message, char *ptr, size_t size) { - size_t count, n; + size_t count, n, s; char *p, *q; - p = message->buffer + message->buffer_start; + s = message->buffer_start; + p = message->buffer + s; count = 0; while(count < size && message->buffer_start < message->buffer_stop) { @@ -198,7 +192,7 @@ static size_t message_buffer_flush(message_t *message, char *ptr, size_t size) } if(count == size) - return count; + break; if(q) { @@ -210,7 +204,7 @@ static size_t message_buffer_flush(message_t *message, char *ptr, size_t size) if(count == size) { message->buffer_r = 1; - return count; + break; } } else @@ -222,6 +216,10 @@ static size_t message_buffer_flush(message_t *message, char *ptr, size_t size) } } + /* hook for the MDA pipe */ + if(mda_fp && message->buffer_start != s) + fwrite(message->buffer +s, 1, message->buffer_start - s, mda_fp); + if(message->buffer_start == message->buffer_stop) message->buffer_start = message->buffer_stop = 0; @@ -231,38 +229,28 @@ static size_t message_buffer_flush(message_t *message, char *ptr, size_t size) size_t message_read(message_t *message, char *ptr, size_t size) { size_t count = 0, n; + char *p = ptr; if(!message->buffer) message_buffer_alloc(message); - n = message_buffer_flush(message, ptr, size); + n = message_buffer_flush(message, p, size); count += n; - ptr += n; + p += n; while(count != size) { message_buffer_fill(message); - if(!(n = message_buffer_flush(message, ptr, size - count))) + if(!(n = message_buffer_flush(message, p, size - count))) break; count += n; - ptr += n; - + p += n; }; return count; } -void message_rewind(message_t *message) -{ - FILE *fp = message->fp ? message->fp : stdin; - - message->buffer_start = message->buffer_stop = 0; - message->buffer_r = 0; - - rewind(fp); -} - int message_eof(message_t *message) { FILE *fp = message->fp ? message->fp : stdin; @@ -347,7 +335,13 @@ unsigned message_parse_headers(message_t *message) start = stop; if(line[0] == '\n') + { + printf("size: %d\n", message->buffer_size); + printf("start: %d\n", message->buffer_start); + printf("stop: %d\n", message->buffer_stop); + return count; + } } } @@ -67,8 +67,6 @@ unsigned message_parse_headers(message_t *message); size_t message_read(message_t *message, char *ptr, size_t size); -void message_rewind(message_t *message); - int message_eof(message_t *message); #endif @@ -135,17 +135,16 @@ static const char * message_cb (void **buf, int *len, void *arg) int octets; if (len == NULL) + { + /* only allow rewinding in the beginning of a message otherwise + * it will break the pipes */ assert(*buf == NULL); + return; + } if (*buf == NULL) *buf = malloc (BUFSIZ); - if (len == NULL) - { - message_rewind(message); - return NULL; - } - *len = message_read(message, *buf, BUFSIZ); return *buf; |