public CalendarWriter(Stream stream, string encodingName) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanWrite) { throw new ArgumentException(CalendarStrings.StreamMustAllowWrite, "stream"); } if (encodingName == null) { throw new ArgumentNullException("encodingName"); } this.writer = new ContentLineWriter(stream, Charset.GetEncoding(encodingName)); }
private static void GenerateOldFashionedReportBody(MessageItem message, Stream outputStream, out CultureInfo cultureInfo, out Charset charset) { Encoding unicode = Encoding.Unicode; string text = ReportMessage.GenerateOldFashionedReportBody(message, out cultureInfo).ToString(cultureInfo); OutboundCodePageDetector outboundCodePageDetector = new OutboundCodePageDetector(); outboundCodePageDetector.AddText(text); charset = Charset.GetCharset(outboundCodePageDetector.GetCodePage(Culture.GetCulture(cultureInfo.Name), false)); using (MemoryStream memoryStream = new MemoryStream(unicode.GetBytes(text))) { new TextToHtml { InputEncoding = unicode, OutputEncoding = charset.GetEncoding() }.Convert(memoryStream, outputStream); } }
// Token: 0x0600003F RID: 63 RVA: 0x00004608 File Offset: 0x00002808 private bool TryWriteNotificationWithAppendedComments(DsnHumanReadableWriter notificationWriter, MessageItem rejectItem, StreamAttachment commentAttachment, ApprovalInformation info) { bool result = true; string htmlModerationBody = notificationWriter.GetHtmlModerationBody(info); Charset textCharset = commentAttachment.TextCharset; Encoding inputEncoding = null; if (textCharset == null || !textCharset.TryGetEncoding(out inputEncoding)) { return(false); } Charset charset = textCharset; if (!ModeratedDLApplication.IsEncodingMatch(info.Codepages, textCharset.CodePage)) { charset = Charset.UTF8; } BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, charset.Name); using (Stream stream = rejectItem.Body.OpenWriteStream(configuration)) { HtmlToHtml htmlToHtml = new HtmlToHtml(); htmlToHtml.Header = htmlModerationBody; htmlToHtml.HeaderFooterFormat = HeaderFooterFormat.Html; htmlToHtml.InputEncoding = inputEncoding; htmlToHtml.OutputEncoding = charset.GetEncoding(); try { using (Stream contentStream = commentAttachment.GetContentStream(PropertyOpenMode.ReadOnly)) { htmlToHtml.Convert(contentStream, stream); stream.Flush(); } } catch (ExchangeDataException arg) { ModeratedDLApplication.diag.TraceDebug <ExchangeDataException>(0L, "Attaching comments failed with {0}", arg); result = false; } } return(result); }
protected void Process(TextTokenId tokenId) { switch (tokenId) { case TextTokenId.Text: OutputFragmentSimple(parser.Token); break; case TextTokenId.EncodingChange: if (output != null && output.OutputCodePageSameAsInput) { var codePage = parser.Token.Argument; #if DEBUG Encoding newOutputEncoding; InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding)); #endif output.OutputEncoding = Charset.GetEncoding(codePage); } break; case TextTokenId.EndOfFile: if (injection != null && injection.HaveTail) { AddLineBreak(1); InternalDebug.Assert(output != null); } // close the paragraph container CloseContainer(); // close the document container CloseAllContainersAndSetEOF(); break; } }
private static object FromHtmlToHtml(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader) { Charset itemMimeCharset = ConvertUtils.GetItemMimeCharset(coreItem.PropertyBag); Charset charset = configuration.Charset; HtmlToHtml htmlToHtml = new HtmlToHtml(); htmlToHtml.InputEncoding = itemMimeCharset.GetEncoding(); htmlToHtml.OutputEncoding = charset.GetEncoding(); htmlToHtml.Header = configuration.InjectPrefix; htmlToHtml.Footer = configuration.InjectSuffix; htmlToHtml.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat; htmlToHtml.DetectEncodingFromMetaTag = false; htmlToHtml.FilterHtml = configuration.FilterHtml; htmlToHtml.HtmlTagCallback = configuration.InternalHtmlTagCallback; htmlToHtml.OutputHtmlFragment = configuration.IsHtmlFragment; if (configuration.StyleSheetLimit != null) { TextConvertersInternalHelpers.SetSmallCssBlockThreshold(htmlToHtml, configuration.StyleSheetLimit.Value); } return(BodyReadDelegates.GetTextStreamOrReader(bodyStream, htmlToHtml, createReader)); }
public static string ConvertHtmlToPlainText(string message) { StringReader stringReader = null; StringWriter stringWriter = null; string result; try { if (message == null) { result = null; } else { int codePage = 65001; stringReader = new StringReader(message); stringWriter = new StringWriter(); new HtmlToText { InputEncoding = Charset.GetEncoding(codePage), OutputEncoding = Charset.GetEncoding(codePage) }.Convert(stringReader, stringWriter); result = stringWriter.ToString(); } } finally { if (stringReader != null) { stringReader.Dispose(); } if (stringWriter != null) { stringWriter.Dispose(); } } return(result); }
public Stream GetContentWriteStream(string charsetName) { BodyFormat bodyFormat = this.BodyFormat; if (bodyFormat == BodyFormat.None) { throw new InvalidOperationException(EmailMessageStrings.CannotWriteBodyDoesNotExist); } if (BodyFormat.Rtf == bodyFormat) { throw new InvalidOperationException(EmailMessageStrings.NotSupportedForRtfBody); } Charset charset; Charset.TryGetCharset(this.CharsetName, out charset); Charset charset2 = Charset.GetCharset(charsetName); bool flag = charset == null || charset.CodePage != charset2.CodePage; if (flag) { charset2.GetEncoding(); } return(this.Message.Body_GetContentWriteStream(charset2)); }
private void Process(HtmlTokenId tokenId) { this.token = this.parser.Token; switch (tokenId) { case HtmlTokenId.Tag: if (this.token.TagIndex <= HtmlTagIndex.Unknown) { break; } HtmlDtd.TagDefinition tagDef = GetTagDefinition(this.token.TagIndex); if (this.normalizedInput) { if (!this.token.IsEndTag) { if (this.token.IsTagBegin) { this.PushElement(tagDef); } this.ProcessStartTagAttributes(tagDef); } else { if (this.token.IsTagBegin) { this.PopElement(tagDef); } } } else { if (!this.token.IsEndTag) { if (this.token.IsTagBegin) { this.LFillTagB(tagDef); this.PushElement(tagDef); this.RFillTagB(tagDef); } this.ProcessStartTagAttributes(tagDef); } else { if (this.token.IsTagBegin) { this.LFillTagE(tagDef); this.PopElement(tagDef); this.RFillTagE(tagDef); } } } break; case HtmlTokenId.Text: if (!this.insideComment) { if (this.insideAnchor && this.urlCompareSink.IsActive) { token.Text.WriteTo(this.urlCompareSink); } if (this.insidePre) { this.ProcessPreformatedText(); } else if (this.normalizedInput) { this.ProcessText(); } else { this.NormalizeProcessText(); } } break; case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; case HtmlTokenId.Restart: break; case HtmlTokenId.EncodingChange: if (this.output.OutputCodePageSameAsInput) { int codePage = this.token.Argument; #if DEBUG Encoding newOutputEncoding; InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding)); #endif this.output.OutputEncoding = Charset.GetEncoding(codePage); } break; case HtmlTokenId.EndOfFile: if (this.lineStarted) { this.output.OutputNewLine(); this.lineStarted = false; } if (!this.convertFragment) { if (this.injection != null && this.injection.HaveHead) { if (this.wideGap) { this.output.OutputNewLine(); this.wideGap = false; } this.injection.Inject(false, this.output); } this.output.CloseDocument(); this.output.Flush(); } this.endOfFile = true; break; } }
private static void WriteOutlookSearchFolderDefinitionBlob(MessageItem message, Restriction restriction, bool deepTraversal, StoreId[] folderScope) { using (Stream stream = message.OpenPropertyStream(InternalSchema.AssociatedSearchFolderDefinition, PropertyOpenMode.Create)) { using (BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.Unicode)) { Charset itemWindowsCharset = ConvertUtils.GetItemWindowsCharset(message); OutlookBlobWriter outlookBlobWriter = new OutlookBlobWriter(binaryWriter, itemWindowsCharset.GetEncoding()); outlookBlobWriter.WriteInt(4100); outlookBlobWriter.WriteInt(72); outlookBlobWriter.WriteInt(0); outlookBlobWriter.WriteString(string.Empty); outlookBlobWriter.WriteSkipBlock(); outlookBlobWriter.WriteBool(deepTraversal); outlookBlobWriter.WriteString(string.Empty); outlookBlobWriter.WriteEntryIdList(folderScope); outlookBlobWriter.WriteSkipBlock(); outlookBlobWriter.WriteRestriction(restriction); outlookBlobWriter.WriteSkipBlock(); } } }
private static Restriction ReadOutlookSearchFolderDefinitionBlob(MessageItem message, out bool deepTraversal, out StoreId[] ids) { Restriction result = null; try { using (Stream stream = message.OpenPropertyStream(InternalSchema.AssociatedSearchFolderDefinition, PropertyOpenMode.ReadOnly)) { using (BinaryReader binaryReader = new BinaryReader(stream, Encoding.Unicode)) { Charset itemWindowsCharset = ConvertUtils.GetItemWindowsCharset(message); OutlookBlobReader outlookBlobReader = new OutlookBlobReader(binaryReader, itemWindowsCharset.GetEncoding()); int num = outlookBlobReader.ReadInt(); if (num != 4100) { throw new CorruptDataException(ServerStrings.ExSearchFolderCorruptOutlookBlob("version")); } int num2 = outlookBlobReader.ReadInt(); if (num2 != 72) { throw new CorruptDataException(ServerStrings.ExSearchFolderCorruptOutlookBlob("storage type")); } outlookBlobReader.ReadInt(); outlookBlobReader.ReadString(); outlookBlobReader.ReadSkipBlock(); deepTraversal = outlookBlobReader.ReadBool(); outlookBlobReader.ReadString(); ids = outlookBlobReader.ReadEntryIdList(); outlookBlobReader.ReadSkipBlock(); result = outlookBlobReader.ReadRestriction(); } } } catch (EndOfStreamException innerException) { throw new CorruptDataException(ServerStrings.ExSearchFolderCorruptOutlookBlob("EndOfStreamException"), innerException); } catch (OutOfMemoryException innerException2) { throw new CorruptDataException(ServerStrings.ExSearchFolderCorruptOutlookBlob("OutOfMemoryException"), innerException2); } return(result); }
public bool TryDecodeValue(Charset defaultCharset, bool enableFallback, bool allowControlCharacters, bool enable2047, bool enableJisDetection, bool enableUtf8Detection, bool enableDbcsDetection, out string charsetName, out string cultureName, out EncodingScheme encodingScheme, out string value) { charsetName = null; cultureName = null; encodingScheme = EncodingScheme.None; value = null; StringBuilder stringBuilder = ScratchPad.GetStringBuilder(Math.Min(1024, this.iterator.TotalLength)); char[] array = null; byte[] array2 = null; ValuePosition currentPosition = this.iterator.CurrentPosition; bool flag = false; bool flag2 = false; if (defaultCharset != null && (enableJisDetection || enableUtf8Detection || (enableDbcsDetection && FeInboundCharsetDetector.IsSupportedFarEastCharset(defaultCharset)))) { defaultCharset = this.DetectValueCharset(defaultCharset, enableJisDetection, enableUtf8Detection, enableDbcsDetection, out encodingScheme); flag2 = true; } Decoder decoder = null; string text = null; if (!enable2047) { this.iterator.SkipToEof(); } else { string lastEncodedWordLanguage = null; Charset charset = null; Decoder decoder2 = null; bool flag3 = true; string text2; for (;;) { this.ParseRawFragment(ref flag); if (this.iterator.Eof) { goto IL_217; } ValuePosition currentPosition2 = this.iterator.CurrentPosition; string text3; byte bOrQ; ValuePosition encodedWordContentStart; ValuePosition encodedWordContentEnd; if (!this.ParseEncodedWord(text, lastEncodedWordLanguage, ref array2, out text2, out text3, out bOrQ, out encodedWordContentStart, out encodedWordContentEnd)) { flag = false; } else { if (text == null) { encodingScheme = EncodingScheme.Rfc2047; charsetName = text2; cultureName = text3; } text = text2; if (currentPosition != currentPosition2 && !flag) { if (!flag3) { this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder); flag3 = true; } if (decoder == null) { if (defaultCharset == null || !defaultCharset.IsAvailable) { if (!enableFallback) { break; } } else { decoder = defaultCharset.GetEncoding().GetDecoder(); } } if (decoder != null) { this.ConvertRawFragment(currentPosition, currentPosition2, decoder, allowControlCharacters, ref array, stringBuilder); } else { this.ZeroExpandFragment(currentPosition, currentPosition2, allowControlCharacters, stringBuilder); } } Charset charset2; if (!Charset.TryGetCharset(text2, out charset2)) { if (!flag3) { this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder); flag3 = true; } if (!enableFallback) { goto Block_19; } decoder2 = null; } else if (charset2 != charset) { if (!flag3) { this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder); flag3 = true; } if (!charset2.IsAvailable) { if (!enableFallback) { goto Block_23; } decoder2 = null; } else { decoder2 = charset2.GetEncoding().GetDecoder(); charset = charset2; } } if (decoder2 != null) { this.DecodeEncodedWord(bOrQ, decoder2, encodedWordContentStart, encodedWordContentEnd, allowControlCharacters, ref array2, ref array, stringBuilder); flag3 = false; } else { this.ZeroExpandFragment(currentPosition2, this.iterator.CurrentPosition, allowControlCharacters, stringBuilder); } currentPosition = this.iterator.CurrentPosition; flag = true; } } charsetName = ((defaultCharset == null) ? null : defaultCharset.Name); return(false); Block_19: charsetName = text2; return(false); Block_23: charsetName = text2; return(false); IL_217: if (!flag3) { this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder); } } if (currentPosition != this.iterator.CurrentPosition) { if (text == null) { if (flag2 && encodingScheme == EncodingScheme.None && defaultCharset != null && !defaultCharset.IsSevenBit && defaultCharset.AsciiSupport == CodePageAsciiSupport.Complete) { charsetName = Charset.ASCII.Name; } else { charsetName = ((defaultCharset == null) ? null : defaultCharset.Name); } } if (decoder == null) { if (defaultCharset == null || !defaultCharset.IsAvailable) { if (!enableFallback) { charsetName = ((defaultCharset == null) ? null : defaultCharset.Name); return(false); } decoder = null; } else { decoder = defaultCharset.GetEncoding().GetDecoder(); } } if (decoder != null) { this.ConvertRawFragment(currentPosition, this.iterator.CurrentPosition, decoder, allowControlCharacters, ref array, stringBuilder); } else { this.ZeroExpandFragment(currentPosition, this.iterator.CurrentPosition, allowControlCharacters, stringBuilder); } } ScratchPad.ReleaseStringBuilder(); value = stringBuilder.ToString(); return(true); }
private void Process(HtmlTokenId tokenId) { var token = parser.Token; switch (tokenId) { case HtmlTokenId.Tag: if (token.IsTagBegin) { switch (token.TagIndex) { case HtmlTagIndex.Title: break; case HtmlTagIndex.Comment: case HtmlTagIndex.Script: case HtmlTagIndex.Style: insideComment = !token.IsEndTag; break; case HtmlTagIndex.A: if (outputAnchorLinks) { insideAnchor = !token.IsEndTag; if (!token.IsEndTag) { } else { } } break; case HtmlTagIndex.Base: case HtmlTagIndex.BaseFont: case HtmlTagIndex.BGSound: case HtmlTagIndex.Link: case HtmlTagIndex.FrameSet: case HtmlTagIndex.Frame: case HtmlTagIndex.Iframe: break; case HtmlTagIndex.Map: case HtmlTagIndex.Div: case HtmlTagIndex.P: case HtmlTagIndex.H1: case HtmlTagIndex.H2: case HtmlTagIndex.H3: case HtmlTagIndex.H4: case HtmlTagIndex.H5: case HtmlTagIndex.H6: case HtmlTagIndex.Center: case HtmlTagIndex.BlockQuote: case HtmlTagIndex.Address: case HtmlTagIndex.Marquee: case HtmlTagIndex.BR: case HtmlTagIndex.HR: case HtmlTagIndex.Form: case HtmlTagIndex.FieldSet: case HtmlTagIndex.OptGroup: case HtmlTagIndex.Select: case HtmlTagIndex.Option: case HtmlTagIndex.OL: case HtmlTagIndex.UL: case HtmlTagIndex.Dir: case HtmlTagIndex.Menu: case HtmlTagIndex.LI: case HtmlTagIndex.DL: case HtmlTagIndex.DT: case HtmlTagIndex.DD: case HtmlTagIndex.Table: case HtmlTagIndex.Caption: case HtmlTagIndex.ColGroup: case HtmlTagIndex.Col: case HtmlTagIndex.Tbody: case HtmlTagIndex.Thead: case HtmlTagIndex.Tfoot: case HtmlTagIndex.TR: case HtmlTagIndex.TC: case HtmlTagIndex.Pre: case HtmlTagIndex.PlainText: case HtmlTagIndex.Listing: collapseWhitespaceState = CollapseWhitespaceState.NewLine; break; case HtmlTagIndex.TH: case HtmlTagIndex.TD: if (!token.IsEndTag) { output.Write("\t"); } break; case HtmlTagIndex.NoEmbed: case HtmlTagIndex.NoFrames: insideComment = !token.IsEndTag; break; } } switch (token.TagIndex) { case HtmlTagIndex.A: if (!token.IsEndTag && outputAnchorLinks) { } break; case HtmlTagIndex.Area: if (!token.IsEndTag && outputAnchorLinks) { } break; case HtmlTagIndex.Img: case HtmlTagIndex.Image: if (!token.IsEndTag && outputAnchorLinks) { } break; } break; case HtmlTokenId.Text: if (!insideComment) { token.Text.WriteToAndCollapseWhitespace(output, ref collapseWhitespaceState); } break; case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; case HtmlTokenId.Restart: break; case HtmlTokenId.EncodingChange: var encodingOutput = output as ConverterEncodingOutput; if (encodingOutput != null) { var codePage = token.Argument; if (encodingOutput.CodePageSameAsInput) { #if DEBUG Encoding newOutputEncoding; InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding)); #endif encodingOutput.Encoding = Charset.GetEncoding(codePage); } } break; case HtmlTokenId.EndOfFile: output.Write("\r\n"); output.Flush(); endOfFile = true; break; } }
protected void Process(TextTokenId tokenId) { if (!started) { if (!convertFragment) { output.OpenDocument(); if (injection != null && injection.HaveHead) { injection.Inject(true, output); } } output.SetQuotingLevel(0); started = true; } switch (tokenId) { case TextTokenId.Text: OutputFragmentSimple(parser.Token); break; case TextTokenId.EncodingChange: if (!convertFragment) { if (output.OutputCodePageSameAsInput) { var codePage = parser.Token.Argument; #if DEBUG Encoding newOutputEncoding; // we should have already checked this in parser before reporting change InternalDebug.Assert(Charset.TryGetEncoding(codePage, out newOutputEncoding)); #endif output.OutputEncoding = Charset.GetEncoding(codePage); } } break; case TextTokenId.EndOfFile: if (!convertFragment) { if (injection != null && injection.HaveTail) { if (!output.LineEmpty) { output.OutputNewLine(); } injection.Inject(false, output); } output.Flush(); } else { output.CloseParagraph(); } endOfFile = true; break; } }
private void Process(HtmlTokenId tokenId) { token = parser.Token; switch (tokenId) { case HtmlTokenId.EndOfFile: if (lineStarted) { output.OutputNewLine(); lineStarted = false; } if (!convertFragment) { if (injection != null && injection.HaveHead) { if (wideGap) { output.OutputNewLine(); wideGap = false; } injection.Inject(false, output); } output.CloseDocument(); output.Flush(); } endOfFile = true; break; case HtmlTokenId.Text: if (!insideComment) { if (insideAnchor && urlCompareSink.IsActive) { token.Text.WriteTo(urlCompareSink); } if (insidePre) { ProcessPreformatedText(); return; } if (normalizedInput) { ProcessText(); return; } NormalizeProcessText(); return; } break; case HtmlTokenId.EncodingChange: if (output.OutputCodePageSameAsInput) { int argument = token.Argument; output.OutputEncoding = Charset.GetEncoding(argument); return; } break; case HtmlTokenId.Tag: { if (token.TagIndex <= HtmlTagIndex.Unknown) { return; } HtmlDtd.TagDefinition tagDefinition = GetTagDefinition(token.TagIndex); if (normalizedInput) { if (!token.IsEndTag) { if (token.IsTagBegin) { PushElement(tagDefinition); } ProcessStartTagAttributes(tagDefinition); return; } if (token.IsTagBegin) { PopElement(tagDefinition); return; } } else { if (!token.IsEndTag) { if (token.IsTagBegin) { LFillTagB(tagDefinition); PushElement(tagDefinition); RFillTagB(tagDefinition); } ProcessStartTagAttributes(tagDefinition); return; } if (token.IsTagBegin) { LFillTagE(tagDefinition); PopElement(tagDefinition); RFillTagE(tagDefinition); return; } } break; } case HtmlTokenId.Restart: case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; default: return; } }
// Token: 0x0600024D RID: 589 RVA: 0x0000AE62 File Offset: 0x00009062 internal static void ThrowDecodingFailedException(ref DecodingResults decodingResults) { Charset.GetEncoding(decodingResults.CharsetName); throw new ExchangeDataException("internal value decoding error"); }
private bool TryGetHtmlCharsetFromMetaTag(uint maxBytesToSearch, out Charset htmlBodyCharset) { htmlBodyCharset = null; using (MemoryStream memoryStream = this.LoadHtmlBodyInMemory()) { memoryStream.Position = 0L; Charset itemMimeCharset = ConvertUtils.GetItemMimeCharset(this.coreItem.PropertyBag); using (HtmlReader htmlReader = new HtmlReader(memoryStream, itemMimeCharset.GetEncoding())) { while (htmlReader.ReadNextToken()) { if ((long)htmlReader.CurrentOffset > (long)((ulong)maxBytesToSearch)) { return(false); } if (htmlReader.TokenKind == HtmlTokenKind.EmptyElementTag && htmlReader.TagId == HtmlTagId.Meta) { bool flag = false; bool flag2 = false; string text = string.Empty; HtmlAttributeReader attributeReader = htmlReader.AttributeReader; while (!flag && attributeReader.ReadNext()) { if (attributeReader.Id == HtmlAttributeId.Charset && attributeReader.HasValue) { text = attributeReader.ReadValue(); flag = true; } else if (attributeReader.Id == HtmlAttributeId.Content && attributeReader.HasValue) { text = attributeReader.ReadValue(); if (flag2) { flag = true; } } else if (attributeReader.Id == HtmlAttributeId.HttpEquiv && attributeReader.HasValue) { string a = attributeReader.ReadValue(); if (string.Equals(a, "content-type", StringComparison.OrdinalIgnoreCase) || string.Equals(a, "charset", StringComparison.OrdinalIgnoreCase)) { flag2 = true; if (!string.IsNullOrEmpty(text)) { flag = true; } } } } if (flag) { text = HtmlReader.CharsetFromString(text, flag2); if (!string.IsNullOrEmpty(text) && Charset.TryGetCharset(text, out htmlBodyCharset)) { return(true); } return(false); } } } } } return(false); }