From 2073102d4d2231dd2f341c9dc8bde9ea38274369 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Tue, 2 Aug 2016 14:01:05 +0200 Subject: [PATCH] mmime: add -r for plain text --- man/mmime.1 | 11 +++++++++++ mmime.c | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/man/mmime.1 b/man/mmime.1 index 056913b..1118850 100644 --- a/man/mmime.1 +++ b/man/mmime.1 @@ -6,6 +6,9 @@ .Nd encode MIME mails .Sh SYNOPSIS .Nm +.Op Fl r +< +.Ar message .Sh DESCRIPTION .Nm encodes the standard input into a MIME message. @@ -23,6 +26,14 @@ with a MIME part having Content-Type .Ar type consisting of the contents of .Pa filename . +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl r +Raw mode: don't expand MIME parts in the body, generate a +.Sq Li text/plain +message. +.El .Sh EXIT STATUS .Ex -std .Sh SEE ALSO diff --git a/mmime.c b/mmime.c index 4b34c35..93eb01b 100644 --- a/mmime.c +++ b/mmime.c @@ -17,6 +17,8 @@ #include "blaze822.h" +static int rflag; + int gen_b64(uint8_t *s, off_t size) { static char *b64 = @@ -281,16 +283,22 @@ gen_build() if (line[0] == '\n') { inheader = 0; printf("MIME-Version: 1.0\n"); - printf("Content-Type: multipart/mixed; boundary=\"%s\"\n", sep); - printf("\n"); - printf("This is a multipart message in MIME format.\n\n"); + if (rflag) { + printf("Content-Type: text/plain; charset=UTF-8\n"); + printf("Content-Transfer-Encoding: quoted-printable\n\n"); + + } else { + printf("Content-Type: multipart/mixed; boundary=\"%s\"\n", sep); + printf("\n"); + printf("This is a multipart message in MIME format.\n\n"); + } } else { print_header(line); } continue; } - if (line[0] == '#') { + if (!rflag && line[0] == '#') { char *f = strchr(line, ' '); *f = 0; if (strchr(line, '/')) { @@ -303,9 +311,9 @@ gen_build() } } - if (!intext) { + if (!rflag && !intext) { printf("--%s\n", sep); - printf("Content-Type: text/plain\n"); + printf("Content-Type: text/plain; charset=UTF-8\n"); printf("Content-Disposition: inline\n"); printf("Content-Transfer-Encoding: quoted-printable\n\n"); @@ -314,7 +322,8 @@ gen_build() gen_qp((uint8_t *)line, strlen(line), 78, 0); } - printf("--%s--\n", sep); + if (!rflag) + printf("--%s--\n", sep); free(line); return 0; @@ -325,6 +334,18 @@ main(int argc, char *argv[]) { srand48(time(0) ^ getpid()); - if (argc == 1) - return gen_build(); + int c; + while ((c = getopt(argc, argv, "r")) != -1) + switch(c) { + case 'r': rflag = 1; break; + default: + usage: + fprintf(stderr, "Usage: mmime [-r] < message\n"); + exit(1); + } + + if (argc != optind) + goto usage; + + return gen_build(); }