Exemplo n.º 1
0
 private void QuoteParagraph(StringBuilder quoteBuilder, string initials,
                             MailBodyParser.Paragraph para, QuoteSettings settings)
 {
     if (para.Type != ParagraphType.Sig)
     {
         string newQuotePrefix;
         if (para.OutlookQuote)
         {
             newQuotePrefix = ">> ";
         }
         else if (para.QuoteLevel == 0)
         {
             newQuotePrefix = initials + "> ";
         }
         else
         {
             newQuotePrefix = para.QuotePrefix + new string( '>', para.QuoteLevel + 1 ) + " ";
         }
         QuoteParagraphWithPrefix(quoteBuilder, newQuotePrefix, para.Text, settings);
         if (para.Type == ParagraphType.Plain)
         {
             quoteBuilder.Append(newQuotePrefix);
             quoteBuilder.Append("\r\n");
         }
     }
 }
Exemplo n.º 2
0
        public string Quote(MailBodyParser parser, IResource origMail, QuoteSettings quoteSettings)
        {
            StringBuilder quoteBuilder = StringBuilderPool.Alloc();

            try
            {
                string initials = "";

                if (origMail != null)
                {
                    IResourceList senders = origMail.GetLinksOfType("Contact", "From");
                    if (senders.Count > 0)
                    {
                        IResource sender = senders [0];

                        string name = sender.GetPropText("FirstName");
                        if (name.Length == 0)
                        {
                            name = sender.DisplayName;
                        }
                        if (quoteSettings.PrefixInitials)
                        {
                            initials = GetInitials(sender);
                        }
                        if (quoteSettings.GreetingInReplies)
                        {
                            quoteBuilder.Append(quoteSettings.GreetingString + " " + name + ",\r\n\r\n");
                        }
                    }
                }

                if (quoteSettings.UseSignature && quoteSettings.SignatureInReplies == SignaturePosition.BeforeQuote)
                {
                    quoteBuilder.Append("\r\n");
                    quoteBuilder.Append(quoteSettings.Signature);
                    quoteBuilder.Append("\r\n\r\n");
                }

                for (int i = 0; i < parser.ParagraphCount; i++)
                {
                    MailBodyParser.Paragraph para = parser.GetParagraph(i);
                    QuoteParagraph(quoteBuilder, initials, para, quoteSettings);
                }

                if (quoteSettings.UseSignature && quoteSettings.SignatureInReplies == SignaturePosition.AfterQuote)
                {
                    quoteBuilder.Append(quoteSettings.Signature);
                }

                return(quoteBuilder.ToString());
            }
            finally
            {
                StringBuilderPool.Dispose(quoteBuilder);
            }
        }
Exemplo n.º 3
0
        private static void FormatBody(MailBodyParser parser, string subject, HtmlLinkConverter converter, string style, bool noWrap)
        {
            _builder.Append("<html><head>").Append(style).
            Append(Core.MessageFormatter.DualMediaSubjectStyle).Append("</head><body>");
            if (!String.IsNullOrEmpty(subject))
            {
                _builder.Append(MessageFormatter.FormattedHeader(subject));
            }

            int    oldQuoteLevel  = 0;
            string oldQuotePrefix = "";

            for (int i = 0; i < parser.ParagraphCount; i++)
            {
                MailBodyParser.Paragraph para = parser.GetParagraph(i);
                if (para.QuoteLevel > 0)
                {
                    if (!_quoteTableStarted)
                    {
                        _builder.Append(_cTableStartTag);
                        _quoteTableStarted = true;
                        _quoteRowStarted   = false;
                    }

                    if (_quoteRowStarted)
                    {
                        if (oldQuoteLevel != para.QuoteLevel || oldQuotePrefix != para.QuotePrefix)
                        {
                            _builder.Append("</td></tr>");
                            _quoteRowStarted = false;
                        }
                    }

                    if (!_quoteRowStarted)
                    {
                        _builder.Append("<tr class=\"");
                        _builder.Append((para.QuoteLevel % 2 != 0) ? "oddquote" : "evenquote");
                        _builder.Append("\"><td>");
                        _builder.Append(HTMLEncode(para.QuotePrefix));
                        for (int q = 0; q < para.QuoteLevel; q++)
                        {
                            _builder.Append("&gt;");
                        }
                        _builder.Append("</td><td>");
                        _quoteRowStarted = true;
                    }
                    else
                    {
                        _builder.Append("<br>");
                    }

                    if (para.Type == ParagraphType.Fixed)
                    {
                        _builder.Append(converter.ConvertLinks(ReplaceSpaces(HTMLEncode(para.Text), noWrap)));
                    }
                    else
                    {
                        // show an extra separator line above and below every quoted
                        // plain-text paragraph
                        if (i > 0)
                        {
                            MailBodyParser.Paragraph prevPara = parser.GetParagraph(i - 1);
                            if (prevPara.Type != ParagraphType.Plain && prevPara.QuoteLevel == para.QuoteLevel &&
                                prevPara.QuotePrefix == para.QuotePrefix)
                            {
                                _builder.Append("<br>");
                            }
                        }
                        _builder.Append(converter.ConvertLinks(HTMLEncode(para.Text)));
                        _builder.Append("<br>");
                    }
                }
                else
                {
                    CloseOpenElements();
                    switch (para.Type)
                    {
                    case ParagraphType.Plain:
                        _builder.Append("<p>");
                        if (para.OutlookQuote)
                        {
                            _builder.Append("<span class=\"outlookquote\">");
                            _builder.Append(converter.ConvertLinks(HTMLEncode(para.Text)));
                            _builder.Append("</span>");
                        }
                        else
                        {
                            _builder.Append(converter.ConvertLinks(HTMLEncode(para.Text)));
                        }
                        _builder.Append("</p>\r\n");
                        break;

                    case ParagraphType.Fixed:
                    case ParagraphType.Service:
                        if (para.OutlookQuote)
                        {
                            _builder.Append("<span class=\"outlookquote\">");
                            _builder.Append(converter.ConvertLinks(ReplaceSpaces(HTMLEncode(para.Text), noWrap)));
                            _builder.Append("</span>");
                        }
                        else
                        {
                            _builder.Append(converter.ConvertLinks(ReplaceSpaces(HTMLEncode(para.Text), noWrap)));
                        }
                        _builder.Append("<br>\r\n");
                        break;

                    case ParagraphType.Sig:
                        _builder.Append("<span class=\"sig\">");
                        _builder.Append(converter.ConvertLinks(para.Text));
                        _builder.Append("</span></br>");
                        break;
                    }
                }
                oldQuoteLevel  = para.QuoteLevel;
                oldQuotePrefix = para.QuotePrefix;
            }
            CloseOpenElements();
            _builder.Append("</body></html> ");
        }