Browse Source

Add -e, --edit option

tags/v0.1.0
Damien Goutte-Gattat 9 years ago
parent
commit
1edc87405e
2 changed files with 40 additions and 1 deletions
  1. +4
    -0
      man/fmail.1.in
  2. +36
    -1
      src/fmail.c

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

@@ -10,6 +10,7 @@ fmail \- mail formatter
.RB [ \-a | --attach
.IR file ]
.RB [ \-s | --sign ]
.RB [ \-e | --edit ]
.RB [ \-f | --footer
.IR file ]
.RB [ \-H | --header
@@ -44,6 +45,9 @@ Attach the specified
.TP
.BR -s ", " --sign
Sign the message.
.TP -e ", " --edit
Fire an editor to type the mail body instead of
reading it from standard input.
.TP
.BR -f ", " --footer " " \fIfile\fR
Append the contents of the specified


+ 36
- 1
src/fmail.c View File

@@ -50,6 +50,9 @@ Read a mail from standard input and send it.\n");
");

puts("\
-e, --edit Fire an editor to type mail body\n\
instead of reading it from\n\
standard input.\n\
-f, --footer FILE Include FILE as the mail footer.\n\
");

@@ -402,6 +405,29 @@ process_attachment(const char *filename, magic_t ctx, FILE *out)


/* Read mail from editor. */

static FILE *
read_input_from_editor(void)
{
char tmp_filename[] = "/tmp/fmailXXXXXX";
char command[] = "vim /tmp/fmailXXXXXX";
char buffer[512];
int n, tmp_fd;
FILE *f;

tmp_fd = mkstemp(tmp_filename);
sprintf(command, "vim %s", tmp_filename);
system(command);

f = fdopen(tmp_fd, "r");
unlink(tmp_filename);

return f;
}


/* Main function. */

int
@@ -416,6 +442,7 @@ main(int argc, char *argv[])
{ "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' },
@@ -437,7 +464,7 @@ main(int argc, char *argv[])
ctx.footer = NULL;
ctx.input = stdin;

while ( (c = getopt_long(argc, argv, "hvsa:f:H:F:T:C:S:",
while ( (c = getopt_long(argc, argv, "hvsa:ef:H:F:T:C:S:",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
@@ -462,6 +489,10 @@ main(int argc, char *argv[])
ctx.attachments[ctx.att_count++] = optarg;
break;

case 'e':
ctx.input = NULL;
break;

case 'f':
ctx.footer = optarg;
break;
@@ -492,6 +523,10 @@ main(int argc, char *argv[])
sb_addf(headers, "Date: %s\r\n", rfc2822_date());
sb_addf(headers, "User-Agent: fmail %s\r\n", VERSION);

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

/* Read user-provided headers. */
read_headers(ctx.input, headers);



Loading…
Cancel
Save