From cb648ae7441444a60de8b6f69c24c11999a2866d Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Sun, 22 May 2011 18:47:57 +0200 Subject: [PATCH] Add the -f, --footer option --- man/fmail.1.in | 7 +++++++ src/fmail.c | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/man/fmail.1.in b/man/fmail.1.in index 6768f52..28b2bc4 100644 --- a/man/fmail.1.in +++ b/man/fmail.1.in @@ -10,6 +10,8 @@ fmail \- mail formatter .RB [ \-a | --attach .IR file ] .RB [ \-s | --sign ] +.RB [ \-f | --footer +.IR file ] .RB [ \-H | --header .IR header ] .RB [ \-F | --from @@ -43,6 +45,11 @@ Attach the specified .BR -s ", " --sign Sign the message. .TP +.BR -f ", " --footer " " \fIfile\fR +Append the contents of the specified +.I file +as the mail footer. +.TP .BR -H ", " --header " " \fIheader\fR Add an arbitrary header. .TP diff --git a/src/fmail.c b/src/fmail.c index 8e8ed7b..9693b6e 100644 --- a/src/fmail.c +++ b/src/fmail.c @@ -49,6 +49,10 @@ Read a mail from standard input and send it.\n"); -v, --version Display the version message.\n\ "); + puts("\ + -f, --footer FILE Include FILE as the mail footer.\n\ +"); + puts("\ Headers options:\n\ -H, --header \"NAME: TEXT\"\n\ @@ -100,6 +104,7 @@ typedef struct fmail_ctx { const char **attachments; size_t att_count; + const char *footer; magic_t magic_ctx; gpgme_ctx_t signing_ctx; } fmail_ctx_t; @@ -257,6 +262,18 @@ process_text_body(fmail_ctx_t *ctx, FILE *in, FILE *out) qp_encode_stream(in, out); fprintf(out, "\r\n"); + if ( ctx->footer ) { + FILE *f; + + if ( ! (f = fopen(ctx->footer, "r")) ) + err(EXIT_FAILURE, "cannot open footer file '%s'", ctx->footer); + + fprintf(out, "-- \r\n"); + qp_encode_stream(f, out); + fprintf(out, "\r\n"); + fclose(f); + } + for ( i = 0; i < ctx->att_count; i++ ) { fprintf(out, "--%s\r\n", boundary); process_attachment(ctx->attachments[i], ctx->magic_ctx, out); @@ -398,6 +415,7 @@ main(int argc, char *argv[]) { "version", 0, NULL, 'v' }, { "sign", 0, NULL, 's' }, { "attach", 1, NULL, 'a' }, + { "footer", 1, NULL, 'f' }, { "header", 1, NULL, 'H' }, { "from", 1, NULL, 'F' }, { "to", 1, NULL, 'T' }, @@ -415,8 +433,9 @@ main(int argc, char *argv[]) ctx.magic_ctx = initialize_magic(); ctx.attachments = NULL; ctx.att_count = 0; + ctx.footer = NULL; - while ( (c = getopt_long(argc, argv, "hvsa:H:F:T:C:S:", + while ( (c = getopt_long(argc, argv, "hvsa:f:H:F:T:C:S:", options, NULL)) != -1 ) { switch ( c ) { case 'h': @@ -441,6 +460,10 @@ main(int argc, char *argv[]) ctx.attachments[ctx.att_count++] = optarg; break; + case 'f': + ctx.footer = optarg; + break; + case 'H': sb_addf(headers, "%s\r\n", optarg); break;