From b57cc43b9d3353187a15beb229b4d1ef3db8be27 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 17 Sep 2006 20:49:16 +0000 Subject: [PATCH] Sends messages (without recipients yet) --- src/compose.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/compose.c b/src/compose.c index effd886..884d207 100644 --- a/src/compose.c +++ b/src/compose.c @@ -2,6 +2,7 @@ +#include #include #include #include @@ -189,8 +190,9 @@ void compose_save(Compose * compose) /* compose_send */ -char * _send_headers(Compose * compose); -char * _send_body(GtkWidget * view); +static char * _send_headers(Compose * compose); +static char * _send_body(GtkWidget * view); +static int _send_mail(Compose * compose, char * msg, size_t msg_len); void compose_send(Compose * compose) { char * msg; @@ -208,21 +210,42 @@ void compose_send(Compose * compose) } msg_len = strlen(msg); body_len = strlen(body); - if((p = realloc(msg, msg_len + body_len + 3)) == NULL) + if((p = realloc(msg, msg_len + body_len + 8)) == NULL) mailer_error(compose->mailer, "Memory allocation", 0); else { msg = p; - snprintf(&msg[msg_len], body_len + 3, "\r\n%s", body); - msg_len+=body_len+2; + snprintf(&msg[msg_len], body_len + 8, "\r\n%s\r\n.\r\n", body); + msg_len+=body_len+7; } g_free(body); + _send_mail(compose, msg, msg_len); free(msg); -/* FIXME will be useful later - execlp("sendmail", "sendmail", "-bs", NULL); */ } -char * _send_headers(Compose * compose) +static int _send_mail(Compose * compose, char * msg, size_t msg_len) +{ + int fd[2]; + pid_t pid; + + if(pipe(fd) != 0) + return mailer_error(compose->mailer, strerror(errno), 1); + if((pid = fork()) == -1) + return mailer_error(compose->mailer, strerror(errno), 1); + if(pid == 0) + { + close(0); + dup2(fd[0], 0); + execl("sendmail", "/usr/sbin/sendmail", "-bm", NULL); + exit(2); + } + /* FIXME send mail progressively, get sendmail's output */ + write(1, msg, msg_len); + write(fd[1], msg, msg_len); + return 0; +} + +static char * _send_headers(Compose * compose) { struct { char * hdr; @@ -268,7 +291,7 @@ char * _send_headers(Compose * compose) return msg; } -char * _send_body(GtkWidget * view) +static char * _send_body(GtkWidget * view) { GtkTextBuffer * tbuf; GtkTextIter start;