Example #1
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: 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);
                    }
                }
            }
        }