private bool TryWriteApprovalRequestBodyWithPreview(Body destiniationBody, DsnHumanReadableWriter approvalRequestWriter, ApprovalInformation info, Charset outputCharset)
        {
            if (this.originalEmailMessage == null)
            {
                return(false);
            }
            TextConverter textConverter;

            if (this.originalMesssageBodyFormat == Microsoft.Exchange.Data.Transport.Email.BodyFormat.Rtf)
            {
                textConverter = new RtfToHtml
                {
                    Header             = approvalRequestWriter.GetHtmlModerationBody(info),
                    HeaderFooterFormat = HeaderFooterFormat.Html,
                    OutputEncoding     = outputCharset.GetEncoding()
                };
            }
            else if (this.originalMesssageBodyFormat == Microsoft.Exchange.Data.Transport.Email.BodyFormat.Text)
            {
                textConverter = new TextToHtml
                {
                    Header             = approvalRequestWriter.GetHtmlModerationBody(info),
                    HeaderFooterFormat = HeaderFooterFormat.Html,
                    InputEncoding      = this.originalMessageBodyCharset.GetEncoding(),
                    OutputEncoding     = outputCharset.GetEncoding()
                };
            }
            else
            {
                if (this.originalMesssageBodyFormat != Microsoft.Exchange.Data.Transport.Email.BodyFormat.Html)
                {
                    return(false);
                }
                textConverter = new HtmlToHtml
                {
                    Header             = approvalRequestWriter.GetHtmlModerationBody(info),
                    HeaderFooterFormat = HeaderFooterFormat.Html,
                    InputEncoding      = this.originalMessageBodyCharset.GetEncoding(),
                    OutputEncoding     = outputCharset.GetEncoding()
                };
            }
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml, outputCharset);

            using (Stream stream = destiniationBody.OpenWriteStream(configuration))
            {
                using (Stream contentReadStream = this.originalEmailMessage.Body.GetContentReadStream())
                {
                    try
                    {
                        textConverter.Convert(contentReadStream, stream);
                    }
                    catch (ExchangeDataException arg)
                    {
                        ModerationApprovalRequestWriter.diag.TraceDebug <ExchangeDataException>(0L, "Approval request with inline preview failed {0}", arg);
                        return(false);
                    }
                }
            }
            return(true);
        }
        private static BodyWriteConfiguration CreateBodyWriteConfiguration(BodyFormat bf)
        {
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(bf, "utf-8");

            bodyWriteConfiguration.SetTargetFormat(bf, "utf-8", BodyCharsetFlags.DisableCharsetDetection);
            return(bodyWriteConfiguration);
        }
        // Token: 0x06000620 RID: 1568 RVA: 0x00030A78 File Offset: 0x0002EC78
        public static void RenderReadBody(TextWriter output, Item item, OwaSafeHtmlCallbackBase callBack, bool isJunkOrPhishing)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (item == null)
            {
                return;
            }
            ReportMessage reportMessage = item as ReportMessage;
            bool          flag          = null != reportMessage;

            if (Utilities.IsOpaqueSigned(item))
            {
                MessageItem messageItem = item as MessageItem;
                Item        item2       = null;
                if (messageItem != null && ItemConversion.TryOpenSMimeContent(messageItem, OwaContext.Current.UserContext.Configuration.DefaultAcceptedDomain.Name, out item2))
                {
                    item = item2;
                }
            }
            if (item.Body == null || (flag && item.Body.Size <= 0L))
            {
                if (flag)
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        Charset charset;
                        reportMessage.GenerateReportBody(memoryStream, out charset);
                        item.OpenAsReadWrite();
                        BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, charset.Name);
                        using (Stream stream = item.Body.OpenWriteStream(configuration))
                        {
                            memoryStream.Position = 0L;
                            memoryStream.WriteTo(stream);
                        }
                        goto IL_DC;
                    }
                }
                return;
            }
