Пример #1
0
        // Token: 0x06000C2F RID: 3119 RVA: 0x0003FD5C File Offset: 0x0003DF5C
        private void BuildMultiPartResponse(XmlDocument xmlResponse)
        {
            StringBuilder stringBuilder = null;

            if (base.MailboxLoggingEnabled && base.MailboxLogger != null)
            {
                stringBuilder = new StringBuilder();
                stringBuilder.Append("----------------------- Multipart Response ---------------------\r\n");
            }
            using (BinaryWriter binaryWriter = new BinaryWriter(base.OutputStream))
            {
                AirSyncStream airSyncStream = new AirSyncStream();
                base.Context.Response.BuildMultiPartWbXmlResponse(xmlResponse, airSyncStream);
                this.multipartStreams.Insert(0, airSyncStream);
                binaryWriter.Write(this.multipartStreams.Count);
                if (stringBuilder != null)
                {
                    stringBuilder.AppendFormat("Number of Parts: {0}\r\n", this.multipartStreams.Count);
                }
                int num = 4 + this.multipartStreams.Count * 8;
                for (int i = 0; i < this.multipartStreams.Count; i++)
                {
                    long length = this.multipartStreams[i].Length;
                    binaryWriter.Write(num);
                    binaryWriter.Write((int)length);
                    if (stringBuilder != null)
                    {
                        stringBuilder.AppendFormat("Part {0}: offset {1}, size {2}\r\n", i, num, length);
                    }
                    num += (int)length;
                }
                for (int j = 0; j < this.multipartStreams.Count; j++)
                {
                    StreamHelper.CopyStream(this.multipartStreams[j], base.OutputStream, (int)this.multipartStreams[j].Length);
                    if (stringBuilder != null && j == 0)
                    {
                        stringBuilder.AppendLine();
                        this.multipartStreams[j].Seek(0L, SeekOrigin.Begin);
                        using (WbxmlReader wbxmlReader = new WbxmlReader(this.multipartStreams[j]))
                        {
                            stringBuilder.Append(AirSyncUtility.BuildOuterXml(wbxmlReader.ReadXmlDocument(), !GlobalSettings.EnableMailboxLoggingVerboseMode));
                        }
                        stringBuilder.AppendLine();
                    }
                }
                if (stringBuilder != null)
                {
                    base.MailboxLogger.SetData(MailboxLogDataName.ResponseBody, stringBuilder.ToString());
                }
            }
        }
Пример #2
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
            }));
        }