Exemplo n.º 1
0
        public override IAttachment Read(string attachmentId)
        {
            IList <AttachmentId> attachmentIds = IdConverter.GetAttachmentIds(attachmentId);
            IAttachment          result;

            using (IItem item = this.BindToParentItem())
            {
                using (DisposeGuard disposeGuard = default(DisposeGuard))
                {
                    IItem      item2      = item;
                    Attachment attachment = null;
                    for (int i = 0; i < attachmentIds.Count; i++)
                    {
                        attachment = IrmUtils.GetAttachmentCollection(item2).Open(attachmentIds[i]);
                        disposeGuard.Add <Attachment>(attachment);
                        if (i < attachmentIds.Count - 1)
                        {
                            if (!(attachment is ItemAttachment))
                            {
                                throw new CorruptDataException(Strings.ErrorAllButLastNestedAttachmentMustBeItemAttachment);
                            }
                            ItemAttachment itemAttachment = attachment as ItemAttachment;
                            item2 = itemAttachment.GetItem();
                            disposeGuard.Add <IItem>(item2);
                        }
                    }
                    StorageTranslator <IAttachment, IAttachment> attachmentTranslator = this.GetAttachmentTranslator(attachment.AttachmentType, false);
                    IAttachment attachment2 = attachmentTranslator.ConvertToEntity(attachment);
                    attachment2.Id = attachmentId;
                    result         = attachment2;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
 internal static void CreateAttachment(IItem parentItem, Attachment16Data attachmentData)
 {
     AirSyncDiagnostics.TraceDebug <byte>(ExTraceGlobals.RequestsTracer, null, "CreateAttachment with AttachMethod:{0}", attachmentData.Method);
     if (attachmentData.Method == 1)
     {
         if (attachmentData.Content == null)
         {
             throw new ConversionException(string.Format(" Attachment content can not be null.", new object[0]));
         }
         IStreamAttachment streamAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.Stream) as IStreamAttachment;
         AttachmentHelper.CopyCommonAttachmentProperties(streamAttachment, attachmentData);
         using (Stream contentStream = streamAttachment.GetContentStream())
         {
             contentStream.Write(attachmentData.Content, 0, attachmentData.Content.Length);
         }
         streamAttachment.Save();
     }
     else
     {
         if (attachmentData.Method != 5)
         {
             throw new ConversionException(string.Format("UnSupported Value '{0}' for Attachment Method. Only 1 & 5 is supported AttachemntType", attachmentData.Method));
         }
         ItemAttachment itemAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.EmbeddedMessage) as ItemAttachment;
         AttachmentHelper.CopyCommonAttachmentProperties(itemAttachment, attachmentData);
         using (Stream stream = new MemoryStream(attachmentData.Content))
         {
             stream.Seek(0L, SeekOrigin.Begin);
             InboundConversionOptions inboundConversionOptions = AirSyncUtility.GetInboundConversionOptions();
             inboundConversionOptions.ClearCategories = false;
             try
             {
                 using (Item item = itemAttachment.GetItem())
                 {
                     ItemConversion.ConvertAnyMimeToItem(item, stream, inboundConversionOptions);
                     item.Save(SaveMode.NoConflictResolution);
                 }
             }
             catch (ExchangeDataException innerException)
             {
                 throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException, false);
             }
             catch (ConversionFailedException innerException2)
             {
                 throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException2, false);
             }
         }
         itemAttachment.Save();
     }
     AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, null, "AttachmentHelper:CreateAttachments:: AttachmentCreated successful. AttachmentCount:{0}", parentItem.IAttachmentCollection.Count);
 }
        // 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);
        }
        // Token: 0x0600003E RID: 62 RVA: 0x00004434 File Offset: 0x00002634
        private void AttachOriginalMessageToNotification(MessageItem initiationMessage, MessageItem notificationMessage, out string originalSenderDisplayname)
        {
            originalSenderDisplayname = string.Empty;
            if (string.IsNullOrEmpty(this.defaultAcceptedDomain))
            {
                ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Cannot attach original message to notification without domain for content conversion.");
                return;
            }
            AttachmentCollection attachmentCollection = initiationMessage.AttachmentCollection;

            foreach (AttachmentHandle handle in attachmentCollection)
            {
                using (Attachment attachment = attachmentCollection.Open(handle))
                {
                    if ("OriginalMessage".Equals(attachment.FileName, StringComparison.OrdinalIgnoreCase))
                    {
                        StreamAttachment streamAttachment = attachment as StreamAttachment;
                        if (streamAttachment != null)
                        {
                            using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.ReadOnly))
                            {
                                using (ItemAttachment itemAttachment = (ItemAttachment)notificationMessage.AttachmentCollection.Create(AttachmentType.EmbeddedMessage))
                                {
                                    using (Item item = itemAttachment.GetItem())
                                    {
                                        InboundConversionOptions options = new InboundConversionOptions(this.defaultAcceptedDomain);
                                        ItemConversion.ConvertAnyMimeToItem(item, contentStream, options);
                                        item[MessageItemSchema.Flags] = MessageFlags.None;
                                        originalSenderDisplayname     = (item.TryGetProperty(MessageItemSchema.SenderDisplayName) as string);
                                        item.Save(SaveMode.NoConflictResolution);
                                        itemAttachment[AttachmentSchema.DisplayName] = initiationMessage.Subject;
                                        itemAttachment.Save();
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
        // 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);
        }
Exemplo n.º 6
0
        // Token: 0x0600155B RID: 5467 RVA: 0x0007CE68 File Offset: 0x0007B068
        protected void CopyMessageContents(MessageItem source, MessageItem destination, bool copyOriginalRecipients, Item attachmentItem)
        {
            source.Load();
            string inReplyTo  = destination.InReplyTo;
            string references = destination.References;

            destination.Subject           = ((source.TryGetProperty(ItemSchema.SubjectPrefix) as string) ?? string.Empty) + ((source.TryGetProperty(ItemSchema.NormalizedSubject) as string) ?? string.Empty);
            destination.InReplyTo         = inReplyTo;
            destination.Importance        = source.Importance;
            destination.InternetMessageId = source.InternetMessageId;
            destination.Categories.Clear();
            destination.Categories.AddRange(source.Categories);
            destination.IconIndex = source.IconIndex;
            destination.IsRead    = source.IsRead;
            destination.IsReadReceiptRequested = source.IsReadReceiptRequested;
            destination.References             = references;
            if (copyOriginalRecipients)
            {
                this.originalRecipients = new HashSet <RecipientId>();
                foreach (Recipient recipient in destination.Recipients)
                {
                    this.originalRecipients.Add(recipient.Id);
                }
            }
            destination.Recipients.Clear();
            foreach (Recipient recipient2 in source.Recipients)
            {
                destination.Recipients.Add(recipient2.Participant, recipient2.RecipientItemType);
            }
            if (source.ReplyTo != null)
            {
                foreach (Participant item in source.ReplyTo)
                {
                    destination.ReplyTo.Add(item);
                }
            }
            RightsManagedMessageItem rightsManagedMessageItem = destination as RightsManagedMessageItem;
            AttachmentCollection     attachmentCollection     = (rightsManagedMessageItem != null) ? rightsManagedMessageItem.ProtectedAttachmentCollection : destination.AttachmentCollection;

            if (rightsManagedMessageItem == null && attachmentItem != null)
            {
                throw new InvalidOperationException("attachmentItem must be null for non-IRM messages");
            }
            if (this.ReplaceMime || attachmentItem != null)
            {
                if (rightsManagedMessageItem == null)
                {
                    Body.CopyBody(source, destination, GlobalSettings.DisableCharsetDetectionInCopyMessageContents);
                }
                else
                {
                    using (Stream stream = source.Body.OpenReadStream(new BodyReadConfiguration(source.Body.Format, source.Body.Charset)))
                    {
                        using (Stream stream2 = rightsManagedMessageItem.ProtectedBody.OpenWriteStream(new BodyWriteConfiguration(source.Body.Format, source.Body.Charset)))
                        {
                            Util.StreamHandler.CopyStreamData(stream, stream2);
                        }
                    }
                }
            }
            foreach (AttachmentHandle handle in source.AttachmentCollection)
            {
                using (Attachment attachment = source.AttachmentCollection.Open(handle))
                {
                    int num = 0;
                    if (attachment is StreamAttachment)
                    {
                        num = 1;
                    }
                    else if (attachment is OleAttachment)
                    {
                        num = 2;
                    }
                    if (num > 0)
                    {
                        Microsoft.Exchange.Data.Storage.AttachmentType type = (num == 1) ? Microsoft.Exchange.Data.Storage.AttachmentType.Stream : Microsoft.Exchange.Data.Storage.AttachmentType.Ole;
                        StreamAttachmentBase streamAttachmentBase           = (StreamAttachmentBase)attachment;
                        using (StreamAttachmentBase streamAttachmentBase2 = (StreamAttachmentBase)attachmentCollection.Create(type))
                        {
                            using (Stream contentStream = streamAttachmentBase2.GetContentStream())
                            {
                                using (Stream contentStream2 = streamAttachmentBase.GetContentStream())
                                {
                                    int    num2   = 4096;
                                    byte[] buffer = new byte[num2];
                                    int    count;
                                    while ((count = contentStream2.Read(buffer, 0, num2)) > 0)
                                    {
                                        contentStream.Write(buffer, 0, count);
                                    }
                                    streamAttachmentBase2.ContentType = streamAttachmentBase.ContentType;
                                    streamAttachmentBase2[AttachmentSchema.DisplayName] = streamAttachmentBase.DisplayName;
                                    streamAttachmentBase2.FileName = streamAttachmentBase.FileName;
                                    streamAttachmentBase2[AttachmentSchema.AttachContentId] = streamAttachmentBase[AttachmentSchema.AttachContentId];
                                    streamAttachmentBase2.IsInline = streamAttachmentBase.IsInline;
                                }
                            }
                            streamAttachmentBase2.Save();
                            continue;
                        }
                    }
                    ItemAttachment itemAttachment = (ItemAttachment)attachment;
                    using (Item item2 = itemAttachment.GetItem())
                    {
                        using (ItemAttachment itemAttachment2 = attachmentCollection.AddExistingItem(item2))
                        {
                            itemAttachment2.Save();
                        }
                    }
                }
            }
            if (attachmentItem != null)
            {
                using (ItemAttachment itemAttachment3 = attachmentCollection.AddExistingItem(attachmentItem))
                {
                    itemAttachment3.Save();
                }
            }
        }
Exemplo n.º 7
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
            }));
        }
        // Token: 0x06000431 RID: 1073 RVA: 0x0002396C File Offset: 0x00021B6C
        public void RenderAttachmentList()
        {
            AttachmentWellInfo attachmentWellInfo             = null;
            ArrayList          previousAttachmentDisplayNames = new ArrayList();

            base.SanitizingResponse.Write("<form name=\"delFrm\" action=\"?ae=Dialog&t=Attach&a=Del\" method=\"POST\">");
            base.SanitizingResponse.Write("<input type=\"hidden\" name=\"{0}\" value=\"{1}\">", "hidid", this.messageIdString);
            base.SanitizingResponse.Write("<input type=\"hidden\" name=\"{0}\" value=\"{1}\">", "hid64bitmsgid", Utilities.UrlEncode(this.messageIdString));
            base.SanitizingResponse.Write("<input type=\"hidden\" name=\"{0}\" value=\"{1}\">", "hidchk", this.changeKeyString);
            base.SanitizingResponse.Write("<div id=\"{0}\">", "lstArId");
            base.SanitizingResponse.Write("<table cellpadding=1 cellspacing=0 border=\"0\" class=\"attchList\"><caption>");
            base.SanitizingResponse.Write(LocalizedStrings.GetNonEncoded(573876176));
            base.SanitizingResponse.Write("</caption><tr>");
            base.SanitizingResponse.Write("<th class=\"lftcrnr\"><img src=\"");
            base.SanitizingResponse.Write(base.UserContext.GetThemeFileUrl(ThemeFileId.Clear));
            base.SanitizingResponse.Write("\" alt=\"\" class=\"invimg\"></th>");
            base.SanitizingResponse.Write("<th class=\"chkbx\">");
            base.SanitizingResponse.Write("<input type=\"checkbox\" name=\"chkAll\" id=\"chkAll\" onclick=\"chkAttchAll();\" alt=\"");
            base.SanitizingResponse.Write(LocalizedStrings.GetNonEncoded(-288583276));
            base.SanitizingResponse.Write("\"></th>");
            base.SanitizingResponse.Write("<th>");
            base.SanitizingResponse.Write(LocalizedStrings.GetNonEncoded(796893232));
            base.SanitizingResponse.Write("</th>");
            base.SanitizingResponse.Write("<th align=\"right\" class=\"sze\">");
            base.SanitizingResponse.Write(LocalizedStrings.GetNonEncoded(-837446919));
            base.SanitizingResponse.Write("</th>");
            base.SanitizingResponse.Write("<th class=\"rtcrnr\"><img src=\"");
            base.SanitizingResponse.Write(base.UserContext.GetThemeFileUrl(ThemeFileId.Clear));
            base.SanitizingResponse.Write("\" alt=\"\" class=\"invimg\"></th>");
            base.SanitizingResponse.Write("</tr>");
            if (this.attachmentList.Count > 0)
            {
                string value = null;
                for (int i = 0; i < this.attachmentList.Count; i++)
                {
                    string arg;
                    if (i == 0)
                    {
                        arg   = "class=\"frst\"";
                        value = "frst ";
                    }
                    else
                    {
                        arg   = null;
                        value = null;
                    }
                    attachmentWellInfo = (this.attachmentList[i] as AttachmentWellInfo);
                    base.SanitizingResponse.Write("<tr>");
                    base.SanitizingResponse.Write("<td {0} style=\"padding:0 0 0 0;\"><img src=\"{1}\" alt=\"\" class=\"invimg\"></td>", arg, base.UserContext.GetThemeFileUrl(ThemeFileId.Clear));
                    base.SanitizingResponse.Write("<td {0}><input type=checkbox name=\"{1}\" id=\"{1}\" value=\"{2}\" onclick=\"onClkChkBx(this);\"></td>", arg, "dLst", attachmentWellInfo.AttachmentId.ToBase64String());
                    base.SanitizingResponse.Write("<td {0}>", arg);
                    bool flag = false;
                    if (attachmentWellInfo.AttachmentType == AttachmentType.EmbeddedMessage)
                    {
                        using (Attachment attachment = attachmentWellInfo.OpenAttachment())
                        {
                            ItemAttachment itemAttachment = attachment as ItemAttachment;
                            if (itemAttachment != null)
                            {
                                using (Item item = itemAttachment.GetItem())
                                {
                                    flag = true;
                                    AttachmentWell.RenderAttachmentLinkForItem(base.SanitizingResponse, attachmentWellInfo, item, this.messageIdString, base.UserContext, previousAttachmentDisplayNames, AttachmentWell.AttachmentWellFlags.None, false);
                                }
                            }
                        }
                    }
                    if (!flag)
                    {
                        AttachmentWell.RenderAttachmentLink(base.SanitizingResponse, AttachmentWellType.ReadWrite, attachmentWellInfo, this.messageIdString, base.UserContext, previousAttachmentDisplayNames, AttachmentWell.AttachmentWellFlags.None, false);
                    }
                    base.SanitizingResponse.Write("</td>");
                    base.SanitizingResponse.Write("<td colspan=2 class=\"");
                    base.SanitizingResponse.Write(value);
                    base.SanitizingResponse.Write("sze\">");
                    double num = 0.0;
                    if (attachmentWellInfo.Size > 0L)
                    {
                        num = (double)attachmentWellInfo.Size / 1024.0 / 1024.0;
                        num = Math.Round(num, 2);
                        this.attachUsage += num;
                    }
                    if (num == 0.0)
                    {
                        base.SanitizingResponse.Write(" < 0.01");
                    }
                    else
                    {
                        base.SanitizingResponse.Write(num);
                    }
                    base.SanitizingResponse.Write(" MB</td>");
                    base.SanitizingResponse.Write("</tr>");
                }
            }
            else
            {
                base.SanitizingResponse.Write("<tr>");
                base.SanitizingResponse.Write("<td colspan=5 class=\"noattach\" nowrap>");
                base.SanitizingResponse.Write(LocalizedStrings.GetNonEncoded(-1907299050));
                base.SanitizingResponse.Write("</td>");
                base.SanitizingResponse.Write("</tr>");
            }
            base.SanitizingResponse.Write("</table>");
            base.SanitizingResponse.Write("</div>");
            Utilities.RenderCanaryHidden(base.SanitizingResponse, base.UserContext);
            base.SanitizingResponse.Write("</form>");
        }
        public void AddAttachment(Attachment attachment, IRecipientSession adRecipientSession)
        {
            bool     flag     = false;
            MimePart mimePart = attachment.MimePart;
            Header   header   = null;

            if (mimePart != null)
            {
                header = mimePart.Headers.FindFirst("X-MS-Exchange-Organization-Approval-AttachToApprovalRequest");
            }
            string text;

            if (header != null && header.TryGetValue(out text))
            {
                if (text.Equals("Never"))
                {
                    return;
                }
                if (text.Equals("AsMessage"))
                {
                    flag = true;
                }
            }
            if (flag)
            {
                using (Stream contentReadStream = attachment.GetContentReadStream())
                {
                    using (ItemAttachment itemAttachment = (ItemAttachment)this.messageItem.AttachmentCollection.Create(AttachmentType.EmbeddedMessage))
                    {
                        using (Item item = itemAttachment.GetItem())
                        {
                            ItemConversion.ConvertAnyMimeToItem(item, contentReadStream, new InboundConversionOptions(Components.Configuration.FirstOrgAcceptedDomainTable.DefaultDomainName)
                            {
                                UserADSession = adRecipientSession
                            });
                            item[MessageItemSchema.Flags] = MessageFlags.None;
                            item.Save(SaveMode.NoConflictResolution);
                            string valueOrDefault = item.GetValueOrDefault <string>(ItemSchema.Subject);
                            if (!string.IsNullOrEmpty(valueOrDefault))
                            {
                                itemAttachment[AttachmentSchema.DisplayName] = valueOrDefault;
                            }
                            itemAttachment.Save();
                        }
                    }
                    return;
                }
            }
            using (StreamAttachment streamAttachment = (StreamAttachment)this.messageItem.AttachmentCollection.Create(AttachmentType.Stream))
            {
                streamAttachment.FileName = attachment.FileName;
                using (Stream contentStream = streamAttachment.GetContentStream())
                {
                    using (Stream contentReadStream2 = attachment.GetContentReadStream())
                    {
                        ApprovalProcessor.CopyStream(contentReadStream2, contentStream, this.Buffer);
                    }
                    contentStream.Flush();
                }
                streamAttachment.Save();
            }
        }