public static void ProcessAttachment(IStoreSession session, string ewsAttachmentId, IExchangePrincipal exchangePrincipal, PropertyOpenMode openMode, WacUtilities.AttachmentProcessor attachmentProcessor) { IdConverterDependencies converterDependencies = new IdConverterDependencies.FromRawData(false, false, null, null, exchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), session as MailboxSession, session as MailboxSession, session as PublicFolderSession); using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(ewsAttachmentId, converterDependencies)) { bool flag = WacUtilities.IsIrmRestricted(attachmentRetriever.RootItem); if (openMode == PropertyOpenMode.Modify) { attachmentRetriever.RootItem.OpenAsReadWrite(); } StreamAttachment streamAttachment = attachmentRetriever.Attachment as StreamAttachment; if (streamAttachment == null) { attachmentProcessor(exchangePrincipal, attachmentRetriever.Attachment, null, flag); } else { using (Stream contentStream = streamAttachment.GetContentStream(openMode)) { bool flag2 = WacUtilities.IsContentProtected(attachmentRetriever.Attachment.FileName, contentStream); attachmentProcessor(exchangePrincipal, streamAttachment, contentStream, flag || flag2); if (openMode == PropertyOpenMode.Modify) { attachmentRetriever.RootItem.Save(SaveMode.NoConflictResolution); } } } } }
protected override Stream InternalExecute() { UserContext userContext = UserContextManager.GetUserContext(HttpContext.Current, CallContext.Current.EffectiveCaller, true); ConfigurationContext configurationContext = new ConfigurationContext(userContext); AttachmentHandler attachmentHandler = new AttachmentHandler(this.id, this.webOperationContext, base.CallContext, configurationContext); Stream result; try { using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(this.id, base.CallContext)) { Stream attachmentStream = attachmentHandler.GetAllAttachmentsAsZipStream(attachmentRetriever); base.CallContext.OnDisposed += delegate(object sender, EventArgs args) { if (attachmentStream != null) { attachmentStream.Dispose(); } }; result = attachmentStream; } } catch (CannotOpenFileAttachmentException) { this.webOperationContext.StatusCode = HttpStatusCode.NotFound; result = null; } catch (ObjectNotFoundException) { this.webOperationContext.StatusCode = HttpStatusCode.NotFound; result = null; } return(result); }
private static bool MessageIsDraft(WacRequest wacRequest) { ADSessionSettings adsessionSettings; ExchangePrincipal exchangePrincipal = WacUtilities.GetExchangePrincipal(wacRequest, out adsessionSettings, wacRequest.WacFileRep.IsArchive); CultureInfo cultureInfo = CultureInfo.GetCultureInfo(wacRequest.CultureName); if (exchangePrincipal.RecipientTypeDetails == RecipientTypeDetails.PublicFolder) { return(false); } bool result; using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(exchangePrincipal, cultureInfo, "Client=OWA;Action=WAC")) { IdConverterDependencies converterDependencies = new IdConverterDependencies.FromRawData(false, false, null, null, wacRequest.MailboxSmtpAddress.ToString(), null, mailboxSession, null); using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(wacRequest.EwsAttachmentId, converterDependencies)) { Item rootItem = attachmentRetriever.RootItem; Attachment attachment = attachmentRetriever.Attachment; string text; string text2; result = WacUtilities.ItemIsMessageDraft(rootItem, attachment, out text, out text2); } } return(result); }
private static void EliminateGzFileDoubleCompression(AttachmentHandler.IAttachmentRetriever attachmentRetriever) { if (attachmentRetriever != null && attachmentRetriever.Attachment != null && attachmentRetriever.Attachment.FileExtension != null && attachmentRetriever.Attachment.FileExtension.ToLower().Equals(".gz") && attachmentRetriever.Attachment.ContentType != null && attachmentRetriever.Attachment.ContentType.ToLower().Contains("application/x-gzip")) { string text = HttpContext.Current.Request.Headers["Accept-Encoding"]; if (!string.IsNullOrEmpty(text)) { HttpContext.Current.Request.Headers["Accept-Encoding"] = text.Replace("gzip", ""); } } }
// Token: 0x06001ACE RID: 6862 RVA: 0x000655DC File Offset: 0x000637DC protected override WacAttachmentType InternalExecute() { if (string.IsNullOrEmpty(this.attachmentId)) { throw new OwaInvalidRequestException("You must provide an attachmentId when calling GetWacAttachmentInfo."); } WacAttachmentType result; using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(this.attachmentId, base.CallContext)) { result = GetWacAttachmentInfo.Execute(base.CallContext, attachmentRetriever.RootItem.Session, attachmentRetriever.RootItem, attachmentRetriever.Attachment, this.draftId, this.attachmentId, this.isEdit); } return(result); }
// Token: 0x06001B14 RID: 6932 RVA: 0x00066B94 File Offset: 0x00064D94 protected override string InternalExecute() { string wacUrl; using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(this.attachmentId, base.CallContext)) { StoreSession session = attachmentRetriever.RootItem.Session; Item rootItem = attachmentRetriever.RootItem; Attachment attachment = attachmentRetriever.Attachment; WacAttachmentType wacAttachmentType = GetWacAttachmentInfo.Execute(base.CallContext, session, rootItem, attachment, null, this.attachmentId, false); if (wacAttachmentType == null) { throw new OwaInvalidOperationException("There is no reason known for code to reach here without throwing an unhandled exception elsewhere"); } wacUrl = wacAttachmentType.WacUrl; } return(wacUrl); }
// 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); }
// Token: 0x0600010E RID: 270 RVA: 0x00004984 File Offset: 0x00002B84 public Stream GetAllAttachmentsAsZipStream(AttachmentHandler.IAttachmentRetriever attachmentRetriever) { 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(), "Item id is empty or null. returning null stream."); throw new FaultException("Id cannot be null or empty."); } Item rootItem = attachmentRetriever.RootItem; if (rootItem is ReportMessage || ObjectClass.IsSmsMessage(rootItem.ClassName)) { return(null); } Stream stream = null; Stream result; try { AttachmentHandler.IAttachmentPolicyChecker attachmentPolicyChecker = AttachmentPolicyChecker.CreateInstance(this.configurationContext.AttachmentPolicy); AttachmentCollection attachmentCollection = IrmUtils.GetAttachmentCollection(rootItem); BlockStatus itemBlockStatus = AttachmentHandler.GetItemBlockStatus(rootItem); string subject = AttachmentHandler.GetSubject(rootItem); ZipFileAttachments zipFileAttachments = new ZipFileAttachments(itemBlockStatus, subject); foreach (AttachmentHandle handle in attachmentCollection) { using (Attachment attachment = attachmentCollection.Open(handle)) { if (attachment is OleAttachment || attachment.IsInline || attachment is ReferenceAttachment) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "Attachment is inline, an ole image, or a reference attachment. Do not add to zip file. id is {0}", attachment.Id.ToString()); } else { AttachmentPolicyLevel policy = attachmentPolicyChecker.GetPolicy(attachment, this.webOperationContext.IsPublicLogon); if (this.IsBlocked(policy)) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "Attachment is blocked. Do not add to zip file. id is {0}", attachment.Id.ToString()); } else { zipFileAttachments.AddAttachmentToZip(attachment, policy, this.configurationContext); } } } } if (zipFileAttachments.Count == 0) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug((long)this.GetHashCode(), "AttachmentHandler.GetAllAttachmentsAsZipStream: No attachments returned for item"); result = null; } else { IRecipientSession adrecipientSession = rootItem.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 = zipFileAttachments.WriteArchive(this.configurationContext, this.webOperationContext, outboundConversionOptions, attachmentCollection); stream.Seek(0L, SeekOrigin.Begin); result = stream; } } catch (Exception ex) { if (stream != null) { stream.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); }
protected override Stream InternalExecute() { UserContext userContext = UserContextManager.GetUserContext(HttpContext.Current, CallContext.Current.EffectiveCaller, true); ConfigurationContext configurationContext = new ConfigurationContext(userContext); string mailboxSmtpAddress = userContext.MailboxIdentity.PrimarySmtpAddress.ToString(); CobaltStoreSaver cobaltStoreSaver; if (WacUtilities.ShouldUpdateAttachment(mailboxSmtpAddress, this.id, out cobaltStoreSaver)) { base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Updated, true); cobaltStoreSaver.SaveAndLogExceptions(base.CallContext.ProtocolLog); } else { base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Updated, false); } AttachmentHandler attachmentHandler = new AttachmentHandler(this.id, this.webOperationContext, base.CallContext, configurationContext); attachmentHandler.IsImagePreview = this.isImagePreview; Stream result; try { using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(this.id, base.CallContext)) { AttachmentHandler.IAttachmentPolicyChecker policyChecker = AttachmentPolicyChecker.CreateInstance(configurationContext.AttachmentPolicy); Stream attachmentStream = attachmentHandler.GetAttachmentStream(attachmentRetriever, policyChecker, this.asDataUri); GetAttachment.EliminateGzFileDoubleCompression(attachmentRetriever); base.CallContext.OnDisposed += delegate(object sender, EventArgs args) { if (attachmentStream != null) { attachmentStream.Dispose(); } }; if (attachmentRetriever.Attachment != null) { base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Extension, attachmentRetriever.Attachment.FileExtension); base.CallContext.ProtocolLog.Set(GetAttachmentMetadata.Length, attachmentRetriever.Attachment.Size); } result = attachmentStream; } } catch (InvalidStoreIdException innerException) { throw new OwaInvalidRequestException("Invalid ID, " + this.GetParametersForLogging(), innerException); } catch (InvalidIdMalformedException innerException2) { throw new OwaInvalidRequestException("Malformed ID, " + this.GetParametersForLogging(), innerException2); } catch (CannotOpenFileAttachmentException) { this.webOperationContext.StatusCode = HttpStatusCode.NotFound; result = null; } catch (ObjectNotFoundException) { this.webOperationContext.StatusCode = HttpStatusCode.NotFound; result = null; } return(result); }