summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am10
-rw-r--r--NEWS7
-rw-r--r--local.c15
-rw-r--r--message.c48
-rw-r--r--message.h2
-rw-r--r--smtp.c11
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
diff --git a/NEWS b/NEWS
index 289c796..45cece6 100644
--- a/NEWS
+++ b/NEWS
@@ -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):
diff --git a/local.c b/local.c
index bd5f147..98878fa 100644
--- a/local.c
+++ b/local.c
@@ -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)
diff --git a/message.c b/message.c
index 5f487d6..9191218 100644
--- a/message.c
+++ b/message.c
@@ -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;
+ }
}
}
diff --git a/message.h b/message.h
index a4c4b15..df4f0b7 100644
--- a/message.h
+++ b/message.h
@@ -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
diff --git a/smtp.c b/smtp.c
index 033edaf..1ad0832 100644
--- a/smtp.c
+++ b/smtp.c
@@ -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;