IL_DC:
            Body body = item.Body;

            if (!OwaContext.Current.UserContext.IsBasicExperience && OwaContext.Current.UserContext.IsIrmEnabled && Utilities.IsIrmRestrictedAndDecrypted(item))
            {
                body = ((RightsManagedMessageItem)item).ProtectedBody;
            }
            if (body.Size > 0L)
            {
                Markup markup = Markup.Html;
                if (isJunkOrPhishing)
                {
                    markup = Markup.PlainText;
                }
                BodyConversionUtilities.ConvertAndOutputBody(output, body, markup, callBack, false);
            }
        }
        // Token: 0x06001C01 RID: 7169 RVA: 0x0006D934 File Offset: 0x0006BB34
        private static void SetItemBody(Item item, BodyFormat bodyFormat, string bodyContent)
        {
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(bodyFormat);

            using (TextWriter textWriter = item.Body.OpenTextWriter(configuration))
            {
                textWriter.Write(bodyContent);
            }
        }
Beispiel #5
0
        public override void Apply(MailboxSession session, Item item)
        {
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextPlain);

            using (TextWriter textWriter = item.Body.OpenTextWriter(configuration))
            {
                string asString = AuditLogParseSerialize.GetAsString(this);
                textWriter.Write(asString);
            }
            item.ClassName = "IPM.AuditLog";
        }
        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();
            }
        }
        private static TextWriter CreateTextWriter(IItem item, BodyType type, bool update, out HtmlUpdateBodyCallback htmlUpdateBodyCallback)
        {
            Body body = IrmUtils.GetBody(item);
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(type.ToStorageType());

            if (update && type == BodyType.Html)
            {
                htmlUpdateBodyCallback = new HtmlUpdateBodyCallback(item);
                bodyWriteConfiguration.SetHtmlOptions(HtmlStreamingFlags.None, htmlUpdateBodyCallback);
                return(body.OpenTextWriter(bodyWriteConfiguration));
            }
            htmlUpdateBodyCallback = null;
            return(body.OpenTextWriter(bodyWriteConfiguration));
        }
Beispiel #8
0
        public static int SerializeMailboxAuditRecord(IAuditLogRecord auditRecord, MessageItem auditMessage)
        {
            int result = 0;
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextPlain);

            using (TextWriter textWriter = auditMessage.Body.OpenTextWriter(configuration))
            {
                string asString = AuditLogParseSerialize.GetAsString(auditRecord);
                textWriter.Write(asString);
                result = Encoding.Unicode.GetByteCount(asString);
            }
            ExTraceGlobals.FaultInjectionTracer.TraceTest(2219191613U);
            auditMessage.ClassName = "IPM.AuditLog";
            return(result);
        }
