private void ShowResourceContent() { try { StringBuilder htmlCtor = StringBuilderPool.Alloc(); string head = "<head>\n<title>Contacts</title>\n<style type=\"text/css\">\n\n" + Style + "</style>\n" + _Script + "</head>\n\n"; htmlCtor.Append("<html>").Append(head); htmlCtor.Append("<body>").Append("<h1>" + _task.DisplayName + "</h1>\n"); htmlCtor.Append("<table id=\"main\" border=\"0\" cellpadding=\"0\" cellspacing=\"4\">\n"); htmlCtor.Append("<tr class=\"top\">\n"); ContsructLeftColumn(htmlCtor); ContsructRightColumn(htmlCtor); htmlCtor.Append("</tr>\n"); htmlCtor.Append("</table>\n"); htmlCtor.Append("</body></html>"); ShowHtml(htmlCtor.ToString(), _ctxRestricted, null); StringBuilderPool.Dispose(htmlCtor); } catch (Exception e) { Utils.DisplayException(e, "Error"); return; } }
/// <summary> /// If the passed item has any categories assigned, renders the category icon to the newspaper view. /// </summary> /// <param name="item">Resource.</param> /// <param name="writer">Output text writer.</param> public static void RenderCategoryIcon(IResource item, TextWriter writer) { // Add the category icon, if the category is ON IResourceList cats = item.GetLinksOfType("Category", "Category"); if (cats.Count != 0) { // Collect the cat names StringBuilder sb = StringBuilderPool.Alloc(); try { foreach (IResource cat in cats) { if (sb.Length > 0) { sb.Append(", "); } sb.Append(cat.DisplayName); } // Add the image writer.WriteLine(" <img class=\"CategoryIcon\" src=\"{0}\" width=\"16\" height=\"16\" alt=\"{1}\" title=\"{1}\" />", GetIconFileName(cats[0]), "Categories: " + sb.ToString()); } finally { StringBuilderPool.Dispose(sb); } } }
private void AddFragment(IResource convs, string text, DateTime date, bool incoming) { StringBuilder bodyBuilder = StringBuilderPool.Alloc(); try { XmlTextWriter xmlWriter = new XmlTextWriter(new StringWriter(bodyBuilder)); try { xmlWriter.WriteStartElement("fragment"); xmlWriter.WriteAttributeString("body", text); xmlWriter.WriteAttributeString("date", date.Ticks.ToString()); xmlWriter.WriteAttributeString("incoming", incoming.ToString()); xmlWriter.WriteEndElement(); xmlWriter.Flush(); convs.GetStringListProp(_propConversationList).Add(bodyBuilder.ToString()); } catch (ArgumentException) { // ignore garbage } finally { xmlWriter.Close(); } } finally { StringBuilderPool.Dispose(bodyBuilder); } }
public string ToString(IResource convs) { StringBuilder bodyBuilder = StringBuilderPool.Alloc(); try { bodyBuilder.Append("<conversation>"); IStringList convsList = convs.GetStringListProp(_propConversationList); if (!_reverseMode) { for (int i = 0; i < convsList.Count; ++i) { bodyBuilder.Append(convsList[i]); } } else { for (int i = convsList.Count - 1; i >= 0; --i) { bodyBuilder.Append(convsList[i]); } } bodyBuilder.Append("</conversation>"); convsList.Dispose(); return(bodyBuilder.ToString()); } finally { StringBuilderPool.Dispose(bodyBuilder); } }
/** * NOTE: if len is not multiple of 3, then more than len bytes * in the bytes array could be used */ public static string Encode(byte[] bytes, int len) { int i = 0; uint code; StringBuilder builder = StringBuilderPool.Alloc(); try { while (len > 0) { code = (uint)bytes[i + 2] + (((uint)bytes[i + 1]) << 8) + (((uint)bytes[i]) << 16); builder.Append(_UUAlphabet[(int)((code >> 18) & 0x3f)]); builder.Append(_UUAlphabet[(int)((code >> 12) & 0x3f)]); builder.Append(_UUAlphabet[(int)((code >> 6) & 0x3f)]); builder.Append(_UUAlphabet[(int)(code & 0x3f)]); i += 3; len -= 3; } return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
internal static string HtmlEntites() { if (_HtmlEntities != null) { return(_HtmlEntities); } StringBuilder sb = StringBuilderPool.Alloc(); try { XmlDocument xml = new XmlDocument(); xml.Load(JetBrains.Omea.HTML.HtmlEntityReader.GetHtmlEntitiesStream()); foreach (XmlElement e in xml.GetElementsByTagName("Entity")) { int val = Int32.Parse(e.GetAttribute("Value")); sb.AppendFormat("<!ENTITY {0} \"{1}\">\n", e.GetAttribute("Name"), (char)val); } _HtmlEntities = sb.ToString(); } catch { _HtmlEntities = ""; } finally { StringBuilderPool.Dispose(sb); } return(_HtmlEntities); }
public void AddResourceDragData(IResourceList dragResources, IDataObject dataObject) { if (!dataObject.GetDataPresent(typeof(string))) { StringBuilder sb = StringBuilderPool.Alloc(); try { foreach (IResource resource in dragResources) { if (sb.Length != 0) { sb.Append(", "); } string text = resource.DisplayName; if (text.IndexOf(' ') > 0) { sb.Append("“" + text + "”"); } else { sb.Append(text); } } dataObject.SetData(sb.ToString()); } finally { StringBuilderPool.Dispose(sb); } } }
private string CleanPreviewText(string body, int lines, bool skipQuoting) { StringBuilder resultBuilder = StringBuilderPool.Alloc(); try { int pos = 0; int foundLines = 0; int quotedLines = 0; while (foundLines < lines) { int nextPos = body.IndexOf('\n', pos); if (nextPos == -1) { if (foundLines < lines - 1 && quotedLines > 0) { return(CleanPreviewText(body, lines, false)); } resultBuilder.Append(body.Substring(pos)); break; } string nextLine = body.Substring(pos, nextPos - pos); pos = nextPos + 1; while (pos < body.Length && body [pos] == '\n') { pos++; } if (skipQuoting && MailBodyParser.GetQuoteLevel(nextLine) > 0) { quotedLines++; continue; } if (foundLines > 0) { resultBuilder.Append("\r\n"); } foundLines++; resultBuilder.Append(nextLine); if (pos == body.Length) { break; } } if (foundLines == 0 && quotedLines > 0) { return(CleanPreviewText(body, lines, false)); } return(resultBuilder.ToString()); } finally { StringBuilderPool.Dispose(resultBuilder); } }
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 static void ParseQuoting(string line, out int quoteLevel, out string quotePrefix, out string quotedText) { int spaces = CountStartingSpaces(line); quoteLevel = 0; StringBuilder quotePrefixBuilder = StringBuilderPool.Alloc(); try { int pos = spaces; bool foundWhitespace = false; while (pos < line.Length) { if (line [pos] == '>') { quoteLevel++; } else if (Char.IsLetter(line, pos)) { // the letters before the first > character are the quote prefix // any other letter stops the quoting if (quoteLevel > 0 || foundWhitespace) { break; } quotePrefixBuilder.Append(line [pos]); } else if (!Char.IsWhiteSpace(line, pos)) { break; } else { foundWhitespace = true; } pos++; } if (quoteLevel > 0) { quotePrefix = quotePrefixBuilder.ToString(); quotedText = line.Substring(pos); } else { quotePrefix = ""; quotedText = line; } } finally { StringBuilderPool.Dispose(quotePrefixBuilder); } }
public static string DecodeMIMEString(string str) { StringBuilder output = StringBuilderPool.Alloc(); try { int begin = 0; int end; while ((begin = str.IndexOf(_mimeBegin, begin)) >= 0) { /** * do not search mime end separator directly, enumerate mime * header parts instead -- this avoids incorrect determination of * header end in case of quotedprintable header */ end = begin + 1; for (int i = 0; i < 3; ++i) { end = str.IndexOf(_mimeSeparator, end + 1); if (end <= 0) { return(output.ToString()); } } string encodedWord = str.Substring(begin + 2, end - begin - 2); string[] sections = encodedWord.Split('?'); if (sections.Length != 3) { throw new BadEncodedWordStructure("Number of sections in encoded word should be equal to 3"); } if (sections[1] == "Q" || sections[1] == "q") // quoted-pritable { ParseQuotedPrintable(sections[0], sections[2].Replace('_', ' '), output); } else if (sections[1] == "B" || sections[1] == "b") // base64 { ParseBase64(sections[0], sections[2], output); } else { throw new BadEncodedWordStructure("Unknown MIME encoding: " + sections[1]); } begin = end; } return(output.ToString()); } finally { StringBuilderPool.Dispose(output); } }
public void InvalidateDisplayName(int abbreviateLevel) { StringBuilder builder = StringBuilderPool.Alloc(); try { InvalidateDisplayName(abbreviateLevel, builder); } finally { StringBuilderPool.Dispose(builder); } }
public static string EncodeQuotedPrintable(byte[] bytes) { StringBuilder builder = StringBuilderPool.Alloc(); try { EncodeQuotedPrintable(bytes, builder); return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
public static string DecodeQuotedPrintable(string charset, string text) { StringBuilder builder = StringBuilderPool.Alloc(); try { ParseQuotedPrintable(charset, text, builder); return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
public static string EncodeQuotedPrintable(string charset, string text) { StringBuilder builder = StringBuilderPool.Alloc(); try { Encoding encoding = GetEncodingExceptionSafe(charset); EncodeQuotedPrintable(encoding.GetBytes(text), builder); return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
public static string ParseMIMEHeader(string header) { StringBuilder result = StringBuilderPool.Alloc(); try { int len = header.Length; for (int i = 0; i < len; ++i) { char c = header[i]; if (c == '=' && i < len - 1 && header[i + 1] == '?') { int mimeStrEnd = i + 1; for (int j = 0; mimeStrEnd > 0 && j < 3; ++j) { mimeStrEnd = header.IndexOf('?', mimeStrEnd + 1); } if (mimeStrEnd > 0 && mimeStrEnd < len - 1 && header[mimeStrEnd + 1] == '=') { result.Append( MIMEParser.DecodeMIMEString(header.Substring(i, mimeStrEnd - i + 2))); i = mimeStrEnd + 1; } else { result.Append(MIMEParser.DecodeMIMEString(header.Substring(i))); i = len; } } else { result.Append(c); } } return(result.ToString()); } catch { } finally { StringBuilderPool.Dispose(result); } return(header); }
public string ToHtmlString(IResource convs, int propDisplayName) { StringBuilder htmlBuilder = StringBuilderPool.Alloc(); try { ToHtmlHead(htmlBuilder); ToHtmlBody(convs, propDisplayName, htmlBuilder); ToHtmlEnd(htmlBuilder); Trace.WriteLine(htmlBuilder.ToString()); return(htmlBuilder.ToString()); } finally { StringBuilderPool.Dispose(htmlBuilder); } }
public static string CreateQuotedPrintableMIMEString(string charset, string text) { StringBuilder builder = StringBuilderPool.Alloc(); try { builder.Append(_mimeBegin); builder.Append(charset); builder.Append("?Q?"); EncodeQuotedPrintable(GetEncodingExceptionSafe(charset).GetBytes(text), builder); builder.Append("?="); return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
public string GetPreviewText(IResource res, int lines) { StringBuilder builder = StringBuilderPool.Alloc(); try { builder.Append("<conversation>"); IStringList convsList = res.GetStringListProp(_manager._propConversationList); if (!_manager._reverseMode) { for (int i = 0; i < convsList.Count && lines-- > 0; ++i) { builder.Append(convsList[i]); } } else { for (int i = convsList.Count - 1; i >= 0 && lines-- > 0; --i) { builder.Append(convsList[i]); } } convsList.Dispose(); builder.Append("</conversation>"); XmlTextReader reader = new XmlTextReader(new StringReader(builder.ToString())); builder.Length = 0; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.MoveToAttribute("body")) { builder.AppendFormat("{0}\r\n", reader.Value); } reader.MoveToElement(); } } return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
/** * returns the index of last processed line in the array */ private int ProcessBody(string[] lines, int fisrtLine, string boundary, MessagePartEncoding MIME_encoding, string bodyCharset) { int i = fisrtLine; if (MIME_encoding == MessagePartEncoding.Base64) { StringBuilder builder = StringBuilderPool.Alloc(); try { for ( ; i < lines.Length; ++i) { string line = lines[i].TrimEnd('\r'); if (line.StartsWith(boundary)) { break; } builder.Append(line); } _bodyBuilder.Append(DecodeLine(builder.ToString(), MIME_encoding, bodyCharset)); } finally { StringBuilderPool.Dispose(builder); } } else { for ( ; i < lines.Length; ++i) { string line = lines[i].TrimEnd('\r'); if (line.StartsWith(boundary)) { break; } _bodyBuilder.Append(DecodeLine(line, MIME_encoding, bodyCharset)); if (MIME_encoding != MessagePartEncoding.QuotedPrintable || !line.EndsWith("=")) { _bodyBuilder.Append("\r\n"); } } } return(i); }
/** * Adds a pending paragraph (possibly quoted) to the paragraph list. */ private void AddTextPara(ArrayList lines, bool beforeEmptyLine) { if (lines.Count > 0) { PlainTextParaType paraType = IsPlainTextPara(lines); if (paraType == PlainTextParaType.Plain) { StringBuilder bodyBuilder = StringBuilderPool.Alloc(); try { for (int i = 0; i < lines.Count - 1; i++) { string line = (string)lines [i]; bodyBuilder.Append(line); if (!line.EndsWith(" ")) { bodyBuilder.Append(" "); } } bodyBuilder.Append(lines [lines.Count - 1]); _paragraphs.Add(new Paragraph(bodyBuilder.ToString(), ParagraphType.Plain, _lastQuoteLevel, _lastQuotePrefix, _foundOutlookQuote)); } finally { StringBuilderPool.Dispose(bodyBuilder); } } else if (paraType == PlainTextParaType.Fixed) { AddFixedParas(lines, beforeEmptyLine); } else { foreach (string line in lines) { _paragraphs.Add(new Paragraph(line, ParagraphType.Plain, _lastQuoteLevel, _lastQuotePrefix, _foundOutlookQuote)); } } } }
private void ReleasePooledBuffer() { if (_pooledBuilder != null) { _pooledBuilder.Dispose(); _pooledBuilder = null; _builder = null; if (_previousPooledBuilders != null) { foreach (var pooledBuilder in _previousPooledBuilders) { pooledBuilder.Dispose(); } _previousPooledBuilders.Clear(); _previousPooledBuilders = null; } } }
public static string GenerateArticleId(IResource article, string domainName) { StringBuilder builder = StringBuilderPool.Alloc(); try { builder.Append('<'); builder.AppendFormat("{0:x4}", Environment.MachineName.ToLower().GetHashCode()); builder.AppendFormat("{0:x4}", article.Id); builder.AppendFormat("{0:x8}", DateTime.Now.Ticks); builder.Append('@'); builder.Append(domainName.ToLower()); builder.Append('>'); return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
public override string HtmlContent(IResource contact) { StringBuilder result = StringBuilderPool.Alloc(); try { if (contact.GetPropText(ContactManager._propTitle).Length > 0) { result.Append(OptionalTag(contact, "Title:", ContactManager._propTitle)); } result.Append(ObligatoryTag(contact, "First Name:", ContactManager._propFirstName)); result.Append(ObligatoryTag(contact, "Mid Name:", ContactManager._propMiddleName)); result.Append(ObligatoryTag(contact, "Last Name:", ContactManager._propLastName)); if (contact.GetPropText(ContactManager._propSuffix).Length > 0) { result.Append(OptionalTag(contact, "Suffix:", ContactManager._propSuffix)); } bool showAllNames = contact.HasProp(Core.ContactManager.Props.ShowOriginalNames); if (showAllNames) { ArrayList uniqueNames = CollectUniqueContactNames(contact, showAllNames); if (((uniqueNames.Count > 1) || (uniqueNames.Count == 1 && (string)uniqueNames[0] != contact.DisplayName))) { result.Append("\t<tr><td>Available Names:</td><td>"); foreach (string name in uniqueNames) { result.Append(name).Append("<br/>"); } result.Append("</td></tr>"); } } return(result.ToString()); } finally { StringBuilderPool.Dispose(result); } }
public override string ToString() { StringBuilder builder = StringBuilderPool.Alloc(); try { for (int i = 0; i < Count; i++) { if (i > 0) { builder.Append(_toStringSeparator); } builder.Append(this [i].ToString()); } return(builder.ToString()); } finally { StringBuilderPool.Dispose(builder); } }
private static string EscapeSinglePeriodsAndTranslateToCharset(string body, string charset) { string[] lines; lines = body.Split('\n'); bool areSinglePeriods = false; for (int i = 0; i < lines.Length; ++i) { if (lines[i].StartsWith(".")) { lines[i] = lines[i].Insert(0, "."); areSinglePeriods = true; } } StringBuilder bodyBuilder = StringBuilderPool.Alloc(); try { if (areSinglePeriods) { for (int i = 0; i < lines.Length; ++i) { bodyBuilder.Append(lines[i]); bodyBuilder.Append('\n'); } body = bodyBuilder.ToString(); } bodyBuilder.Length = 0; byte[] bytes = MIMEParser.GetEncodingExceptionSafe(charset).GetBytes(body); for (int i = 0; i < bytes.Length; ++i) { bodyBuilder.Append((char)bytes[i]); } return(bodyBuilder.ToString()); } finally { StringBuilderPool.Dispose(bodyBuilder); } }
public static string BuildPlainTextFlowedBody(string body, string charset) { StringBuilder bodyBuilder = StringBuilderPool.Alloc(); try { string[] lines = body.Split('\n'); foreach (string line in lines) { string lineCopy = line; while (lineCopy.Length > _PlainTextFlowedLineMaxLen) { int i; for (i = _PlainTextFlowedLinePreferredLen; i < lineCopy.Length && !Char.IsWhiteSpace(lineCopy[i]); ++i) { ; } if (i == lineCopy.Length) { break; } bodyBuilder.Append(lineCopy.Substring(0, i + 1)); lineCopy = lineCopy.Substring(i + 1); if (lineCopy.Length > 0) { bodyBuilder.Append("\r\n"); } } bodyBuilder.Append(lineCopy); bodyBuilder.Append('\n'); } return(EscapeSinglePeriodsAndTranslateToCharset(bodyBuilder.ToString(), charset)); } finally { StringBuilderPool.Dispose(bodyBuilder); } }
private void LogBookmarkChange(BookmarkChange change) { if (!Core.ResourceStore.IsOwnerThread()) { Core.ResourceAP.QueueJob(new LogBookmarkChangeDelegate(LogBookmarkChange), change); } else { StringBuilder historyStr = StringBuilderPool.Alloc(); try { historyStr.AppendFormat("{0}\x01{1}\x01{2}\x01{3}\x01{4}\x01{5}\x01{6}\x01{7}\x01{8}", change.type, change.id, change.rdfid, change.oldparent, change.oldparent_id, change.parent, change.parent_id, change.name, change.url); _root.GetStringListProp(FavoritesPlugin._propChangesLog).Add(historyStr.ToString()); } finally { StringBuilderPool.Dispose(historyStr); } } }
private void ShowResourceContent() { try { StringBuilder htmlCtor = StringBuilderPool.Alloc(); string head = "<head><title>Contacts</title><style type=\"text/css\">" + "\n" + Style + "</style>"; htmlCtor.Append("<html>").Append(head).Append("\n").Append(_Script).Append("\n</head>\n").Append("<body>"); AppendHeader(htmlCtor); htmlCtor.Append("<table id=\"main\" border=\"0\" cellpadding=\"0\" cellspacing=\"4\">\n"); htmlCtor.Append("<tr class=\"top\">\n"); ContsructColumn(_leftBlocks, htmlCtor); ContsructColumn(_rightBlocks, htmlCtor); htmlCtor.Append("</tr>\n"); ConstructCorrespondenceBlock(htmlCtor); int mergeCandidates = ContactManager.GetContactsForMerging(_contact).Count; if (mergeCandidates > 0) { string verb = (mergeCandidates == 1) ? " is " : " are "; string ending = (mergeCandidates == 1) ? "" : "s"; string text = "<p style=\"color:#aca899\"> There" + verb + mergeCandidates + " contact" + ending + " suggested for merging</p>"; htmlCtor.Append("<tr><td class=\"text\" colspan=\"2\">").Append(text).Append("</td></tr>"); } htmlCtor.Append("</table>").Append("</body></html>"); ShowHtml(htmlCtor.ToString(), _ctxRestricted, null); StringBuilderPool.Dispose(htmlCtor); } catch (Exception ex) { Core.ReportException(ex, false); return; } }
public override void EditResource(IResource contact) { SuspendLayout(); try { IResourceList uinList = contact.GetLinksOfType(ICQPlugin._icqAccountResName, ICQPlugin._propICQAcct); if (uinList.Count == 0) { _uinsList.ForeColor = SystemColors.GrayText; _uinsList.Enabled = false; _uinsList.Text = "Not Specified"; } else { _uinsList.ForeColor = SystemColors.ControlText; _uinsList.Enabled = true; StringBuilder uinBuilder = StringBuilderPool.Alloc(); try { foreach (IResource uin in uinList) { uinBuilder.Append(uin.ToString()).Append(';'); } _uinsList.Text = uinBuilder.ToString(0, uinBuilder.Length - 2); } finally { StringBuilderPool.Dispose(uinBuilder); } } Height = _uinsList.PreferredHeight; _uinsList.BackColor = BackColor; } finally { ResumeLayout(); } }