internal static EmailMessage GenerateDecisionNotTakenNotification(RoutingAddress from, RoutingAddress recipient, string subject, string threadIndex, string threadTopic, string decisionMaker, bool?decision, ExDateTime?decisionTime, Header acceptLanguageHeader, Header contentLanguageHeader, CultureInfo fallbackCulture)
        {
            if (from.Equals(RoutingAddress.NullReversePath) || recipient.Equals(RoutingAddress.NullReversePath) || !from.IsValid || !recipient.IsValid)
            {
                return(null);
            }
            DsnHumanReadableWriter dsnHumanReadableWriter      = Components.DsnGenerator.DsnHumanReadableWriter;
            ApprovalInformation    decisionConflictInformation = dsnHumanReadableWriter.GetDecisionConflictInformation(subject, decisionMaker, decision, decisionTime, acceptLanguageHeader, contentLanguageHeader, fallbackCulture);
            EmailMessage           emailMessage = EmailMessage.Create(BodyFormat.Html, false, decisionConflictInformation.MessageCharset.Name);

            emailMessage.From = new EmailRecipient(string.Empty, from.ToString());
            emailMessage.To.Add(new EmailRecipient(string.Empty, recipient.ToString()));
            emailMessage.Subject = decisionConflictInformation.Subject;
            using (Stream contentWriteStream = emailMessage.Body.GetContentWriteStream())
            {
                dsnHumanReadableWriter.WriteHtmlModerationBody(contentWriteStream, decisionConflictInformation);
                contentWriteStream.Flush();
            }
            Header header = Header.Create("X-MS-Exchange-Organization-SCL");

            header.Value = "-1";
            emailMessage.RootPart.Headers.AppendChild(header);
            Header header2 = (TextHeader)Header.Create("Thread-Index");

            header2.Value = threadIndex;
            emailMessage.RootPart.Headers.AppendChild(header2);
            Header header3 = (TextHeader)Header.Create("Thread-Topic");

            header3.Value = threadTopic;
            emailMessage.RootPart.Headers.AppendChild(header3);
            return(emailMessage);
        }
        // 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.");
            }
        }
        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);
            }
        }
예제 #4
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();
                                }
                            }
                        }
                    }
                }
            }
        }
        // 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();
                    }
                }
            }
        }
        // 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);
                    }
                }
            }
        }