Hi Gus
I am not sure is I am writing at correct place
but there are few bugs I fixed in a copy of source code (latest to the moment of writing this)
1) This is working method for decoding Quoted printable
internal static string DecodeQuotedPrintable(string input, Encoding encoding)
{
////parse looking for =XX where XX is hexadecimal
var occurences = new Regex(@"(=[0-9A-Z]{2}){1,}", RegexOptions.Multiline);
//var occurences = new Regex("(=[0-9A-Z][0-9A-Z])", RegexOptions.Multiline);
var matches = occurences.Matches(input);
foreach (Match match in matches.Cast<Match>()
.OrderByDescending(c=>c.Groups[0].Value.Length)
.ToList())
{
try
{
var b = new byte[match.Groups[0].Value.Length / 3];
for (int i = 0; i < match.Groups[0].Value.Length / 3; i++)
{
b[i] = byte.Parse(match.Groups[0].Value.Substring(i * 3 + 1, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
}
var array = encoding.GetChars(b);
input = input.Replace(match.Groups[0].Value, new string(array));
}
catch
{ ;}
}
input = input.Replace("?=", "").Replace("=\r\n", "");
return input;
}
before the fix the body was not decoding properly
2) this is the correct version of a method for accumulating body
private void AppendDataToContentStream(string data) {
switch (ContentTransferEncoding) {
case ContentTransferEncoding.QuotedPrintable:
//_contentBuilder.Append(data.TrimEnd(new[] {' ', '='}));
_contentBuilder.Append(data.TrimEnd(new[] {'='}));
break;
case ContentTransferEncoding.EightBit:
case ContentTransferEncoding.SevenBit:
_contentBuilder.AppendLine(data);
break;
default:
_contentBuilder.Append(data);
break;
}
}
3) This is the fixed version for correctly retrieving all labels (not just one)
private void TryProcessGmLabels(string data)
{
var labelsMatches =
Expressions.GMailLabelSplitRex.Matches(Expressions.GMailLabelsRex.Match(data).Groups[1].Value);
if (labelsMatches.Count == 0)return ;//.Success || labelsMatch.Groups.Count <= 1) return;
foreach (Match labelsMatch in labelsMatches)
{
Labels.AddRangeInternal(
labelsMatch.Groups.Cast<Group>()
.Skip(1)
.Select(_ => (_.Value.StartsWith("&") ? ImapUTF7.Decode(_.Value) : _.Value).Replace("\"", "")));
}
_downloadProgress = _downloadProgress | MessageFetchMode.GMailLabels;
}
I am not sure is I am writing at correct place
but there are few bugs I fixed in a copy of source code (latest to the moment of writing this)
1) This is working method for decoding Quoted printable
internal static string DecodeQuotedPrintable(string input, Encoding encoding)
{
////parse looking for =XX where XX is hexadecimal
var occurences = new Regex(@"(=[0-9A-Z]{2}){1,}", RegexOptions.Multiline);
//var occurences = new Regex("(=[0-9A-Z][0-9A-Z])", RegexOptions.Multiline);
var matches = occurences.Matches(input);
foreach (Match match in matches.Cast<Match>()
.OrderByDescending(c=>c.Groups[0].Value.Length)
.ToList())
{
try
{
var b = new byte[match.Groups[0].Value.Length / 3];
for (int i = 0; i < match.Groups[0].Value.Length / 3; i++)
{
b[i] = byte.Parse(match.Groups[0].Value.Substring(i * 3 + 1, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
}
var array = encoding.GetChars(b);
input = input.Replace(match.Groups[0].Value, new string(array));
}
catch
{ ;}
}
input = input.Replace("?=", "").Replace("=\r\n", "");
return input;
}
before the fix the body was not decoding properly
2) this is the correct version of a method for accumulating body
private void AppendDataToContentStream(string data) {
switch (ContentTransferEncoding) {
case ContentTransferEncoding.QuotedPrintable:
//_contentBuilder.Append(data.TrimEnd(new[] {' ', '='}));
_contentBuilder.Append(data.TrimEnd(new[] {'='}));
break;
case ContentTransferEncoding.EightBit:
case ContentTransferEncoding.SevenBit:
_contentBuilder.AppendLine(data);
break;
default:
_contentBuilder.Append(data);
break;
}
}
3) This is the fixed version for correctly retrieving all labels (not just one)
private void TryProcessGmLabels(string data)
{
var labelsMatches =
Expressions.GMailLabelSplitRex.Matches(Expressions.GMailLabelsRex.Match(data).Groups[1].Value);
if (labelsMatches.Count == 0)return ;//.Success || labelsMatch.Groups.Count <= 1) return;
foreach (Match labelsMatch in labelsMatches)
{
Labels.AddRangeInternal(
labelsMatch.Groups.Cast<Group>()
.Skip(1)
.Select(_ => (_.Value.StartsWith("&") ? ImapUTF7.Decode(_.Value) : _.Value).Replace("\"", "")));
}
_downloadProgress = _downloadProgress | MessageFetchMode.GMailLabels;
}