#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../src/cmime_message.h"
void usage() {
printf("\n");
printf("libcmime - simple api demonstration\n");
printf("-----------------------------------\n");
printf("demonstrates: append or prepend something to the subject string\n");
printf("output: output is written to stdout if no output file is specified\n");
printf("optional parameter: -a string to append \n");
printf("optional parameter: -p string to prepend\n");
printf("optional parameter: -o /path/to/out_file\n");
printf("\nexample: ./examples/append_and_prepend_subject -a \"aaa aaa aaa\" -p \"bbb bbb bbb\"");
}
int main(int argc, char *argv[])
{
char from[] = "from@example.org";
char to[] = "to@example.org";
char subject[] = "this is a subject";
char body[] = "some very interesting body line";
char *file = NULL;
char *out = NULL;
int option;
char *append = NULL;
char *prepend = NULL;
while((option = getopt(argc,argv,"ha:p:o:")) != EOF) {
switch(option) {
case 'a':
asprintf(&append, "%s", optarg);
break;
case 'p':
asprintf(&prepend, "%s", optarg);
break;
case 'o':
asprintf(&file, "%s", optarg);
break;
case 'h':
usage();
break;
default:
usage();
}
}
if(append != NULL)
if(prepend != NULL)
if(file != NULL) {
printf("file created: %s\n", file);
} else {
printf("error writing file: %s\n", file);
}
} else {
printf("%s\n", out);
}
if(append != NULL)
free(append);
if(prepend != NULL)
free(prepend);
if(file != NULL)
free(file);
if(out != NULL)
free(out);
return (0);
}