コード例 #1
0
        // Token: 0x06001C33 RID: 7219 RVA: 0x0006FF24 File Offset: 0x0006E124
        protected override string InternalExecute()
        {
            IdAndSession idAndSession = base.IdConverter.ConvertItemIdToIdAndSessionReadOnly(this.itemId);
            MessageItem  messageItem  = Item.BindAsMessage(idAndSession.Session, idAndSession.Id);

            messageItem.Load(StoreObjectSchema.ContentConversionProperties);
            OutboundConversionOptions outboundConversionOptions = new OutboundConversionOptions(base.CallContext.DefaultDomain.DomainName.ToString());
            UserContext userContext = UserContextManager.GetUserContext(base.CallContext.HttpContext);

            outboundConversionOptions.UserADSession = UserContextUtilities.CreateADRecipientSession(base.CallContext.ClientCulture.LCID, true, ConsistencyMode.IgnoreInvalid, false, userContext, true, base.CallContext.Budget);
            outboundConversionOptions.LoadPerOrganizationCharsetDetectionOptions(userContext.ExchangePrincipal.MailboxInfo.OrganizationId);
            outboundConversionOptions.AllowPartialStnefConversion = true;
            outboundConversionOptions.DemoteBcc = true;
            string @string;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                ItemConversion.ConvertItemToMime(messageItem, memoryStream, outboundConversionOptions);
                memoryStream.Position = 0L;
                byte[] array = new byte[memoryStream.Length];
                memoryStream.Read(array, 0, array.Length);
                @string = Encoding.ASCII.GetString(array);
            }
            return(@string);
        }
コード例 #2
0
        internal static void DecodeIrmMessage(StoreSession storeSession, Item mailboxItem, bool acquireLicense)
        {
            RightsManagedMessageItem rightsManagedMessageItem = mailboxItem as RightsManagedMessageItem;

            if (rightsManagedMessageItem == null)
            {
                return;
            }
            if (!IrmUtils.DoesSessionSupportIrm(storeSession))
            {
                return;
            }
            if (!rightsManagedMessageItem.IsRestricted)
            {
                return;
            }
            if (!rightsManagedMessageItem.CanDecode)
            {
                return;
            }
            if (rightsManagedMessageItem.IsDecoded)
            {
                return;
            }
            OutboundConversionOptions outboundConversionOptions = IrmUtils.GetOutboundConversionOptions(storeSession.MailboxOwner.MailboxInfo.OrganizationId);

            rightsManagedMessageItem.TryDecode(outboundConversionOptions, acquireLicense);
        }
コード例 #3
0
        // Token: 0x06002914 RID: 10516 RVA: 0x000E8774 File Offset: 0x000E6974
        protected void RenderMime()
        {
            OutboundConversionOptions outboundConversionOptions = Utilities.CreateOutboundConversionOptions(base.UserContext);

            outboundConversionOptions.AllowPartialStnefConversion = true;
            outboundConversionOptions.DemoteBcc = true;
            try
            {
                ItemConversion.ConvertItemToMime(base.Item, base.Response.OutputStream, outboundConversionOptions);
            }
            catch (NotSupportedException innerException)
            {
                throw new OwaInvalidRequestException("Conversion failed", innerException);
            }
            catch (NotImplementedException innerException2)
            {
                throw new OwaInvalidRequestException("Conversion failed", innerException2);
            }
            catch (StoragePermanentException innerException3)
            {
                throw new OwaInvalidRequestException("Conversion failed", innerException3);
            }
            catch (StorageTransientException innerException4)
            {
                throw new OwaInvalidRequestException("Conversion failed", innerException4);
            }
        }
