aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-09-19 16:43:58 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-09-19 16:43:58 +0200
commit54435b30b6c9f42d13842927e20c27aa267ef960 (patch)
treec52404c6079acbc17ac59b67b7ee7baadfab6df7
parent7e9a73397bce23b7356b953c74301540fa91f015 (diff)
downloadmblaze-54435b30b6c9f42d13842927e20c27aa267ef960.tar.gz
mmime: gen_qp: encode trailing space and tab as =20/=09
See RFC2045 6.7.(3): > It follows that an octet with decimal value 9 or 32 appearing at the > end of an encoded line must be represented according to Rule #1. Prefer this over generating a soft-line break and then a real line break.
-rw-r--r--mmime.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/mmime.c b/mmime.c
index af7c86d..83e0d82 100644
--- a/mmime.c
+++ b/mmime.c
@@ -85,7 +85,6 @@ int gen_qp(uint8_t *s, off_t size, int maxlinelen, int linelen)
}
if ((s[i] > 126) ||
- (s[i] < 32 && s[i] != '\n' && s[i] != '\t') ||
(s[i] == '=')) {
printf("=%02X", s[i]);
linelen += 3;
@@ -99,6 +98,18 @@ int gen_qp(uint8_t *s, off_t size, int maxlinelen, int linelen)
putc_unlocked('_', stdout);
linelen++;
prev = '_';
+ } else if (s[i] < 33 && s[i] != '\n') {
+ if ((s[i] == ' ' || s[i] == '\t') &&
+ i+1 < size &&
+ (s[i+1] != '\n' && s[i+1] != '\r')) {
+ putc_unlocked(s[i], stdout);
+ linelen += 1;
+ prev = s[i];
+ } else {
+ printf("=%02X", s[i]);
+ linelen += 3;
+ prev = '_';
+ }
} else if (s[i] == '\n') {
if (prev == ' ' || prev == '\t')
puts("=");