aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-06-18 00:35:40 +0200
committerLeah Neukirchen <leah@vuxu.org>2021-06-18 01:13:03 +0200
commit9713264f70846d6eda3d9ed97d0212c5a077f888 (patch)
treeedc8a8e2ad09079342ada7f0f66bdda4a6f0774a
parent23941c6c19e314563cada0a8d46f706a7b92e9ae (diff)
downloadmblaze-9713264f70846d6eda3d9ed97d0212c5a077f888.tar.gz
mblaze-9713264f70846d6eda3d9ed97d0212c5a077f888.tar.xz
mblaze-9713264f70846d6eda3d9ed97d0212c5a077f888.zip
mmime: be more careful when qp-encoding in headers
Characters such as , or ; mustn't appear in qp-encoded strings, as they have a meaning in phrases. To be safe, encode all special characters except for the safe ones in RFC 2047 5.(3). _ is dealt with already.
-rw-r--r--mmime.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/mmime.c b/mmime.c
index 5c18171..b55d301 100644
--- a/mmime.c
+++ b/mmime.c
@@ -59,6 +59,11 @@ int gen_b64(uint8_t *s, off_t size)
return 0;
}
+#define qphrasevalid(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || \
+ (c >= 'a' && c <= 'z') || \
+ c == '!' || c == '*' || c == '+' || c == '-' || \
+ c == '/')
+
size_t
gen_qp(uint8_t *s, off_t size, size_t maxlinelen, size_t linelen)
{
@@ -123,6 +128,10 @@ gen_qp(uint8_t *s, off_t size, size_t maxlinelen, size_t linelen)
putc_unlocked('\n', stdout);
linelen = 0;
prev = 0;
+ } else if (header && !qphrasevalid(s[i])) {
+ printf("=%02X", s[i]);
+ linelen += 3;
+ prev = '_';
} else {
putc_unlocked(s[i], stdout);
linelen++;