Exemplo n.º 1
0
        private void ShowMessage(Message m)
        {
            try
            {
                if (m != null)
                {
                    // Can't bind HTML content, so push it into the control, if the message is HTML
                    if (m.ShowHtml)
                    {
                        string embedded = null;
                        if (m.MayHaveInlineAttachment)
                        {
                            embedded = m.EmbedAttachments(xstFile);  // Returns null if this is not appropriate
                        }
                        if (embedded != 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);
                        }
                    }
                    // Can't bind RTF content, so push it into the control, if the message is RTF
                    else if (m.ShowRtf)
                    {
                        var decomp = new RtfDecompressor();

                        using (System.IO.MemoryStream ms = decomp.Decompress(m.RtfCompressed, true))
                        {
                            ms.Position = 0;
                            rtfMessage.SelectAll();
                            rtfMessage.Selection.Load(ms, DataFormats.Rtf);
                        }
                    }
                }
                else
                {
                    // Clear the HTML, in case we were showing that before
                    wbMessage.Navigate("about:blank");

                    // Clear the RTF, in case we were showing that before
                    rtfMessage.Document.Blocks.Clear();
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error reading message body");
            }
        }
Exemplo n.º 2
0
        public FlowDocument GetBodyAsFlowDocument()
        {
            FlowDocument doc = new FlowDocument();

            var decomp = new RtfDecompressor();

            using (System.IO.MemoryStream ms = decomp.Decompress(RtfCompressed, true))
            {
                ms.Position = 0;
                TextRange selection = new TextRange(doc.ContentStart, doc.ContentEnd);
                selection.Load(ms, DataFormats.Rtf);
            }
            // For debug, a way to look at the document
            //var infoString = System.Windows.Markup.XamlWriter.Save(doc);
            return(doc);
        }