Beispiel #9
0
        public static int SerializeAdminAuditRecord(IAuditLogRecord auditRecord, MessageItem auditMessage)
        {
            int result = 0;

            auditMessage.Subject = string.Format("{0} : {1}", auditRecord.UserId, auditRecord.Operation);
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextPlain);

            using (TextWriter textWriter = auditMessage.Body.OpenTextWriter(configuration))
            {
                string asString = AuditLogParseSerialize.GetAsString(auditRecord);
                textWriter.Write(asString);
                result = Encoding.Unicode.GetByteCount(asString);
            }
            auditMessage.From = new Participant(string.Format("{0}{1}", auditRecord.UserId, "audit"), string.Empty, string.Empty);
            auditMessage.Recipients.Add(new Participant(string.Format("{0}{1}", auditRecord.ObjectId, "audit"), string.Empty, string.Empty));
            auditMessage.ClassName = "IPM.AuditLog";
            return(result);
        }
        // Token: 0x06000037 RID: 55 RVA: 0x00003A78 File Offset: 0x00001C78
        private void SendExpiryNdrOofNotification(MessageItem messageItem, ApprovalInformation.ApprovalNotificationType notificationType)
        {
            ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Entering SendExpiryNdrOofNotification");
            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);
            ICollection <string> moderatedRecipients = this.GetModeratedRecipients(messageItem, false);
            string valueOrDefault2 = messageItem.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty);
            DsnHumanReadableWriter defaultDsnHumanReadableWriter = DsnHumanReadableWriter.DefaultDsnHumanReadableWriter;
            StoreObjectId          defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox);

            using (MessageItem messageItem2 = MessageItem.Create(mailboxSession, defaultFolderId))
            {
                ApprovalInformation approvalInformation = null;
                approvalInformation  = defaultDsnHumanReadableWriter.GetMessageInModerationExpiredNdrOofInformation(notificationType, messageItem.Subject, moderatedRecipients, 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);
                }
                this.StampCommonNotificationProperties(messageItem2, messageItem, new RoutingAddress[]
                {
                    routingAddress
                }, valueOrDefault2, approvalInformation.Culture);
                string text;
                this.AttachOriginalMessageToNotification(messageItem, messageItem2, out text);
                messageItem2.ClassName = "IPM.Note.Microsoft.Approval.Reply";
                messageItem2.SendWithoutSavingMessage();
                ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Notification sent.");
            }
        }
        // Token: 0x0600003F RID: 63 RVA: 0x00004608 File Offset: 0x00002808
        private bool TryWriteNotificationWithAppendedComments(DsnHumanReadableWriter notificationWriter, MessageItem rejectItem, StreamAttachment commentAttachment, ApprovalInformation info)
        {
            bool     result             = true;
            string   htmlModerationBody = notificationWriter.GetHtmlModerationBody(info);
            Charset  textCharset        = commentAttachment.TextCharset;
            Encoding inputEncoding      = null;

            if (textCharset == null || !textCharset.TryGetEncoding(out inputEncoding))
            {
                return(false);
            }
            Charset charset = textCharset;

            if (!ModeratedDLApplication.IsEncodingMatch(info.Codepages, textCharset.CodePage))
            {
                charset = Charset.UTF8;
            }
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, charset.Name);

            using (Stream stream = rejectItem.Body.OpenWriteStream(configuration))
            {
                HtmlToHtml htmlToHtml = new HtmlToHtml();
                htmlToHtml.Header             = htmlModerationBody;
                htmlToHtml.HeaderFooterFormat = HeaderFooterFormat.Html;
                htmlToHtml.InputEncoding      = inputEncoding;
                htmlToHtml.OutputEncoding     = charset.GetEncoding();
                try
                {
                    using (Stream contentStream = commentAttachment.GetContentStream(PropertyOpenMode.ReadOnly))
                    {
                        htmlToHtml.Convert(contentStream, stream);
                        stream.Flush();
                    }
                }
                catch (ExchangeDataException arg)
                {
                    ModeratedDLApplication.diag.TraceDebug <ExchangeDataException>(0L, "Attaching comments failed with {0}", arg);
                    result = false;
                }
            }
            return(result);
        }
        private void WriteApprovalRequestBody(Body destiniationBody, DsnHumanReadableWriter writer, ApprovalInformation info, bool writePreview)
        {
            if (writePreview)
            {
                Charset outputCharset;
                bool    flag = !ModerationApprovalRequestWriter.CheckInputOutputCharsetMatch(info.Codepages, this.originalMessageBodyCharset, out outputCharset);
                if (!flag && this.TryWriteApprovalRequestBodyWithPreview(destiniationBody, writer, info, outputCharset))
                {
                    return;
                }
                ModerationApprovalRequestWriter.diag.TraceError <bool, string>((long)this.GetHashCode(), "Failed to write preview for message.  Falling back to no preview. Charset mismatch:{0}. Approval data:{1}.", flag, this.initiationMessage.ApprovalData);
                info = writer.GetApprovalRequestMessageInformation(this.initiationMessage.Subject, this.originalSenderDisplayName, this.originalToFormattedLine, this.originalCcFormattedLine, this.moderatedRecipients, false, info.Culture);
            }
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml, info.MessageCharset.Name);

            using (Stream stream = destiniationBody.OpenWriteStream(configuration))
            {
                writer.WriteHtmlModerationBody(stream, info);
            }
        }