コード例 #4
0
ファイル: TestMessage.cs プロジェクト: YHZX2013/exchange_diff
        private bool TryGenerateMessageFromMsgFileData(string defaultDomain)
        {
            bool result;

            using (Stream stream = new MemoryStream(this.MessageFileData))
            {
                using (MessageItem messageItem = MessageItem.CreateInMemory(StoreObjectSchema.ContentConversionProperties))
                {
                    using (Stream stream2 = new MemoryStream())
                    {
                        try
                        {
                            InboundConversionOptions inboundConversionOptions = new InboundConversionOptions(defaultDomain);
                            inboundConversionOptions.UserADSession = this.GetRecipientSession();
                            OutboundConversionOptions outboundConversionOptions = new OutboundConversionOptions(defaultDomain);
                            outboundConversionOptions.UserADSession = inboundConversionOptions.UserADSession;
                            ItemConversion.ConvertMsgStorageToItem(stream, messageItem, inboundConversionOptions);
                            if (this.WasSpecifiedByUser("Sender"))
                            {
                                SmtpAddress sender  = this.Sender;
                                Participant sender2 = new Participant(string.Empty, (string)this.Sender, "SMTP");
                                messageItem.Sender = sender2;
                            }
                            ItemConversion.ConvertItemToSummaryTnef(messageItem, stream2, outboundConversionOptions);
                            stream2.Position = 0L;
                            this.message     = EmailMessage.Create(stream2);
                            result           = true;
                        }
                        catch (CorruptDataException ex)
                        {
                            base.WriteVerbose(Strings.UnableToCreateFromMsg(ex.Message));
                            result = false;
                        }
                        catch (ConversionFailedException ex2)
                        {
                            base.WriteVerbose(Strings.UnableToCreateFromMsg(ex2.Message));
                            result = false;
                        }
                        catch (PropertyErrorException ex3)
                        {
                            base.WriteVerbose(Strings.UnableToCreateFromMsg(ex3.Message));
                            result = false;
                        }
                        catch (StoragePermanentException ex4)
                        {
                            base.WriteVerbose(Strings.UnableToCreateFromMsg(ex4.Message));
                            result = false;
                        }
                        catch (StorageTransientException ex5)
                        {
                            base.WriteVerbose(Strings.UnableToCreateFromMsg(ex5.Message));
                            result = false;
                        }
                    }
                }
            }
            return(result);
        }
コード例 #5
0
        // Token: 0x06001988 RID: 6536 RVA: 0x000953D4 File Offset: 0x000935D4
        internal Stream GetItemAttachmentStream(Attachment attachment, HttpContext httpContext)
        {
            OwaContext  owaContext  = OwaContext.Get(httpContext);
            UserContext userContext = owaContext.UserContext;
            OutboundConversionOptions outboundConversionOptions = Utilities.CreateOutboundConversionOptions(userContext);
            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 = this.GetContentsReplacementStream(-1706159495);
                    text   = ".txt";
                }
            }
            if (text != null)
            {
                this.fileName             = this.GetConvertedItemFileName(this.fileName, text);
                this.encodedfileNameBytes = this.GetEncodedString(this.fileName);
            }
            stream.Position = 0L;
            return(stream);
        }
コード例 #6
0
        private ItemPartIrmInfo GetItemPartIrmInfo(IItem item)
        {
            RightsManagedMessageItem rightsManagedMessageItem = item as RightsManagedMessageItem;

            if (rightsManagedMessageItem == null || !rightsManagedMessageItem.IsRestricted)
            {
                return(ItemPartIrmInfo.NotRestricted);
            }
            ItemPartIrmInfo result = null;

            if (!this.canOpenIrmMessage || !rightsManagedMessageItem.CanDecode)
            {
                if (!this.canOpenIrmMessage)
                {
                    result = ItemPartIrmInfo.CreateForIrmDisabled();
                }
                else if (!rightsManagedMessageItem.CanDecode)
                {
                    result = ItemPartIrmInfo.CreateForUnsupportedScenario();
                }
            }
            else
            {
                try
                {
                    OutboundConversionOptions options = new OutboundConversionOptions(item.Session.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid), string.Empty);
                    rightsManagedMessageItem.Decode(options, true);
                    result = ItemPartIrmInfo.Create(rightsManagedMessageItem.UsageRights, rightsManagedMessageItem.Restriction.Name, rightsManagedMessageItem.Restriction.Description, rightsManagedMessageItem.ConversationOwner.EmailAddress, rightsManagedMessageItem.UserLicenseExpiryTime, rightsManagedMessageItem.Restriction.RequiresRepublishingWhenRecipientsChange, rightsManagedMessageItem.CanRepublish);
                }
                catch (RightsManagementPermanentException exception)
                {
                    result = ItemPartIrmInfo.CreateForDecryptionFailure(exception);
                }
                catch (RightsManagementTransientException exception2)
                {
                    result = ItemPartIrmInfo.CreateForDecryptionFailure(exception2);
                }
            }
            return(result);
        }
