about summary refs log tree commit diff
path: root/mmime.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-08-02 14:01:05 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-08-02 14:01:18 +0200
commit2073102d4d2231dd2f341c9dc8bde9ea38274369 (patch)
treea1919a0e1d062cbfbefdd9ae3b7f5466c4d9a1fa /mmime.c
parenta52af29aa96be8d59a6e7806283ca91dcf46c8a7 (diff)
downloadmblaze-2073102d4d2231dd2f341c9dc8bde9ea38274369.tar.gz
mblaze-2073102d4d2231dd2f341c9dc8bde9ea38274369.tar.xz
mblaze-2073102d4d2231dd2f341c9dc8bde9ea38274369.zip
mmime: add -r for plain text
Diffstat (limited to 'mmime.c')
-rw-r--r--mmime.c39
1 files changed, 30 insertions, 9 deletions
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();
 }