public void SetBody(Body body)
        {
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(this.GetXsoBodyFormat(body), body.CharsetName);
            Body body2 = this.messageItem.Body;

            using (Stream stream = body2.OpenWriteStream(configuration))
            {
                using (Stream contentReadStream = body.GetContentReadStream())
                {
                    ApprovalProcessor.CopyStream(contentReadStream, stream, this.Buffer);
                }
                stream.Flush();
            }
        }
        // Token: 0x06000039 RID: 57 RVA: 0x00003EA4 File Offset: 0x000020A4
        private void SendRejectNotification(MessageItem messageItem)
        {
            ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Entering SendRejectNotification");
            if (!this.ShouldSendNotification(messageItem))
            {
                return;
            }
            RoutingAddress routingAddress;

            if (!this.TryGetOriginalSender(messageItem, out routingAddress))
            {
                return;
            }
            MailboxSession mailboxSession = (MailboxSession)messageItem.Session;

            messageItem.Load(ModeratedDLApplication.NotificationPropertiesFromInitMessage);
            string valueOrDefault = messageItem.GetValueOrDefault <string>(MessageItemSchema.AcceptLanguage, string.Empty);
            DsnHumanReadableWriter defaultDsnHumanReadableWriter = DsnHumanReadableWriter.DefaultDsnHumanReadableWriter;
            ICollection <string>   moderatedRecipients           = this.GetModeratedRecipients(messageItem, false);
            string        valueOrDefault2 = messageItem.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty);
            StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox);

            using (MessageItem messageItem2 = MessageItem.Create(mailboxSession, defaultFolderId))
            {
                StreamAttachment streamAttachment = null;
                try
                {
                    bool flag = ModeratedDLApplication.TryGetCommentAttachment(messageItem, out streamAttachment) && streamAttachment.Size > 0L;
                    messageItem2.ClassName = "IPM.Note.Microsoft.Approval.Reply.Reject";
                    bool flag2 = true;
                    ApprovalInformation approvalInformation = null;
                    if (flag)
                    {
                        approvalInformation  = defaultDsnHumanReadableWriter.GetModerateRejectInformation(messageItem.Subject, moderatedRecipients, flag, valueOrDefault2, valueOrDefault);
                        messageItem2.Subject = approvalInformation.Subject;
                        flag2 = this.TryWriteNotificationWithAppendedComments(defaultDsnHumanReadableWriter, messageItem2, streamAttachment, approvalInformation);
                    }
                    if (!flag || !flag2)
                    {
                        approvalInformation  = defaultDsnHumanReadableWriter.GetModerateRejectInformation(messageItem.Subject, moderatedRecipients, false, valueOrDefault2, valueOrDefault);
                        messageItem2.Subject = approvalInformation.Subject;
                        BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, approvalInformation.MessageCharset.Name);
                        using (Stream stream = messageItem2.Body.OpenWriteStream(configuration))
                        {
                            defaultDsnHumanReadableWriter.WriteHtmlModerationBody(stream, approvalInformation);
                            stream.Flush();
                        }
                    }
                    if (flag && !flag2)
                    {
                        using (StreamAttachment streamAttachment2 = messageItem2.AttachmentCollection.Create(AttachmentType.Stream) as StreamAttachment)
                        {
                            streamAttachment2.FileName = defaultDsnHumanReadableWriter.GetModeratorsCommentFileName(approvalInformation.Culture);
                            using (Stream contentStream = streamAttachment2.GetContentStream())
                            {
                                using (Stream contentStream2 = streamAttachment.GetContentStream(PropertyOpenMode.ReadOnly))
                                {
                                    byte[] buffer = new byte[8192];
                                    ApprovalProcessor.CopyStream(contentStream2, contentStream, buffer);
                                }
                                contentStream.Flush();
                            }
                            streamAttachment2.Save();
                        }
                    }
                    this.StampCommonNotificationProperties(messageItem2, messageItem, new RoutingAddress[]
                    {
                        routingAddress
                    }, valueOrDefault2, approvalInformation.Culture);
                    messageItem2.SendWithoutSavingMessage();
                }
                finally
                {
                    if (streamAttachment != null)
                    {
                        streamAttachment.Dispose();
                    }
                }
            }
        }
        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();
            }
        }