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"); } } }
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); } }
private void QuoteParagraphWithPrefix(StringBuilder quoteBuilder, string prefix, string text, QuoteSettings settings) { int lineLength = settings.QuoteMargin - prefix.Length; int pos = 0; while (pos < text.Length) { int newPos = pos + lineLength; if (newPos > text.Length) { newPos = text.Length; } else if (newPos < text.Length) { while (newPos > pos && !Char.IsWhiteSpace(text, newPos)) { newPos--; } if (newPos == pos) // no word break found, split word { newPos = pos + lineLength; } } quoteBuilder.Append(prefix); quoteBuilder.Append(text.Substring(pos, newPos - pos).Trim()); quoteBuilder.Append("\r\n"); while (newPos < text.Length && Char.IsWhiteSpace(text, newPos)) { newPos++; } pos = newPos; } }
public string QuoteMessage(IResource resource, string body, QuoteSettings settings) { MailBodyParser parser = new MailBodyParser(body, 50); return(_quoter.Quote(parser, resource, settings)); }
public string QuoteMessage(IResource resource, int bodyProp, QuoteSettings settings) { return(QuoteMessage(resource, resource.GetPropText(bodyProp), settings)); }