コード例 #7
0
        private void CopyMfnContentTo(MeetingForwardNotification meetingForwardNotification, TransportMailItem mailItem)
        {
            OutboundConversionOptions outboundConversionOptions = new OutboundConversionOptions(Components.Configuration.FirstOrgAcceptedDomainTable.DefaultDomainName);

            outboundConversionOptions.DsnMdnOptions          = DsnMdnOptions.PropagateUserSettings;
            outboundConversionOptions.DsnHumanReadableWriter = Components.DsnGenerator.DsnHumanReadableWriter;
            outboundConversionOptions.RecipientCache         = mailItem.ADRecipientCache;
            outboundConversionOptions.UserADSession          = mailItem.ADRecipientCache.ADSession;
            mailItem.CacheTransportSettings();
            outboundConversionOptions.ClearCategories    = mailItem.TransportSettings.ClearCategories;
            outboundConversionOptions.UseRFC2231Encoding = mailItem.TransportSettings.Rfc2231EncodingEnabled;
            outboundConversionOptions.Limits.MimeLimits  = MimeLimits.Unlimited;
            outboundConversionOptions.AllowDlpHeadersToPenetrateFirewall = true;
            using (Stream stream = mailItem.OpenMimeWriteStream())
            {
                if (Components.Configuration.LocalServer.TransportServer.ContentConversionTracingEnabled && Components.Configuration.LocalServer.TransportServer.PipelineTracingPath != null)
                {
                    outboundConversionOptions.LogDirectoryPath = Components.Configuration.LocalServer.TransportServer.PipelineTracingPath.PathName;
                }
                ItemConversion.ConvertItemToSummaryTnef(meetingForwardNotification, stream, outboundConversionOptions);
            }
        }
コード例 #8
0
        public static Stream ConvertItemToMime(StoreObject xsoItem)
        {
            Item item = xsoItem as Item;

            if (item == null)
            {
                throw new UnexpectedTypeException("Item", xsoItem);
            }
            OutboundConversionOptions outboundConversionOptions = AirSyncUtility.GetOutboundConversionOptions();
            PolicyData policyData = ADNotificationManager.GetPolicyData(Command.CurrentCommand.User);

            if (policyData != null && !policyData.AttachmentsEnabled)
            {
                outboundConversionOptions.FilterAttachmentHandler = ((Item item1, Attachment attachment) => false);
            }
            item.Load(StoreObjectSchema.ContentConversionProperties);
            AirSyncStream airSyncStream = new AirSyncStream();

            try
            {
                if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item))
                {
                    ItemConversion.ConvertItemToMime(((RightsManagedMessageItem)item).DecodedItem, airSyncStream, outboundConversionOptions);
                }
                else
                {
                    ItemConversion.ConvertItemToMime(item, airSyncStream, outboundConversionOptions);
                }
            }
            catch (ConversionFailedException innerException)
            {
                throw new ConversionException(string.Format(CultureInfo.InvariantCulture, "MIME conversion failed for Item {0}", new object[]
                {
                    item
                }), innerException);
            }
            return(airSyncStream);
        }
