Browse Source

Add option -a, --attach

tags/v0.1.0
Damien Goutte-Gattat 9 years ago
parent
commit
c63425a80b
1 changed files with 21 additions and 2 deletions
  1. +21
    -2
      src/fmail.c

+ 21
- 2
src/fmail.c View File

@@ -30,6 +30,7 @@
#include <gpgme.h>

#include <sbuffer.h>
#include <xmem.h>

/* Help and informations about the program. */
@@ -46,6 +47,11 @@ Read a mail from standard input and send it.\n");
-v, --version Display the version message.\n\
");

puts("\
Attachments options:\n\
-a, --attach FILE Attach the specified file.\n\
");

puts("\
Cryptography options:\n\
-s, --sign Sign the message.\n\
@@ -268,14 +274,16 @@ sign_stream(gpgme_ctx_t ctx, FILE *in, FILE *out)
int
main(int argc, char *argv[])
{
char c;
char c, **attachments;
string_buffer_t *headers;
gpgme_ctx_t sign_ctx;
int att_count;

struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "sign", 0, NULL, 's' },
{ "attach", 1, NULL, 'a' },
{ NULL, 0, NULL, 0 }
};

@@ -285,8 +293,10 @@ main(int argc, char *argv[])

headers = sb_new(0);
sign_ctx = NULL;
attachments = NULL;
att_count = 0;

while ( (c = getopt_long(argc, argv, "hvs",
while ( (c = getopt_long(argc, argv, "hvsa:",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
@@ -304,6 +314,12 @@ main(int argc, char *argv[])
case 's':
sign_ctx = initialize_gpgme();
break;

case 'a':
if ( att_count % 10 == 0 )
attachments = xrealloc(attachments, att_count + 10);
attachments[att_count++] = optarg;
break;
}
}

@@ -330,5 +346,8 @@ main(int argc, char *argv[])
else
process_text_body(stdin, stdout);

if ( attachments )
free(attachments);

return EXIT_SUCCESS;
}

Loading…
Cancel
Save