123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- #include "libbb.h"
- #include "mail.h"
- #if 0
- # define dbg_error_msg(...) bb_error_msg(__VA_ARGS__)
- #else
- # define dbg_error_msg(...) ((void)0)
- #endif
- int makemime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int makemime_main(int argc UNUSED_PARAM, char **argv)
- {
- llist_t *opt_headers = NULL, *l;
- const char *opt_output;
- const char *content_type = "application/octet-stream";
- #define boundary opt_output
- enum {
- OPT_c = 1 << 0,
- OPT_e = 1 << 1,
- OPT_o = 1 << 2,
- OPT_C = 1 << 3,
- OPT_N = 1 << 4,
- OPT_a = 1 << 5,
-
-
- };
- INIT_G();
-
- opts = getopt32(argv,
- "c:e:o:C:N:a:*",
- &content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers
- );
-
- argv += optind;
-
- if (opts & OPT_o)
- freopen(opt_output, "w", stdout);
-
- if (!*argv)
- *--argv = (char *)"-";
-
- for (l = opt_headers; l; l = l->link)
- puts(l->data);
-
- srand(monotonic_us());
- boundary = xasprintf("%u-%u-%u",
- (unsigned)rand(), (unsigned)rand(), (unsigned)rand());
-
- printf(
- "Mime-Version: 1.0\n"
- "Content-Type: multipart/mixed; boundary=\"%s\"\n"
- , boundary
- );
-
- while (*argv) {
- printf(
- "\n--%s\n"
- "Content-Type: %s; charset=%s\n"
- "Content-Disposition: inline; filename=\"%s\"\n"
- "Content-Transfer-Encoding: base64\n"
- , boundary
- , content_type
- , G.opt_charset
- , bb_get_last_path_component_strip(*argv)
- );
- encode_base64(*argv++, (const char *)stdin, "");
- }
-
- printf("\n--%s--\n" "\n", boundary);
- return EXIT_SUCCESS;
- #undef boundary
- }
|