Browse Source

Make automatic headers optional.

Do not always add the User-Agent and Date headers. Add them
only if requested by command-line options.
tags/fmail-0.1.1^2
Damien Goutte-Gattat 2 years ago
parent
commit
45d56bcd00
2 changed files with 43 additions and 15 deletions
  1. +12
    -0
      man/fmail.1.in
  2. +31
    -15
      src/fmail.c

+ 12
- 0
man/fmail.1.in View File

@@ -23,6 +23,8 @@ fmail \- mail formatter
.IR recipient ]
.RB [ \-S | --subject
.IR subject ]
.RB [ \-U | --user-agent ]
.RB [ \-D | --date ]
.YS

.SH DESCRIPTION
@@ -95,6 +97,16 @@ header.
Set the
.B Subject:
header.
.TP
.BR -U ", " --user-agent
Add a
.B User-Agent:
header.
.TP
.BR -D "; " --date
Add an automatically generated
.B Date:
header with the current date.

.SH REPORTING BUGS
.PP


+ 31
- 15
src/fmail.c View File

@@ -1,6 +1,6 @@
/*
* fmail - Mail formatter
* Copyright (C) 2011 Damien Goutte-Gattat
* Copyright (C) 2011,2018 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -67,6 +67,8 @@ for submission to a mail submission agent.\n");
-T, --to TEXT Add a To: header.\n\
-C, --cc TEXT Add a Cc: header.\n\
-S, --subject TEXT Set the Subject: header.\n\
-U, --user-agent Add a User-Agent: header.\n\
-D, --date Add a Date: header with the current date.\n\
");

puts("\
@@ -490,22 +492,24 @@ read_input_from_editor(void)
int
main(int argc, char *argv[])
{
char c;
char c, with_useragent, with_date;
string_buffer_t *headers;
fmail_ctx_t ctx;

struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "sign", 0, NULL, 's' },
{ "attach", 1, NULL, 'a' },
{ "edit", 0, NULL, 'e' },
{ "footer", 1, NULL, 'f' },
{ "header", 1, NULL, 'H' },
{ "from", 1, NULL, 'F' },
{ "to", 1, NULL, 'T' },
{ "cc", 1, NULL, 'C' },
{ "subject", 1, NULL, 'S' },
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "sign", 0, NULL, 's' },
{ "attach", 1, NULL, 'a' },
{ "edit", 0, NULL, 'e' },
{ "footer", 1, NULL, 'f' },
{ "header", 1, NULL, 'H' },
{ "from", 1, NULL, 'F' },
{ "to", 1, NULL, 'T' },
{ "cc", 1, NULL, 'C' },
{ "subject", 1, NULL, 'S' },
{ "user-agent", 0, NULL, 'U' },
{ "date", 0, NULL, 'D' },
{ NULL, 0, NULL, 0 }
};

@@ -513,6 +517,8 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
srand(time(NULL));

with_useragent = with_date = 0;

headers = sb_new(0);
ctx.signing_ctx = NULL;
ctx.magic_ctx = initialize_magic();
@@ -574,12 +580,22 @@ main(int argc, char *argv[])
case 'S':
sb_addf(headers, "Subject: %s\r\n", optarg);
break;

case 'U':
with_useragent = 1;
break;

case 'D':
with_date = 1;
break;
}
}

/* Generate automatic headers */
sb_addf(headers, "Date: %s\r\n", rfc2822_date());
sb_addf(headers, "User-Agent: fmail %s\r\n", VERSION);
if ( with_date )
sb_addf(headers, "Date: %s\r\n", rfc2822_date());
if ( with_useragent )
sb_addf(headers, "User-Agent: fmail %s\r\n", VERSION);

/* Fire editor instead of reading from stdin? */
if ( ! ctx.input )


Loading…
Cancel
Save