diff --git a/XstFile.cs b/XstFile.cs index c79f5a5..75fd124 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 @@ -355,8 +365,102 @@ public void ExportMessageProperties(IEnumerable 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();