Quantcast
Channel: ImapX 2
Viewing all articles
Browse latest Browse all 1952

Closed Issue: Bug in StingDecoder.DecodeQuotedPrintable [1915]

$
0
0
StringDecoder.DecodeQuotedPrintable("=3D3E=3E", Encoding.ASCII);

Results in ">>"
Where it should result in "=3E>"

This is because the Regex expression finds =3D and =3E as valid quoted printables in the source.
=3D is of course the quoted printable for an escaped =
So, in replacing the first =3D in the string, a second unintentional =3E is created which wasn't in the original source.
Then the escaped =3E replaces both occurrences with a > character.

```
StringBuilder sb = new StringBuilder();
string validHex = "0123456789ABCDEF";
int start = 0;
int end = input.Length;
while (start < end)
{
int pos = input.IndexOf('=', start);
if (pos < 0)
{
sb.Append(input.Substring(start, end - start));
break;
}
sb.Append(input.Substring(start, pos - start));
start = pos;

if (pos < end - 2 && validHex.Contains(input[pos + 1]) && validHex.Contains(input[pos + 2]))
{
string hex = input.Substring(pos + 1, 2);
byte b = byte.Parse(hex, NumberStyles.HexNumber);
sb.Append(encoding.GetChars(new byte[] { b }));
start += 3;
}
else
{
sb.Append("=");
start++;
}
}
input = sb.ToString().Replace("?=", "").Replace("=\r\n", "");

```

Viewing all articles
Browse latest Browse all 1952

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>