コード例 #9
0
 private byte[] GetMimeData(StoreObjectId itemId, out string[] recipients)
 {
     recipients = null;
     byte[] result;
     using (MessageItem messageItem = MessageItem.Bind(this.mailboxSession, itemId, StoreObjectSchema.ContentConversionProperties))
     {
         List <string> list = new List <string>(messageItem.Recipients.Count);
         foreach (RecipientBase recipientBase in messageItem.Recipients)
         {
             Participant participant = recipientBase.Participant;
             if (participant != null)
             {
                 string valueOrDefault = participant.GetValueOrDefault <string>(ParticipantSchema.SmtpAddress);
                 list.Add(valueOrDefault);
             }
         }
         OutboundConversionOptions options = new OutboundConversionOptions(this.mailboxSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid), this.mailboxSession.ServerFullyQualifiedDomainName)
         {
             IsSenderTrusted = true,
             RecipientCache  = null,
             ClearCategories = true,
             Limits          =
             {
                 MimeLimits = MimeLimits.Unlimited
             },
             AllowPartialStnefConversion = true
         };
         using (PooledMemoryStream pooledMemoryStream = new PooledMemoryStream(6))
         {
             ItemConversion.ConvertItemToMime(messageItem, pooledMemoryStream, options);
             recipients = list.ToArray();
             result     = pooledMemoryStream.ToArray();
         }
     }
     return(result);
 }
コード例 #10
0
        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)));
        }
コード例 #11
0
        // 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);
        }
コード例 #12
0
        // 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);
        }
コード例 #13
0
        private static string GetAttachmentItself(Attachment attachment, Stream outStream, int offset, int count, out int total)
        {
            string text = string.Empty;

            total = 0;
            StreamAttachmentBase streamAttachmentBase = attachment as StreamAttachmentBase;

            if (streamAttachmentBase != null)
            {
                OleAttachment oleAttachment = streamAttachmentBase as OleAttachment;
                Stream        stream        = null;
                try
                {
                    if (oleAttachment != null)
                    {
                        stream = oleAttachment.TryConvertToImage(ImageFormat.Jpeg);
                        if (stream != null)
                        {
                            text = "image/jpeg";
                        }
                    }
                    if (stream == null)
                    {
                        stream = streamAttachmentBase.GetContentStream();
                    }
                    if (string.IsNullOrEmpty(text))
                    {
                        text = attachment.ContentType;
                    }
                    if (string.IsNullOrEmpty(text))
                    {
                        text = attachment.CalculatedContentType;
                    }
                    if (stream.Length > 0L)
                    {
                        if ((long)offset >= stream.Length)
                        {
                            throw new ArgumentOutOfRangeException("offset");
                        }
                        int num = (count == -1) ? ((int)stream.Length) : count;
                        if (num > GlobalSettings.MaxDocumentDataSize)
                        {
                            throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge);
                        }
                        StreamHelper.CopyStream(stream, outStream, offset, num);
                        total = (int)stream.Length;
                    }
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                        stream = null;
                    }
                }
                return(text);
            }
            ItemAttachment itemAttachment = attachment as ItemAttachment;

            if (itemAttachment != null)
            {
                using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties))
                {
                    text = "message/rfc822";
                    OutboundConversionOptions outboundConversionOptions = AirSyncUtility.GetOutboundConversionOptions();
                    using (AirSyncStream airSyncStream = new AirSyncStream())
                    {
                        try
                        {
                            ItemConversion.ConvertItemToMime(item, airSyncStream, outboundConversionOptions);
                        }
                        catch (ConversionFailedException innerException)
                        {
                            throw new FormatException(string.Format(CultureInfo.InvariantCulture, "MIME conversion failed for Attachment {0}!", new object[]
                            {
                                attachment
                            }), innerException);
                        }
                        if (airSyncStream.Length > 0L)
                        {
                            if ((long)offset >= airSyncStream.Length)
                            {
                                throw new ArgumentOutOfRangeException("offset");
                            }
                            int num2 = (count == -1) ? ((int)airSyncStream.Length) : count;
                            if (num2 > GlobalSettings.MaxDocumentDataSize)
                            {
                                throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge);
                            }
                            StreamHelper.CopyStream(airSyncStream, outStream, offset, num2);
                            total = (int)airSyncStream.Length;
                        }
                    }
                }
                return(text);
            }
            throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Attachment {0} is of invalid format!", new object[]
            {
                attachment
            }));
        }
コード例 #14
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);
        }