Beispiel #13
0
        private void SendMapiMessageHelper(bool setLamNotificationId, string lamNotificationId, SendMapiMailDefinition mapiMailDefinition, bool returnOutParameters, out string entryId, out string internetMessageId, out Guid senderMbxGuid)
        {
            entryId           = string.Empty;
            internetMessageId = string.Empty;
            senderMbxGuid     = Guid.Empty;
            ExchangePrincipal mailboxOwner;

            if (mapiMailDefinition.SenderMbxGuid != Guid.Empty)
            {
                mailboxOwner = ExchangePrincipal.FromMailboxData(mapiMailDefinition.SenderMbxGuid, mapiMailDefinition.SenderMdbGuid, new List <CultureInfo>(0));
            }
            else
            {
                string domainPartOfEmailAddress = MapiMessageSubmitter.GetDomainPartOfEmailAddress(mapiMailDefinition.SenderEmailAddress);
                mailboxOwner = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(domainPartOfEmailAddress), mapiMailDefinition.SenderEmailAddress);
            }
            using (MailboxSession mailboxSession = MailboxSession.OpenAsTransport(mailboxOwner, "Client=Monitoring;Action=MapiSubmitLAMProbe"))
            {
                using (MessageItem messageItem = MessageItem.Create(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox)))
                {
                    messageItem.ClassName = mapiMailDefinition.MessageClass;
                    if (setLamNotificationId)
                    {
                        messageItem[MessageItemSchema.MapiSubmitLamNotificationId] = lamNotificationId;
                        messageItem[MessageItemSchema.XLAMNotificationId]          = lamNotificationId;
                    }
                    messageItem[MessageItemSchema.DoNotDeliver] = (mapiMailDefinition.DoNotDeliver ? "Supress" : "Deliver");
                    if (mapiMailDefinition.DropMessageInHub)
                    {
                        messageItem[MessageItemSchema.DropMessageInHub] = "FrontEnd-CAT-250";
                        messageItem[MessageItemSchema.SystemProbeDrop]  = "OnEndOfHeaders";
                    }
                    messageItem.Subject = mapiMailDefinition.MessageSubject;
                    BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextPlain);
                    using (TextWriter textWriter = messageItem.Body.OpenTextWriter(configuration))
                    {
                        textWriter.Write(mapiMailDefinition.MessageBody);
                    }
                    messageItem.Recipients.Add(new Participant(mapiMailDefinition.RecipientEmailAddress, mapiMailDefinition.RecipientEmailAddress, "SMTP"), RecipientItemType.To);
                    if (mapiMailDefinition.DeleteAfterSubmit)
                    {
                        messageItem.SendWithoutSavingMessage();
                    }
                    else
                    {
                        messageItem.Send();
                    }
                    if (returnOutParameters)
                    {
                        senderMbxGuid = mailboxSession.MailboxGuid;
                        messageItem.Load(new PropertyDefinition[]
                        {
                            StoreObjectSchema.EntryId,
                            ItemSchema.InternetMessageId
                        });
                        object obj      = messageItem.TryGetProperty(StoreObjectSchema.EntryId);
                        byte[] entryId2 = (byte[])obj;
                        entryId = MapiMessageSubmitter.EntryIdString(entryId2);
                        object obj2 = messageItem.TryGetProperty(ItemSchema.InternetMessageId);
                        internetMessageId = obj2.ToString();
                    }
                }
            }
        }
        // Token: 0x0600144C RID: 5196 RVA: 0x0007503C File Offset: 0x0007323C
        private static Stream OpenBodyWriteStream(Item item, Microsoft.Exchange.Data.Storage.BodyFormat bodyFormat)
        {
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(bodyFormat, "utf-8");

            return(item.Body.OpenWriteStream(configuration));
        }
        // Token: 0x06002FC9 RID: 12233 RVA: 0x0011611C File Offset: 0x0011431C
        internal static bool SetBody(Item item, string body, Markup markup, StoreObjectType storeObjectType, UserContext userContext)
        {
            bool flag = false;

            switch (markup)
            {
            case Markup.Html:
            {
                string                 targetCharsetName;
                BodyCharsetFlags       bodyCharsetOptions     = BodyConversionUtilities.GetBodyCharsetOptions(userContext, out targetCharsetName);
                BodyFormat             targetFormat           = (storeObjectType != StoreObjectType.CalendarItem && storeObjectType != StoreObjectType.MeetingMessage) ? BodyFormat.TextHtml : BodyFormat.ApplicationRtf;
                BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.TextHtml);
                bodyWriteConfiguration.SetTargetFormat(targetFormat, targetCharsetName, bodyCharsetOptions);
                OwaSafeHtmlInboundCallbacks owaSafeHtmlInboundCallbacks = null;
                owaSafeHtmlInboundCallbacks = new OwaSafeHtmlInboundCallbacks(item, userContext);
                bodyWriteConfiguration.SetHtmlOptions(HtmlStreamingFlags.None, owaSafeHtmlInboundCallbacks);
                try
                {
                    Body body2 = item.Body;
                    if (userContext.IsIrmEnabled && Utilities.IsIrmDecrypted(item))
                    {
                        body2 = ((RightsManagedMessageItem)item).ProtectedBody;
                    }
                    using (TextWriter textWriter = body2.OpenTextWriter(bodyWriteConfiguration))
                    {
                        textWriter.Write(body);
                    }
                }
                catch (InvalidCharsetException innerException)
                {
                    throw new OwaEventHandlerException(LocalizedStrings.GetNonEncoded(1825027020), LocalizedStrings.GetNonEncoded(1825027020), innerException);
                }
                catch (TextConvertersException innerException2)
                {
                    throw new OwaEventHandlerException(LocalizedStrings.GetNonEncoded(1825027020), LocalizedStrings.GetNonEncoded(1825027020), innerException2);
                }
                Utilities.MakeModifiedCalendarItemOccurrence(item);
                bool flag2 = false;
                if (owaSafeHtmlInboundCallbacks != null)
                {
                    flag2 = owaSafeHtmlInboundCallbacks.AttachmentNeedsSave();
                }
                if (flag2 && !Utilities.IsClearSigned(item))
                {
                    flag = AttachmentUtility.ApplyAttachmentsUpdates(item, owaSafeHtmlInboundCallbacks);
                    item.Load();
                }
                break;
            }

            case Markup.PlainText:
                ItemUtility.SetItemBody(item, BodyFormat.TextPlain, body);
                flag = AttachmentUtility.PromoteInlineAttachments(item);
                if (flag)
                {
                    item.Load();
                }
                break;
            }
            return(flag);
        }
