private static uint ComputeCrc32FromStream(Stream stream) { if (!stream.CanSeek) { throw new ArgumentException("Stream is required to support Seek operations, and does not"); } BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize); byte[] array = bufferPool.Acquire(); uint num = 0U; try { int bytesToRead; while ((bytesToRead = stream.Read(array, 0, array.Length)) > 0) { num = ZipEntryAttachment.ComputeCrc32FromBytes(array, bytesToRead, num); } } finally { if (array != null) { bufferPool.Release(array); } } stream.Seek(0L, SeekOrigin.Begin); return(num); }
// 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); }
private static uint[] CompressAndWriteOutputStream(Stream outputStream, Stream inputStream, bool doComputeCrc) { if (outputStream == null) { throw new ArgumentNullException("outputStream"); } if (inputStream == null) { throw new ArgumentNullException("inputStream"); } uint num = 0U; int num2 = 0; BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize); byte[] array = bufferPool.Acquire(); uint num3 = 0U; using (Stream stream = Streams.CreateTemporaryStorageStream()) { try { int num4; using (Stream stream2 = new DeflateStream(stream, CompressionMode.Compress, true)) { while ((num4 = inputStream.Read(array, 0, array.Length)) > 0) { if (doComputeCrc) { num3 = ZipEntryAttachment.ComputeCrc32FromBytes(array, num4, num3); } num2 += num4; stream2.Write(array, 0, num4); } stream2.Flush(); } stream.Seek(0L, SeekOrigin.Begin); while ((num4 = stream.Read(array, 0, array.Length)) > 0) { outputStream.Write(array, 0, num4); num += (uint)num4; } } finally { if (array != null) { bufferPool.Release(array); } } } return(new uint[] { num, num3, (uint)num2 }); }
private void WriteFileData(Stream inputStream, Stream outputStream, BlockStatus blockStatus) { uint[] array = new uint[3]; if (this.CompressionMethod == 8) { array = ZipEntryAttachment.CompressAndWriteOutputStream(outputStream, inputStream, true); this.attachmentBytesWritten = array[0]; this.CheckSum = array[1]; this.attachmentSize = (long)((ulong)array[2]); return; } this.attachmentBytesWritten = ZipEntryAttachment.WriteOutputStream(outputStream, inputStream); }
private static bool CheckShouldRemoveContents(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanSeek) { throw new ArgumentException("Stream is required to support Seek operations, and does not"); } byte[] array = new byte[512]; int bytesToRead = stream.Read(array, 0, 512); bool result = ZipEntryAttachment.CheckShouldRemoveContents(array, bytesToRead); stream.Seek(0L, SeekOrigin.Begin); return(result); }
private Stream GetItemAttachmentStream(Attachment attachment, OutboundConversionOptions outboundConversionOptions) { Stream stream = Streams.CreateTemporaryStorageStream(); string text = null; ItemAttachment itemAttachment = attachment as ItemAttachment; using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties)) { try { if (ItemConversion.IsItemClassConvertibleToMime(item.ClassName)) { ItemConversion.ConvertItemToMime(item, stream, outboundConversionOptions); text = ".eml"; } else if (ObjectClass.IsCalendarItemCalendarItemOccurrenceOrRecurrenceException(item.ClassName)) { (item as CalendarItemBase).ExportAsICAL(stream, "UTF-8", outboundConversionOptions); text = ".ics"; } else if (ObjectClass.IsContact(item.ClassName)) { Contact.ExportVCard(item as Contact, stream, outboundConversionOptions); text = ".vcf"; } else { ItemConversion.ConvertItemToMsgStorage(item, stream, outboundConversionOptions); } } catch (Exception) { stream = ZipEntryAttachment.GetContentsReplacementStream(-1706159495); text = ".txt"; } } if (text != null) { this.fileName = this.GetConvertedItemFileName(this.fileName, text); this.encodedfileNameBytes = ZipEntryAttachment.GetEncodedString(this.fileName); } stream.Position = 0L; return(stream); }
private Stream GetUnfilteredStream(Stream stream) { if (!stream.CanSeek) { throw new ArgumentException("stream", "Stream is required to support Seek operations, and does not"); } if (!this.doNotSniff && this.isNotHtmlandNotXml && ZipEntryAttachment.CheckShouldRemoveContents(stream)) { if (ExTraceGlobals.AttachmentHandlingTracer.IsTraceEnabled(TraceType.DebugTrace)) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string, string>((long)this.GetHashCode(), "ZipEntryAttachment.GetUnfilteredStream: Return contents removed for attachment {0}: mailbox {1}", this.fileName, AttachmentUtilities.TryGetMailboxIdentityName()); } return(ZipEntryAttachment.GetContentsReplacementStream(-1868113279)); } if (ExTraceGlobals.AttachmentHandlingTracer.IsTraceEnabled(TraceType.DebugTrace)) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string, string>((long)this.GetHashCode(), "ZipEntryAttachment.GetUnfilteredStream: Return original contents for attachment {0}: mailbox {1}", this.fileName, AttachmentUtilities.TryGetMailboxIdentityName()); } return(stream); }
internal ZipEntryAttachment(string fileName, Attachment attachment, bool doNeedToFilterHtml, bool doNotSniff, bool isNotHtmlandNotXml) { this.fileName = fileName; this.encodedfileNameBytes = ZipEntryAttachment.GetEncodedString(fileName); this.attachmentId = attachment.Id; this.doNeedToFilterHtml = doNeedToFilterHtml; this.doNotSniff = doNotSniff; this.isNotHtmlandNotXml = isNotHtmlandNotXml; if (this.NeedsCompression(attachment)) { this.CompressionMethod = 8; this.GeneralPurposeBitFlag = 2056; } else { this.CompressionMethod = 0; this.GeneralPurposeBitFlag = 2048; } this.CurrentDateTime = this.CurrentDosDateTime(); }
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))); }
private void ComputeCrc32(Stream stream) { uint num = ZipEntryAttachment.ComputeCrc32FromStream(stream); this.CheckSum = num; }
private static Stream GetContentsReplacementStream(Strings.IDs resource) { byte[] encodedString = ZipEntryAttachment.GetEncodedString(Strings.GetLocalizedString(resource)); return(new MemoryStream(encodedString, 0, encodedString.Length)); }