Browse Source

Add the -f, --footer option

master
Damien Goutte-Gattat 10 years ago
parent
commit
cb648ae744
  1. 7
      man/fmail.1.in
  2. 25
      src/fmail.c

7
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

25
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;

Loading…
Cancel
Save