diff --git a/mail.c b/mail.c index be3da1d..151cc2f 100644 --- a/mail.c +++ b/mail.c @@ -10,7 +10,7 @@ #include struct headers { - uw_Basis_string from, to, cc, bcc, subject; + uw_Basis_string from, to, cc, bcc, subject, replyto; }; typedef struct headers *uw_Mail_headers; @@ -36,6 +36,7 @@ static uw_Mail_headers copy_headers(uw_Mail_headers h) { h2->cc = copy_string(h->cc); h2->bcc = copy_string(h->bcc); h2->subject = copy_string(h->subject); + h2->replyto = copy_string(h->replyto); return h2; } @@ -45,6 +46,7 @@ static void free_headers(uw_Mail_headers h) { free_string(h->cc); free_string(h->bcc); free_string(h->subject); + free_string(h->replyto); free(h); } @@ -172,6 +174,23 @@ uw_Mail_headers uw_Mail_subject(uw_context ctx, uw_Basis_string s, uw_Mail_heade return h2; } +uw_Mail_headers uw_Mail_replyto(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) { + uw_Mail_headers h2 = uw_malloc(ctx, sizeof(struct headers)); + + if (h) + *h2 = *h; + else + memset(h2, 0, sizeof(*h2)); + + if (h2->replyto) + uw_error(ctx, FATAL, "Duplicate Reply-to header"); + + address(ctx, s); + h2->replyto = uw_strdup(ctx, s); + + return h2; +} + typedef struct { uw_context ctx; uw_Mail_headers h; @@ -187,7 +206,7 @@ static int smtp_read(uw_context ctx, int sock, char *buf, ssize_t *pos) { ssize_t recvd; buf[*pos] = 0; - + if ((s = strchr(buf, '\n'))) { int n; @@ -390,6 +409,17 @@ static void commit(void *data) { } } + if (j->h->replyto) { + snprintf(out, sizeof(out), "Reply-to: %s\r\n", j->h->replyto); + out[sizeof(out)-1] = 0; + + if (really_string(sock, out) < 0) { + close(sock); + uw_set_error_message(j->ctx, "Error sending Reply-to"); + return; + } + } + if ((s = uw_get_global(j->ctx, "extra_mail_headers"))) { if (really_string(sock, s) < 0) { close(sock); diff --git a/mail.h b/mail.h index 7e9257a..8354144 100644 --- a/mail.h +++ b/mail.h @@ -9,5 +9,6 @@ uw_Mail_headers uw_Mail_to(uw_context, uw_Basis_string, uw_Mail_headers); uw_Mail_headers uw_Mail_cc(uw_context, uw_Basis_string, uw_Mail_headers); uw_Mail_headers uw_Mail_bcc(uw_context, uw_Basis_string, uw_Mail_headers); uw_Mail_headers uw_Mail_subject(uw_context, uw_Basis_string, uw_Mail_headers); +uw_Mail_headers uw_Mail_replyto(uw_context, uw_Basis_string, uw_Mail_headers); uw_unit uw_Mail_send(uw_context, uw_Mail_headers, uw_Basis_string body, uw_Basis_string xbody); diff --git a/mail.urs b/mail.urs index fe84f99..a1671bf 100644 --- a/mail.urs +++ b/mail.urs @@ -8,6 +8,7 @@ val empty : headers (* Each of the following may be used at most once in constructing a [headers]. *) val from : string -> headers -> headers val subject : string -> headers -> headers +val replyto : string -> headers -> headers (* The following must be called with single valid e-mail address arguments, and * all such addresses passed are combined into single header values. *)