diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 69c4ddb..065646a 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -298,27 +298,15 @@ private void ShowMessage(Message m) // Can't bind HTML content, so push it into the control, if the message is HTML if (m.ShowHtml) { - string embedded = null; + string body = m.GetBodyAsHtmlString(); if (m.MayHaveInlineAttachment) - embedded = m.EmbedAttachments(xstFile); // Returns null if this is not appropriate + body = m.EmbedAttachments(body, xstFile); // Returns null if this is not appropriate - if (embedded != null) + if (body != null) { - wbMessage.NavigateToString(embedded); - m.SortAndSaveAttachments(); // Re-sort attachments in case any new in-line rendering discovered - } - else if (m.BodyHtml != null) - { - wbMessage.NavigateToString(m.BodyHtml); - } - else if (m.Html != null) - { - var ms = new System.IO.MemoryStream(m.Html); - wbMessage.NavigateToStream(ms); - } - else if (m.Body != null) - { - wbMessage.NavigateToString(m.Body); + wbMessage.NavigateToString(body); + if (m.MayHaveInlineAttachment) + m.SortAndSaveAttachments(); // Re-sort attachments in case any new in-line rendering discovered } } // Can't bind RTF content, so push it into the control, if the message is RTF diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 1d7e9a5..a8115a8 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -51,4 +51,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.*")] +[assembly: AssemblyVersion("1.5.*")] diff --git a/View.cs b/View.cs index 442bab4..55f9755 100644 --- a/View.cs +++ b/View.cs @@ -183,31 +183,34 @@ class Message ((BodyHtml != null && BodyHtml.Length > 0) || (Html != null && Html.Length > 0))); } } public bool ShowRtf { get { return NativeBody == BodyType.RTF || (NativeBody == BodyType.Undefined && RtfCompressed != null && RtfCompressed.Length > 0); } } - public string EmbedAttachments(XstFile xst) + public string GetBodyAsHtmlString() { - string raw = null; - if (BodyHtml != null) - raw = BodyHtml; + return BodyHtml; // This will be plain ASCII else if (Html != null) { var e = GetEncoding(); if (e != null) { - raw = new String(e.GetChars(Html)); + return EscapeUnicodeCharacters(new String(e.GetChars(Html))); } } - else if (Body != null) - raw = Body; + else if (Body != null) // Not really expecting this as a source of HTML + return EscapeUnicodeCharacters(Body); - if (raw == null) + return null; + } + + public string EmbedAttachments(string body, XstFile xst) + { + if (body == null) return null; var dict = new Dictionary(); foreach (var a in Attachments.Where(x => x.HasContentId)) dict.Add(a.ContentId, a); - return Regex.Replace(raw, @"(="")cid:(.*?)("")", match => + return Regex.Replace(body, @"(="")cid:(.*?)("")", match => { Attachment a; @@ -251,6 +254,28 @@ public void SortAndSaveAttachments(List atts = null) Attachments.Add(a); } + private static string EscapeUnicodeCharacters(string source) + { + int length = source.Length; + var escaped = new StringBuilder(); + + for (int i = 0; i < length; i++) + { + char ch = source[i]; + + if (ch >= '\x00a0') + { + escaped.AppendFormat("&#x{0};", ((int)ch).ToString("X4")); + } + else + { + escaped.Append(ch); + } + } + + return escaped.ToString(); + } + private string EscapeString(string s) { var sb = new StringBuilder(s.Length);