Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension for #10 #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions XstFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Windows;
using System.Text.RegularExpressions;

namespace XstReader
{
Expand Down Expand Up @@ -329,6 +330,15 @@ public void ExportMessageProperties(IEnumerable<Message> messages, string fileNa
var dict = new Dictionary<string, Queue<LineProp>>();
int lines = 1;

Queue<LineProp> queue_body = new Queue<LineProp>();
dict["0000Body"] = queue_body;
Queue<LineProp> queue_html_utf8 = new Queue<LineProp>();
dict["0000HTML_utf8"] = queue_html_utf8;
Queue<LineProp> queue_html_base64 = new Queue<LineProp>();
dict["0000HTML_base64"] = queue_html_base64;
Queue<LineProp> queue_rtf = new Queue<LineProp>();
dict["0000RTF"] = queue_rtf;

foreach (var m in messages)
{
// Do not reread properties for current message as it will fail updating the display
Expand All @@ -355,8 +365,102 @@ public void ExportMessageProperties(IEnumerable<Message> messages, string fileNa
}
queue.Enqueue(new LineProp { line = lines, p = p });
}

if ( m.Body != null )
{
queue_body.Enqueue(new LineProp { line = lines, p = new Property { Tag = EpropertyTag.PidTagBody, Value = m.Body } });
}

if (m.Html != null)
{
var body_html_utf8string = System.Text.Encoding.UTF8.GetString(m.Html);
// queue_html_default.Enqueue(new LineProp { line = lines, p = new Property { Tag = EpropertyTag.PidTagHtml, Value = System.Text.Encoding.GetEncodingi("sjis") } });
// queue_html_default.Enqueue(new LineProp { line = lines, p = new Property { Tag = EpropertyTag.PidTagHtml, Value = System.Text.Encoding.Default.GetString( m.Html) } });
// queue_html_unicode.Enqueue(new LineProp { line = lines, p = new Property { Tag = EpropertyTag.PidTagHtml, Value = System.Text.Encoding.Unicode.GetString(m.Html) } });
queue_html_utf8 .Enqueue(new LineProp { line = lines, p = new Property { Tag = EpropertyTag.PidTagNativeBody, Value = body_html_utf8string } }); // Tag is misuse but no appropriate one --HAL

var charset = "utf-8";
var r = new Regex(@"charset=""?([-_a-zA-Z0-9]+)");
var match = r.Match(body_html_utf8string);
//System.Text.RegularExpressions.Match m = r.Match(text);

if (match.Success)
{
charset = match.Groups[1].Value;
}

queue_html_base64.Enqueue(new LineProp { line = lines,
p = new Property { Tag = EpropertyTag.PidTagHtml,
Value = "Content-Type: text/html; charset=" + charset + "\nContent-Transfer-Encoding: base64\n\n" +
Convert.ToBase64String(m.Html, Base64FormattingOptions.InsertLineBreaks) } });
}

if (m.RtfCompressed != null)
{
queue_rtf.Enqueue(new LineProp {
line = lines,
p = new Property {
Tag = EpropertyTag.PidTagRtfCompressed,
Value = "Content-Type: application/ms-tnef; name = \"winmail.dat\"\nContent-Transfer-Encoding: base64\n\n" +
Convert.ToBase64String(m.RtfCompressed, Base64FormattingOptions.InsertLineBreaks)
}
});
}


lines++;
}
if (queue_body.Count == 0)
{
queue_body.Enqueue(new LineProp
{
line = 0,
p = new Property
{
Tag = EpropertyTag.PidTagBody,
Value = ""
}
});
}

if (queue_html_utf8.Count == 0)
{
queue_html_utf8.Enqueue(new LineProp
{
line = 0,
p = new Property
{
Tag = EpropertyTag.PidTagNativeBody,
Value = ""
}
});
}

if (queue_html_base64.Count == 0)
{
queue_html_base64.Enqueue(new LineProp
{
line = 0,
p = new Property
{
Tag = EpropertyTag.PidTagHtml,
Value = ""
}
});
}

if (queue_rtf.Count == 0)
{
queue_rtf.Enqueue(new LineProp
{
line = 0,
p = new Property
{
Tag = EpropertyTag.PidTagRtfCompressed,
Value = ""
}
});
}

// Now we sort the columns by ID
var columns = dict.Keys.OrderBy(x => x).ToArray();
Expand Down