예제 #1
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);
        }
예제 #2
0
        // Token: 0x06000334 RID: 820 RVA: 0x0000CC4C File Offset: 0x0000AE4C
        private static void SetResponseHeadersForZipAttachments(IAttachmentWebOperationContext webOperationContext, string fileName)
        {
            if (webOperationContext == null)
            {
                throw new ArgumentNullException("webOperationContext");
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("Argument fileName may not be null or empty string");
            }
            webOperationContext.ContentType = "application/zip; authoritative=true;";
            ZipFileAttachments.SetZipContentDispositionResponseHeader(webOperationContext, fileName);
            DateHeader dateHeader = new DateHeader("Date", DateTime.UtcNow.AddDays(-1.0));

            webOperationContext.Headers["Expires"] = dateHeader.Value;
        }
예제 #3
0
        // Token: 0x0600033B RID: 827 RVA: 0x0000CEC8 File Offset: 0x0000B0C8
        private string ConditionZipEntryFileName(string fileName)
        {
            string text  = ZipFileAttachments.ToSafeFileNameString(fileName);
            string text2 = Path.GetFileNameWithoutExtension(text);
            bool   flag  = false;

            if (text.Length > 148)
            {
                int length = 148 - (text.Length - text2.Length);
                text2 = text2.Substring(0, length);
                flag  = true;
            }
            int num = text2.Length - 1;

            if (text2[0] == '.')
            {
                text2 = '_' + text2.Substring(1, num);
                flag  = true;
            }
            if (ZipFileAttachments.regexWindowsReservedNames.IsMatch(text2) || text2[num] == '.')
            {
                text2 = text2.Substring(0, num) + '_';
                flag  = true;
            }
            string extension = Path.GetExtension(text);
            string text3     = string.Empty;

            if (!flag)
            {
                text3 = text;
            }
            else
            {
                text3 = text2 + extension;
            }
            int num2 = 1;

            while (this.FileNameExists(text3))
            {
                text3 = string.Format("{0}[{1}]{2}", text2, num2, extension);
                num2++;
            }
            return(text3);
        }
예제 #4
0
        // Token: 0x06000336 RID: 822 RVA: 0x0000CD00 File Offset: 0x0000AF00
        private static string ToSafeFileNameString(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("filename", "Argument fileName may not be null or empty string");
            }
            StringBuilder stringBuilder = new StringBuilder(fileName.Length);

            for (int i = 0; i < fileName.Length; i++)
            {
                if (!ZipFileAttachments.IsFilenameOrPathInvalidChar(fileName[i]))
                {
                    stringBuilder.Append(fileName[i]);
                }
                else
                {
                    stringBuilder.Append('_');
                }
            }
            return(stringBuilder.ToString());
        }
        // 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);
        }
예제 #6
0
 // Token: 0x06000330 RID: 816 RVA: 0x0000C9F9 File Offset: 0x0000ABF9
 internal ZipFileAttachments(BlockStatus blockStatus, string zipFileName)
 {
     this.files       = new SortedDictionary <string, ZipEntryAttachment>(StringComparer.OrdinalIgnoreCase);
     this.blockStatus = blockStatus;
     this.zipFileName = ZipFileAttachments.ConditionZipFileNameForMimeHeader(zipFileName);
 }