summaryrefslogtreecommitdiff
path: root/pith/charset.c
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2020-03-18 01:36:38 -0600
committerEduardo Chappa <chappa@washington.edu>2020-03-18 01:36:38 -0600
commit277d70d881a99e563cfa1c4eee4cc0e77c17ea7d (patch)
tree8abbae9716c658e0f9e17c2093b556319e1b3f98 /pith/charset.c
parentd7838fd7545719029474fea04a51332a542e978a (diff)
downloadalpine-277d70d881a99e563cfa1c4eee4cc0e77c17ea7d.tar.xz
* Fixes to documentation provided by Dennis Davis.
* Bug that makes Alpine split encoded words in the subkect of a message in the middle of a utf-8 character into two encoded words, breaking the encoding. Reported by Jean Chevalier.
Diffstat (limited to 'pith/charset.c')
-rw-r--r--pith/charset.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/pith/charset.c b/pith/charset.c
index f651abe9..b3d44d42 100644
--- a/pith/charset.c
+++ b/pith/charset.c
@@ -593,9 +593,32 @@ rfc1522_encoded_word(unsigned char *s, int enc, char *charset)
for(goal = ((goal / 4) * 3) - 2; goal && *s; goal--, s++)
;
else /* special 'Q' encoding */
- for(; goal && *s; s++)
- if((goal -= RFC1522_ENC_CHAR(*s) ? 3 : 1) < 0)
- break;
+ if(!strucmp(charset, "UTF-8")){ /* special handling for utf-8 */
+ int i,more;
+ unsigned char *p;
+ for(; goal && *s; s++){
+ more = *s < 0x80 ? 0
+ : *s < 0xe0 ? 1
+ : *s < 0xf0 ? 2
+ : *s < 0xf8 ? 3
+ : *s < 0xfc ? 4
+ : *s < 0xfe ? 5 : -1;
+ if(more >= 0){ /* check that we have at least more characters */
+ for(p = s, i = 0; i <= more && *p != '\0'; i++, p++)
+ goal -= RFC1522_ENC_CHAR(*p) ? 3 : 1;
+ if(goal < 0) /* does not fit in encoded word */
+ break;
+ s += i - 1; /* i - 1 should be equal to more */
+ }
+ else /* encode it, and skip it */
+ if((goal -= RFC1522_ENC_CHAR(*s) ? 3 : 1) < 0)
+ break;
+ }
+ }
+ else
+ for(; goal && *s; s++)
+ if((goal -= RFC1522_ENC_CHAR(*s) ? 3 : 1) < 0)
+ break;
return(s);
}