예제 #1
0
        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);
        }
        // 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);
        }
예제 #3
0
        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);
        }