Skip to content

Commit

Permalink
Fix IMAP string decoding and encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Mar 14, 2023
1 parent 4a94db4 commit 51c1070
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ESP_Mail_IMAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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)
Expand Down

0 comments on commit 51c1070

Please sign in to comment.