From 51c10706a73630ea365b40bdaf795582799770b5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Mar 2023 15:18:45 +0700 Subject: [PATCH] Fix IMAP string decoding and encoding. --- src/ESP_Mail_IMAP.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ESP_Mail_IMAP.h b/src/ESP_Mail_IMAP.h index 4565babb..a88334d6 100644 --- a/src/ESP_Mail_IMAP.h +++ b/src/ESP_Mail_IMAP.h @@ -260,10 +260,9 @@ void ESP_Mail_Client::decodeTIS620_UTF8(char *out, const char *in, size_t len) int j = 0; for (size_t i = 0; i < len; i++) { - if (in[i] < 0x80) out[j++] = in[i]; - else if (in[i] >= 0xa0 && in[i] < 0xa0 + 0x7f) + else if ((in[i] >= 0xa0 && in[i] < 0xdb) || (in[i] > 0xde && in[i] < 0xfc)) { int unicode = 0x0e00 + in[i] - 0xa0; char o[5]; @@ -273,6 +272,12 @@ void ESP_Mail_Client::decodeTIS620_UTF8(char *out, const char *in, size_t len) out[j++] = o[x]; } } + + if (strlen(out) >= 2 && out[strlen(out) - 2] != '\r' && out[strlen(out) - 1] != '\n') + { + out[j++] = '\r'; + out[j++] = '\n'; + } } int ESP_Mail_Client::decodeLatin1_UTF8(unsigned char *out, int *outlen, const unsigned char *in, int *inlen)