X-Git-Url: https://git.sthu.org/?p=smailq.git;a=blobdiff_plain;f=sendmail.c;fp=sendmail.c;h=8e2aa4fc32616667c8a7c0f8f40e7968a30aa8e8;hp=0000000000000000000000000000000000000000;hb=7a102a5e45835cca2a5902a2ae83a9cdfe105e93;hpb=2e355565092fb8b1121dd4bb335c9ae1c69ba9df diff --git a/sendmail.c b/sendmail.c new file mode 100644 index 0000000..8e2aa4f --- /dev/null +++ b/sendmail.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include + + +static void usage(char* arg0) { + puts("A wrapper script for smailq that mimics sendmail.\n" + "USAGE:\n"); + printf(" %s [OPTIONS] [recipient ...]\n", arg0); + printf(" %s -bp\n", arg0); + puts("\n" + "OPTIONS:\n" + " -bp\n" + " Calls `smailq --list`\n" + "\n" + " -h\n" + " Prints this help text\n" + "\n" + " [OPTIONS] [recipient ...]\n" + " Calls `smailq --send -- [OPTIONS] [recipient ...]`.\n" + " It passes all options as MSA options to smailq.\n"); +} + +int main(int argc, char* argv[]) { + if (argc == 1) { + fputs("No arguments given.\n", stderr); + usage(argv[0]); + return EINVAL; + } + + if (strcmp(argv[1], "-h") == 0) { + usage(argv[0]); + return EXIT_SUCCESS; + } + + if (strcmp(argv[1], "-bp") == 0) { + execlp("smailq", "smailq", "list", NULL); + perror("Error calling smailq --list"); + return EXIT_FAILURE; + } + + /* We have to add two more arguments: -- --send */ + char** newargv = malloc((argc+2)*sizeof(char*)); + if (newargv == NULL) { + perror(NULL); + return EXIT_FAILURE; + } + + /* Fill in the arguments for smailq. Note that argv[argc] is NULL and + * newargv must be termined by a NULL pointer for execvp(). */ + newargv[0] = "smailq"; + newargv[1] = "--send"; + newargv[2] = "--"; + for (int i=1; i <= argc; ++i) + newargv[2+i] = argv[i]; + + execvp("smailq", newargv); + perror("Error calling smailq --list"); + free(newargv); + return EXIT_FAILURE; +}