summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-01-28 01:50:15 -0500
committerJune McEnroe <june@causal.agency>2020-01-28 01:50:49 -0500
commitc7733272ab55ccd776f3d409521d166e478adfab (patch)
tree18f3de5f5c877700c613c7c99e0ebf1030366ae1
parentSplit lines so that they're 76, not 77 characters (diff)
downloadnotemap-c7733272ab55ccd776f3d409521d166e478adfab.tar.gz
notemap-c7733272ab55ccd776f3d409521d166e478adfab.zip
Limit subject to 7-bit 78 characters
Since file names are unlikely to be 8-bit and long, taking the easy way
out. Otherwise it should be encoded according to
<https://tools.ietf.org/html/rfc2047>.
-rw-r--r--notemap.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/notemap.c b/notemap.c
index 35dba0c..f1ebf5a 100644
--- a/notemap.c
+++ b/notemap.c
@@ -217,6 +217,12 @@ static void append(
 		localtime(&status.st_mtime)
 	);
 
+	char subj[78 - (sizeof("Subject: ") - 1)] = {0};
+	for (size_t i = 0; i < sizeof(subj) - 1; ++i) {
+		if (!path[i]) break;
+		subj[i] = (path[i] & 0x80 ? '?' : path[i]);
+	}
+
 #define HEADERS \
 	"From: <%s>\r\n" \
 	"Subject: %s\r\n" \
@@ -231,7 +237,7 @@ static void append(
 
 	size_t max = sizeof(HEADERS)
 		+ strlen(from)
-		+ strlen(path)
+		+ strlen(subj)
 		+ strlen(date)
 		+ strlen(uuid)
 		+ 3 * status.st_size
@@ -241,7 +247,7 @@ static void append(
 
 	FILE *msg = fmemopen(buf, max, "w");
 	if (!msg) err(EX_OSERR, "fmemopen");
-	fprintf(msg, HEADERS, from, path, date, uuid);
+	fprintf(msg, HEADERS, from, subj, date, uuid);
 #undef HEADERS
 
 	int ch;