// Token: 0x06000128 RID: 296 RVA: 0x00004FB0 File Offset: 0x000031B0
        internal static Stream GetFilteredStream(ConfigurationContextBase configurationContext, Stream inputStream, Charset charset, BlockStatus blockStatus)
        {
            HtmlToHtml htmlToHtml = new HtmlToHtml();

            TextConvertersInternalHelpers.SetPreserveDisplayNoneStyle(htmlToHtml, true);
            WebBeaconFilterLevels filterWebBeaconsAndHtmlForms = configurationContext.FilterWebBeaconsAndHtmlForms;
            bool     flag     = filterWebBeaconsAndHtmlForms == WebBeaconFilterLevels.DisableFilter || blockStatus == BlockStatus.NoNeverAgain;
            Encoding encoding = null;

            if (charset != null && charset.TryGetEncoding(out encoding))
            {
                htmlToHtml.DetectEncodingFromMetaTag = false;
                htmlToHtml.InputEncoding             = encoding;
                htmlToHtml.OutputEncoding            = encoding;
            }
            else
            {
                htmlToHtml.DetectEncodingFromMetaTag = true;
                htmlToHtml.InputEncoding             = Encoding.ASCII;
                htmlToHtml.OutputEncoding            = null;
            }
            htmlToHtml.FilterHtml = true;
            if (!flag)
            {
                htmlToHtml.HtmlTagCallback = new HtmlTagCallback(AttachmentUtilities.webBeaconFilter.ProcessTag);
            }
            return(new ConverterStream(inputStream, htmlToHtml, ConverterStreamAccess.Read));
        }
Example #2
0
        // Token: 0x06000333 RID: 819 RVA: 0x0000CAF8 File Offset: 0x0000ACF8
        public Stream WriteArchive(ConfigurationContextBase configurationContext, IAttachmentWebOperationContext webOperationContext, OutboundConversionOptions outboundConversionOptions, AttachmentCollection attachmentCollection)
        {
            Stream stream = new MemoryStream();

            ZipFileAttachments.SetResponseHeadersForZipAttachments(webOperationContext, this.zipFileName);
            List <string> list = new List <string>();

            if (this.hasEmbeddedItem)
            {
                foreach (KeyValuePair <string, ZipEntryAttachment> keyValuePair in this.files)
                {
                    list.Add(keyValuePair.Key);
                }
            }
            foreach (ZipEntryAttachment zipEntryAttachment in this.files.Values)
            {
                this.bytesWritten += zipEntryAttachment.WriteToStream(configurationContext, stream, outboundConversionOptions, this.blockStatus, this.bytesWritten, list, attachmentCollection);
            }
            long startOfDirectory = this.bytesWritten;

            foreach (ZipEntryAttachment zipEntryAttachment2 in this.files.Values)
            {
                this.bytesWritten += (long)((ulong)zipEntryAttachment2.WriteCentralDirectoryStructure(stream));
            }
            long endOfDirectory = this.bytesWritten;

            this.WriteTrailer(stream, startOfDirectory, endOfDirectory);
            return(stream);
        }
 // Token: 0x0600012B RID: 299 RVA: 0x000050B5 File Offset: 0x000032B5
 internal static bool GetDoNotSniff(AttachmentPolicyLevel level, ConfigurationContextBase configurationContext)
 {
     if (configurationContext == null)
     {
         throw new ArgumentNullException("configurationContext");
     }
     return(AttachmentPolicyLevel.ForceSave == level && !configurationContext.IsFeatureEnabled(Feature.ForceSaveAttachmentFiltering));
 }
        private Stream GetFilteredResponseStream(ConfigurationContextBase configurationContext, Stream inputStream, Charset charset, BlockStatus blockStatus)
        {
            BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize);

            byte[] array  = bufferPool.Acquire();
            Stream stream = new MemoryStream();

            try
            {
                using (Stream filteredStream = AttachmentUtilities.GetFilteredStream(configurationContext, inputStream, charset, blockStatus))
                {
                    try
                    {
                        int count;
                        while ((count = filteredStream.Read(array, 0, array.Length)) > 0)
                        {
                            stream.Write(array, 0, count);
                        }
                    }
                    finally
                    {
                        if (array != null)
                        {
                            bufferPool.Release(array);
                        }
                    }
                }
                stream.Seek(0L, SeekOrigin.Begin);
            }
            catch (Exception ex)
            {
                ExTraceGlobals.AttachmentHandlingTracer.TraceError <string>((long)this.GetHashCode(), "ZipEntryAttachment.GetfilteredStream: Safe HTML converter failed with exception {0}", ex.Message);
                stream = new MemoryStream();
            }
            return(stream);
        }
        internal long WriteToStream(ConfigurationContextBase configurationContext, Stream outputStream, OutboundConversionOptions outboundConversionOptions, BlockStatus blockStatus, long outputStreamPosition, IList <string> fileNames, AttachmentCollection attachmentCollection)
        {
            this.headerOffset = outputStreamPosition;
            Stream stream = null;
            uint   num    = 0U;

            using (Attachment attachment = attachmentCollection.Open(this.attachmentId))
            {
                try
                {
                    if (attachment.AttachmentType == AttachmentType.EmbeddedMessage)
                    {
                        this.fileNames = fileNames;
                        stream         = this.GetItemAttachmentStream(attachment, outboundConversionOptions);
                    }
                    else
                    {
                        this.fileNames = null;
                        stream         = ZipEntryAttachment.GetStreamAttachmentStream(attachment);
                    }
                    if (stream.Length > 0L)
                    {
                        Stream stream2;
                        if (this.doNeedToFilterHtml)
                        {
                            if (this.CompressionMethod != 0)
                            {
                                stream2 = AttachmentUtilities.GetFilteredStream(configurationContext, stream, attachment.TextCharset, blockStatus);
                            }
                            else
                            {
                                stream2 = this.GetFilteredResponseStream(configurationContext, stream, attachment.TextCharset, blockStatus);
                            }
                        }
                        else
                        {
                            stream2 = this.GetUnfilteredStream(stream);
                        }
                        if (stream2 != stream)
                        {
                            stream.Close();
                            stream = stream2;
                        }
                    }
                    if (this.CompressionMethod == 0)
                    {
                        if (!stream.CanSeek)
                        {
                            throw new ArgumentException("stream", "Stream is required to support Seek operations, and does not");
                        }
                        this.attachmentSize = stream.Length;
                    }
                    this.WriteZipFileHeader(stream, outputStream);
                    this.WriteFileData(stream, outputStream, blockStatus);
                    if (this.CompressionMethod != 0)
                    {
                        num = this.WriteZipFileDescriptor(outputStream);
                    }
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                        stream = null;
                    }
                }
            }
            return((long)((ulong)(this.headerBytesWritten + this.attachmentBytesWritten + num)));
        }
 // Token: 0x06000104 RID: 260 RVA: 0x00004177 File Offset: 0x00002377
 public AttachmentHandler(string id, IAttachmentWebOperationContext webOperationContext, CallContext callContext, ConfigurationContextBase configurationContext)
 {
     this.id                   = id;
     this.callContext          = callContext;
     this.webOperationContext  = webOperationContext;
     this.configurationContext = configurationContext;
 }
        // Token: 0x0600012A RID: 298 RVA: 0x00005080 File Offset: 0x00003280
        internal static bool NeedToFilterHtml(string contentType, string fileExtension, AttachmentPolicyLevel level, ConfigurationContextBase configurationContext)
        {
            bool flag  = AttachmentUtilities.IsHtmlAttachment(contentType, fileExtension);
            bool flag2 = AttachmentPolicyLevel.ForceSave == level;
            bool flag3 = configurationContext.IsFeatureEnabled(Feature.ForceSaveAttachmentFiltering);

            return(flag && (!flag2 || flag3));
        }
