// Token: 0x06000127 RID: 295 RVA: 0x00004F24 File Offset: 0x00003124 internal static string ToHexString(string fileName, bool chrome) { StringBuilder stringBuilder = new StringBuilder(fileName.Length); byte[] bytes = Encoding.UTF8.GetBytes(fileName); for (int i = 0; i < bytes.Length; i++) { if (bytes[i] >= 0 && bytes[i] <= 127) { if (AttachmentUtilities.IsMIMEAttributeSpecialChar((char)bytes[i], chrome)) { stringBuilder.AppendFormat("%{0}", Convert.ToString(bytes[i], 16)); } else { stringBuilder.Append((char)bytes[i]); } } else { stringBuilder.AppendFormat("%{0}", Convert.ToString(bytes[i], 16)); } } return(stringBuilder.ToString()); }
// 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); }
// Token: 0x06000335 RID: 821 RVA: 0x0000CCC4 File Offset: 0x0000AEC4 private static void SetZipContentDispositionResponseHeader(IAttachmentWebOperationContext webOperationContext, string fileName) { bool chrome = webOperationContext.UserAgent.IsBrowserChrome(); string str = AttachmentUtilities.ToHexString(fileName, chrome); webOperationContext.Headers["Content-Disposition"] = "filename=" + str; }
// 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)); }
// Token: 0x0600012C RID: 300 RVA: 0x000050DD File Offset: 0x000032DD internal static bool GetIsHtmlOrXml(string contentType, string fileExtension) { if (contentType == null) { throw new ArgumentNullException("contentType"); } return(AttachmentUtilities.IsXmlAttachment(contentType, fileExtension) || AttachmentUtilities.IsHtmlAttachment(contentType, fileExtension)); }
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); }
// Token: 0x0600010B RID: 267 RVA: 0x000046F0 File Offset: 0x000028F0 private void WriteContentDispositionResponseHeader(string fileName, bool isInline) { bool chrome = this.webOperationContext.UserAgent.IsBrowserChrome(); string text = AttachmentUtilities.ToHexString(fileName, chrome); string value = string.Empty; if (this.webOperationContext.UserAgent.IsBrowserFirefox()) { value = string.Format(CultureInfo.InvariantCulture, (this.webOperationContext.UserAgent.BrowserVersion.Build >= 8) ? "{0}; filename*=UTF-8''{1}" : "{0}; filename*=\"{1}\"", new object[] { isInline ? "inline" : "attachment", text }); } else { value = string.Format(CultureInfo.InvariantCulture, "{0}; filename=\"{1}\"", new object[] { isInline ? "inline" : "attachment", text }); } this.webOperationContext.Headers["Content-Disposition"] = value; }
// Token: 0x0600016D RID: 365 RVA: 0x00005C08 File Offset: 0x00003E08 public bool CancelAttachment(string cancellationId, int timeout) { CancelAttachmentManager.CancellationItem cancellationItem; lock (this.lockObject) { if (!this.CancellationItems.ContainsKey(cancellationId)) { OwaServerTraceLogger.AppendToLog(new TraceLogEvent("CancelAttachmentManager.CancelAttachment", this.userContext, "CancelAttachment", string.Format("CreateAttachment has not started, marking item as cancelled for CancellationId: {0}", cancellationId))); cancellationItem = new CancelAttachmentManager.CancellationItem(); cancellationItem.CancellationId = cancellationId; cancellationItem.IsCancellationRequested = true; this.cancellationItems.Add(cancellationId, cancellationItem); return(true); } cancellationItem = this.CancellationItems[cancellationId]; cancellationItem.IsCancellationRequested = true; if (cancellationItem.CancellationTokenSource != null) { cancellationItem.CancellationTokenSource.Cancel(); } } if (cancellationItem.AttachmentId == null && cancellationItem.AttachmentCompletedEvent != null && !cancellationItem.AttachmentCompletedEvent.WaitOne(timeout)) { OwaServerTraceLogger.AppendToLog(new TraceLogEvent("CancelAttachmentManager.CancelAttachment", this.userContext, "CancelAttachment", string.Format("Cancel attachment timed out for CancellationId: {0}", cancellationId))); return(false); } if (cancellationItem.AttachmentId == null) { OwaServerTraceLogger.AppendToLog(new TraceLogEvent("CancelAttachmentManager.CancelAttachment", this.userContext, "CancelAttachment", string.Format("AttachmentId not found. Returning success for cancellationId: {0}", cancellationId))); return(true); } bool flag2 = AttachmentUtilities.DeleteAttachment(cancellationItem.AttachmentId); OwaServerTraceLogger.AppendToLog(new TraceLogEvent("CancelAttachmentManager.CancelAttachment", this.userContext, "CancelAttachment", string.Format("DeleteAttachmentSucceeded = {0} for CancellationId: {1}, AttachmentId: {2}", flag2, cancellationId, cancellationItem.AttachmentId.Id))); return(flag2); }
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 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: 0x06000107 RID: 263 RVA: 0x000041B0 File Offset: 0x000023B0 public Stream GetAttachmentStream(AttachmentHandler.IAttachmentRetriever attachmentRetriever, AttachmentHandler.IAttachmentPolicyChecker policyChecker, bool asDataUri) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "AttachmentHandler.GetAttachmentStream: Getting attachment stream for id={0}", this.id); if (string.IsNullOrEmpty(this.id)) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug((long)this.GetHashCode(), "Attachment id is empty or null. returning null stream."); throw new FaultException("Id cannot be null or empty."); } Stream stream = null; ByteEncoder byteEncoder = null; Stream stream2 = null; Stream result; try { Attachment attachment = attachmentRetriever.Attachment; AttachmentPolicyLevel policy = policyChecker.GetPolicy(attachment, this.webOperationContext.IsPublicLogon); if (AudioFile.IsProtectedVoiceAttachment(attachment.FileName)) { attachment.ContentType = Utils.GetUnProtectedVoiceAttachmentContentType(attachment.FileName); stream = DRMUtils.OpenProtectedAttachment(attachment, this.callContext.AccessingADUser.OrganizationId); string fileName; if (AudioFile.TryGetNonDRMFileNameFromDRM(attachment.FileName, out fileName)) { attachment.FileName = fileName; } } string text = AttachmentUtilities.GetContentType(attachment); string fileExtension = attachment.FileExtension; OleAttachment oleAttachment = attachment as OleAttachment; if (oleAttachment != null) { stream = oleAttachment.ConvertToImage(ImageFormat.Jpeg); if (stream != null) { text = "image/jpeg"; } } if (this.IsBlocked(policy) && !attachment.IsInline && !this.IsImagePreview) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "Attachment is blocked. Returning null stream. id is {0}", this.id); result = null; } else { this.WriteResponseHeaders(text, policy, attachment); if (stream == null) { StreamAttachment streamAttachment = attachment as StreamAttachment; if (streamAttachment != null) { if (string.Equals(text, "audio/mpeg", StringComparison.OrdinalIgnoreCase)) { stream = streamAttachment.GetContentStream(PropertyOpenMode.Modify); } else { stream = streamAttachment.GetContentStream(PropertyOpenMode.ReadOnly); } } else { ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties)) { IRecipientSession adrecipientSession = item.Session.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid); OutboundConversionOptions outboundConversionOptions = new OutboundConversionOptions(this.callContext.DefaultDomain.DomainName.Domain); outboundConversionOptions.ClearCategories = false; outboundConversionOptions.UserADSession = adrecipientSession; outboundConversionOptions.LoadPerOrganizationCharsetDetectionOptions(adrecipientSession.SessionSettings.CurrentOrganizationId); stream = new MemoryStream(); ItemConversion.ConvertItemToMime(item, stream, outboundConversionOptions); stream.Seek(0L, SeekOrigin.Begin); } } } } long num = 0L; long num2 = 0L; if (AttachmentUtilities.NeedToFilterHtml(text, fileExtension, policy, this.configurationContext)) { stream = AttachmentUtilities.GetFilteredStream(this.configurationContext, stream, attachment.TextCharset, attachmentRetriever.BlockStatus); } else if (this.NeedToSendPartialContent(stream, out num, out num2)) { string value = string.Format(CultureInfo.InvariantCulture, "bytes {0}-{1}/{2}", new object[] { num, num2, stream.Length }); this.webOperationContext.Headers["Accept-Ranges"] = "bytes"; this.webOperationContext.Headers["Content-Range"] = value; this.webOperationContext.ETag = this.id; this.webOperationContext.StatusCode = HttpStatusCode.PartialContent; long num3 = num2 - num + 1L; if (num3 < stream.Length) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <long, long, long>((long)this.GetHashCode(), "RangeBytes:{0} - Seek:{1} - SetLength:{2}", num3, num, num2 + 1L); stream.Seek(num, SeekOrigin.Begin); return(new BoundedStream(stream, true, num, num2)); } } if (asDataUri) { byteEncoder = new Base64Encoder(); stream2 = new EncoderStream(stream, byteEncoder, EncoderStreamAccess.Read); stream = new DataUriStream(stream2, text); } result = stream; } } catch (Exception ex) { if (stream != null) { stream.Dispose(); } if (stream2 != null) { stream2.Dispose(); } if (byteEncoder != null) { byteEncoder.Dispose(); } string formatString = string.Empty; if (ex is ExchangeDataException) { formatString = "Fail to sanitize HTML getting attachment. id is {0}, Exception: {1}"; } else if (ex is StoragePermanentException) { formatString = "StoragePermanentException when getting attachment. id is {0}, Exception: {1}"; } else { if (!(ex is StorageTransientException)) { throw; } formatString = "StorageTransientException when getting attachment. id is {0}, Exception: {1}"; } ExTraceGlobals.AttachmentHandlingTracer.TraceError <string, Exception>((long)this.GetHashCode(), formatString, this.id, ex); throw new CannotOpenFileAttachmentException(ex); } return(result); }