]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: imap-utf7 - only encode in-range 7-bit values
authorPhil Carmody <phil@dovecot.fi>
Mon, 28 Jul 2014 13:49:47 +0000 (16:49 +0300)
committerPhil Carmody <phil@dovecot.fi>
Mon, 28 Jul 2014 13:49:47 +0000 (16:49 +0300)
0x01-0x1F and 0x7f-... must be mBASE64 encoded.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib-imap/imap-utf7.c

index 98ec93cc8b489355ff5746d9e47e347c9b277dc0..81264532032f3435546da17ee5e4d6bc9225e03e 100644 (file)
@@ -60,7 +60,7 @@ static const char *imap_utf8_first_encode_char(const char *str)
        const char *p;
 
        for (p = str; *p != '\0'; p++) {
-               if (*p == '&' || (unsigned char)*p >= 0x80)
+               if (*p == '&' || *p < 0x20 || *p >= 0x7f)
                        return p;
        }
        return NULL;
@@ -89,14 +89,14 @@ int imap_utf8_to_utf7(const char *src, string_t *dest)
                        p++;
                        continue;
                }
-               if ((unsigned char)*p < 0x80) {
+               if (*p >= 0x20 && *p < 0x7f) {
                        str_append_c(dest, *p);
                        p++;
                        continue;
                }
 
                u = utf16;
-               while ((unsigned char)*p >= 0x80) {
+               while (*p != '\0' && (*p < 0x20 || *p >= 0x7f)) {
                        if (uni_utf8_get_char(p, &chr) <= 0)
                                return -1;
                        /* @UNSAFE */