Beispiel #16
0
        // Token: 0x06000C14 RID: 3092 RVA: 0x0004EBBC File Offset: 0x0004CDBC
        private void SendExpiryOrUpdateMessage(MessageItem initiationMessage, MailboxSession session, string decisionMakerAddress, ApprovalStatus status, ExDateTime handledTime)
        {
            if (status != ApprovalStatus.Expired && status != ApprovalStatus.Approved && status != ApprovalStatus.Rejected)
            {
                throw new ArgumentException("Unexpected status");
            }
            StoreObjectId defaultFolderId = session.GetDefaultFolderId(DefaultFolderType.Outbox);

            using (MessageItem messageItem = MessageItem.Create(session, defaultFolderId))
            {
                messageItem.ClassName = "IPM.Note.Microsoft.Approval.Request.Recall";
                string valueOrDefault = initiationMessage.GetValueOrDefault <string>(MessageItemSchema.ApprovalAllowedDecisionMakers);
                if (string.IsNullOrEmpty(valueOrDefault))
                {
                    ApprovalAssistant.GeneralTracer.TraceError((long)this.GetHashCode(), "No list of decisionmakers. No updates");
                }
                else
                {
                    string valueOrDefault2 = initiationMessage.GetValueOrDefault <string>(MessageItemSchema.ApprovalRequestMessageId);
                    if (string.IsNullOrEmpty(valueOrDefault2))
                    {
                        ApprovalAssistant.GeneralTracer.TraceError((long)this.GetHashCode(), "The approval request message id is not found.");
                    }
                    else
                    {
                        Participant valueOrDefault3 = initiationMessage.GetValueOrDefault <Participant>(MessageItemSchema.ReceivedBy);
                        if (valueOrDefault3 == null)
                        {
                            ApprovalAssistant.GeneralTracer.TraceError((long)this.GetHashCode(), "Cannot get the arbitration mailbox information.");
                        }
                        else
                        {
                            messageItem.Sender = valueOrDefault3;
                            RoutingAddress[] routingAddresses;
                            if (!ApprovalUtils.TryGetDecisionMakers(valueOrDefault, out routingAddresses))
                            {
                                ApprovalAssistant.GeneralTracer.TraceError((long)this.GetHashCode(), "initiation message has invalid decision makers.");
                            }
                            else
                            {
                                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, session.GetADSessionSettings(), 555, "SendExpiryOrUpdateMessage", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\Approval\\ApprovalAssistant.cs");
                                string            text;
                                RoutingAddress[]  array = this.FilterByServerVersionAndLookupDisplayName(routingAddresses, tenantOrRootOrgRecipientSession, decisionMakerAddress, out text);
                                if (array.Length == 0)
                                {
                                    ApprovalAssistant.GeneralTracer.TraceDebug((long)this.GetHashCode(), "There is no E14 or later moderator in the list.");
                                }
                                else
                                {
                                    foreach (RoutingAddress address in array)
                                    {
                                        Participant participant = new Participant(string.Empty, (string)address, "SMTP");
                                        messageItem.Recipients.Add(participant, RecipientItemType.To);
                                    }
                                    messageItem[MessageItemSchema.ApprovalDecisionTime]          = handledTime;
                                    messageItem[MessageItemSchema.ApprovalRequestMessageId]      = valueOrDefault2;
                                    messageItem[MessageItemSchema.IsNonDeliveryReceiptRequested] = false;
                                    messageItem[MessageItemSchema.IsDeliveryReceiptRequested]    = false;
                                    byte[] conversationIndex = initiationMessage.ConversationIndex;
                                    messageItem.ConversationIndex             = ConversationIndex.CreateFromParent(conversationIndex).ToByteArray();
                                    messageItem[ItemSchema.NormalizedSubject] = initiationMessage.ConversationTopic;
                                    DsnHumanReadableWriter defaultDsnHumanReadableWriter = DsnHumanReadableWriter.DefaultDsnHumanReadableWriter;
                                    ApprovalInformation    approvalInformation;
                                    if (status != ApprovalStatus.Expired)
                                    {
                                        if (string.IsNullOrEmpty(text))
                                        {
                                            text = decisionMakerAddress;
                                        }
                                        messageItem[MessageItemSchema.ApprovalDecision]      = ((status == ApprovalStatus.Approved) ? 1 : 2);
                                        messageItem[MessageItemSchema.ApprovalDecisionMaker] = text;
                                        bool?decision = new bool?(status == ApprovalStatus.Approved);
                                        approvalInformation = defaultDsnHumanReadableWriter.GetDecisionUpdateInformation(initiationMessage.Subject, text, decision, new ExDateTime?(handledTime));
                                    }
                                    else
                                    {
                                        messageItem[MessageItemSchema.ApprovalDecision] = 0;
                                        approvalInformation = defaultDsnHumanReadableWriter.GetApprovalRequestExpiryInformation(initiationMessage.Subject);
                                    }
                                    messageItem.Subject = approvalInformation.Subject;
                                    BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, approvalInformation.MessageCharset.Name);
                                    using (Stream stream = messageItem.Body.OpenWriteStream(configuration))
                                    {
                                        defaultDsnHumanReadableWriter.WriteHtmlModerationBody(stream, approvalInformation);
                                        stream.Flush();
                                    }
                                    messageItem.SendWithoutSavingMessage();
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #17
0
        private static Stream OpenBodyWriteStream(Item item, BodyFormat bodyFormat)
        {
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(bodyFormat, "utf-8");

            return(item.Body.OpenWriteStream(configuration));
        }
        // Token: 0x06000038 RID: 56 RVA: 0x00003BFC File Offset: 0x00001DFC
        private void SendModeratorExpiryNotification(MessageItem messageItem, ApprovalInformation.ApprovalNotificationType notificationType)
        {
            ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Entering SendModeratorExpiryNotification");
            if (!this.ShouldSendNotification(messageItem))
            {
                return;
            }
            string valueOrDefault = messageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalAllowedDecisionMakers);

            RoutingAddress[] collection;
            if (!ApprovalUtils.TryGetDecisionMakers(valueOrDefault, out collection))
            {
                return;
            }
            MailboxSession mailboxSession = (MailboxSession)messageItem.Session;

            messageItem.Load(ModeratedDLApplication.NotificationPropertiesFromInitMessage);
            ICollection <string> moderatedRecipients = this.GetModeratedRecipients(messageItem, false);
            string valueOrDefault2 = messageItem.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty);
            int    value           = messageItem.GetValueAsNullable <int>(StoreObjectSchema.RetentionPeriod) ?? 2;
            Dictionary <CultureInfo, List <RoutingAddress> > dictionary = null;
            IRecipientSession      tenantOrRootOrgRecipientSession      = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.FullyConsistent, mailboxSession.GetADSessionSettings(), 587, "SendModeratorExpiryNotification", "f:\\15.00.1497\\sources\\dev\\Approval\\src\\Applications\\ModeratedDLApplication\\ModeratedDLApplication.cs");
            DsnHumanReadableWriter defaultDsnHumanReadableWriter        = DsnHumanReadableWriter.DefaultDsnHumanReadableWriter;
            StoreObjectId          defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox);

            if (ClientCultures.IsCultureSupportedForDsn(CultureInfo.CurrentCulture))
            {
                this.defaultFallBackCulture = CultureInfo.CurrentCulture;
            }
            else
            {
                this.defaultFallBackCulture = CultureInfo.GetCultureInfo("en-US");
            }
            if (ApprovalProcessor.TryGetCulturesForDecisionMakers(new List <RoutingAddress>(collection), tenantOrRootOrgRecipientSession, this.defaultFallBackCulture, out dictionary))
            {
                foreach (CultureInfo cultureInfo in dictionary.Keys)
                {
                    IList <RoutingAddress> list = dictionary[cultureInfo];
                    using (MessageItem messageItem2 = MessageItem.Create(mailboxSession, defaultFolderId))
                    {
                        ApprovalInformation approvalInformation = null;
                        string text;
                        this.AttachOriginalMessageToNotification(messageItem, messageItem2, out text);
                        if (string.IsNullOrEmpty(text))
                        {
                            RoutingAddress routingAddress;
                            if (!this.TryGetOriginalSender(messageItem, out routingAddress))
                            {
                                break;
                            }
                            text = routingAddress.ToString();
                        }
                        approvalInformation  = defaultDsnHumanReadableWriter.GetMessageInModerationModeratorExpiredInformation(notificationType, messageItem.Subject, moderatedRecipients, text, new int?(value), cultureInfo.Name, this.defaultFallBackCulture);
                        messageItem2.Subject = approvalInformation.Subject;
                        BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, approvalInformation.MessageCharset.Name);
                        using (Stream stream = messageItem2.Body.OpenWriteStream(configuration))
                        {
                            defaultDsnHumanReadableWriter.WriteHtmlModerationBody(stream, approvalInformation);
                        }
                        this.StampCommonNotificationProperties(messageItem2, messageItem, list, valueOrDefault2, approvalInformation.Culture);
                        messageItem2.ClassName = "IPM.Note.Microsoft.Approval.Reply.Reject";
                        messageItem2.SendWithoutSavingMessage();
                        ModeratedDLApplication.diag.TraceDebug <int, string>((long)this.GetHashCode(), "Expiry Notification sent for {0} decision makers, original message id '{1}'", list.Count, valueOrDefault2);
                    }
                }
            }
        }
        // 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();
                    }
                }
            }
        }