#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: creation of new CMimeMessage_T object with cmime_message_create_skeleton function and add an attachment via cmime_message_add_attachment\n");
printf("output: output is written to stdout if no output file is specified\n");
printf("required parameter: -a /path/to/attachment\n");
printf("optional parameter: -f /path/to/out_file\n");
}
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 *attachment = NULL;
char *out = NULL;
int option;
int retval = 0;
while((option = getopt(argc,argv,"hf:a:")) != EOF) {
switch(option) {
case 'f':
asprintf(&file, "%s", optarg);
break;
case 'a':
asprintf(&attachment, "%s", optarg);
break;
case 'h':
usage();
break;
default:
usage();
}
}
if(attachment != NULL) {
if(file != NULL) {
printf("file created: %s\n", file);
} else {
printf("error writing file: %s\n", file);
}
} else {
printf("%s\n", out);
}
} else {
printf("you have to specify an attachment with -a\n");
retval = -1;
}
if(file != NULL)
free(file);
if(attachment != NULL)
free(attachment);
if(out != NULL)
free(out);
return retval;
}