Example #8
0
        // Token: 0x06000332 RID: 818 RVA: 0x0000CA34 File Offset: 0x0000AC34
        public void AddAttachmentToZip(Attachment attachment, AttachmentPolicyLevel policyLevel, ConfigurationContextBase configurationContextBase)
        {
            if (attachment == null)
            {
                throw new ArgumentNullException("attachment");
            }
            if (configurationContextBase == null)
            {
                throw new ArgumentNullException("configurationContextBase");
            }
            if (attachment.AttachmentType == AttachmentType.EmbeddedMessage)
            {
                this.hasEmbeddedItem = true;
            }
            string contentType        = AttachmentUtilities.GetContentType(attachment);
            string fileExtension      = attachment.FileExtension;
            bool   doNeedToFilterHtml = AttachmentUtilities.NeedToFilterHtml(contentType, fileExtension, policyLevel, configurationContextBase);
            bool   isNotHtmlandNotXml = !AttachmentUtilities.GetIsHtmlOrXml(contentType, fileExtension);
            bool   doNotSniff         = AttachmentUtilities.GetDoNotSniff(policyLevel, configurationContextBase);
            string text = string.IsNullOrEmpty(attachment.FileName) ? attachment.DisplayName : attachment.FileName;

            if (attachment.AttachmentType == AttachmentType.EmbeddedMessage)
            {
                text += fileExtension;
            }
            string text2 = this.ConditionZipEntryFileName(text);

            attachment.FileName = text2;
            ZipEntryAttachment value = new ZipEntryAttachment(text2, attachment, doNeedToFilterHtml, doNotSniff, isNotHtmlandNotXml);

            this.files.Add(text2, value);
        }