From 0be7c343eb263f68ab37d9e34dcb404b64d39711 Mon Sep 17 00:00:00 2001 From: Haruyasu Ueda Date: Thu, 18 Apr 2019 21:06:39 +0900 Subject: [PATCH 1/3] Extension for #10 Add Body and NativeBody to dictionary to export them. --- XstFile.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/XstFile.cs b/XstFile.cs index c79f5a5..5227d95 100644 --- a/XstFile.cs +++ b/XstFile.cs @@ -355,6 +355,15 @@ public void ExportMessageProperties(IEnumerable messages, string fileNa } queue.Enqueue(new LineProp { line = lines, p = p }); } + + queue = new Queue(); + dict[ "Body" ] = queue; + queue.Enqueue(new LineProp { line = lines, p = m.Body }); + + queue = new Queue(); + dict[ "NativeBody" ] = queue; + queue.Enqueue(new LineProp { line = lines, p = m.NativeBody }); + lines++; } From 20038a3baab455161371c8452c05e67302474ce7 Mon Sep 17 00:00:00 2001 From: Haruyasu Ueda Date: Thu, 9 May 2019 13:14:48 +0900 Subject: [PATCH 2/3] export message body in four top columns - plain text as utf8 - HTML text as utf8 - HTML text as base64 with part header - RTFcompressed as base64 with part header CSV looks fine. HTML in base64 is rendered correctly with Outlook, if they are combined into eml format. RTF is not checked yet. --- XstFile.cs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/XstFile.cs b/XstFile.cs index 5227d95..3d48d2a 100644 --- a/XstFile.cs +++ b/XstFile.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Windows; +using System.Text.RegularExpressions; namespace XstReader { @@ -329,6 +330,15 @@ public void ExportMessageProperties(IEnumerable messages, string fileNa var dict = new Dictionary>(); int lines = 1; + Queue queue_body = new Queue(); + dict["0000Body"] = queue_body; + Queue queue_html_utf8 = new Queue(); + dict["0000HTML_utf8"] = queue_html_utf8; + Queue queue_html_base64 = new Queue(); + dict["0000HTML_base64"] = queue_html_base64; + Queue queue_rtf = new Queue(); + dict["0000RTF"] = queue_rtf; + foreach (var m in messages) { // Do not reread properties for current message as it will fail updating the display @@ -356,13 +366,47 @@ public void ExportMessageProperties(IEnumerable messages, string fileNa queue.Enqueue(new LineProp { line = lines, p = p }); } - queue = new Queue(); - dict[ "Body" ] = queue; - queue.Enqueue(new LineProp { line = lines, p = m.Body }); + 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) + } + }); + } - queue = new Queue(); - dict[ "NativeBody" ] = queue; - queue.Enqueue(new LineProp { line = lines, p = m.NativeBody }); lines++; } From 97ed0e8935bd6b9f443c08251aa3f2ecbcd2d488 Mon Sep 17 00:00:00 2001 From: Haruyasu Ueda Date: Thu, 9 May 2019 13:24:22 +0900 Subject: [PATCH 3/3] Fix: added queue for body can be empty Queues for body are always added to dict, but some queue can have no contents. In such case, CSV header output failed. Add dummy line for CSV header if the queue is empty. --- XstFile.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/XstFile.cs b/XstFile.cs index 3d48d2a..75fd124 100644 --- a/XstFile.cs +++ b/XstFile.cs @@ -410,6 +410,57 @@ public void ExportMessageProperties(IEnumerable messages, string fileNa 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();