summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-01-27 15:59:46 -0500
committerJune McEnroe <june@causal.agency>2020-01-27 15:59:46 -0500
commita0c11b5432eed2d7bfc24f489425b030b5346bfc (patch)
tree0931d5b16e9ead764b57f7f90813ad7ab53eca60
parentSkip notes not listed in args (diff)
downloadnotemap-a0c11b5432eed2d7bfc24f489425b030b5346bfc.tar.gz
notemap-a0c11b5432eed2d7bfc24f489425b030b5346bfc.zip
Encode trailing whitespace in quote-printable properly
-rw-r--r--notemap.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/notemap.c b/notemap.c
index 5f35794..c7f116f 100644
--- a/notemap.c
+++ b/notemap.c
@@ -246,14 +246,14 @@ static void append(
 
 	int ch;
 	int len = 0;
+	bool ws = false;
 	while (EOF != (ch = fgetc(note))) {
 		if (len == 76 && ch != '\n') {
 			fprintf(msg, "=\r\n");
 			len = 0;
 		}
 		if (ch == '\n') {
-			// TODO: Check if last character was space or tab.
-			fprintf(msg, "\r\n");
+			fprintf(msg, "%s\r\n", (ws ? "=\r\n" : ""));
 			len = 0;
 		} else if (ch == '\t' || (ch >= ' ' && ch <= '~' && ch != '=')) {
 			fprintf(msg, "%c", ch);
@@ -262,6 +262,7 @@ static void append(
 			fprintf(msg, "=%02X", ch);
 			len += 3;
 		}
+		ws = (ch == '\t' || ch == ' ');
 	}
 	if (ferror(note)) err(EX_IOERR, "%s", path);
 	fclose(note);