private void SendApprovalRequest(ApprovalRequestWriter writer, ICollection <RoutingAddress> p1DecisionMakers, CultureInfo cultureInfo, string messageId, byte[] corelationBlob)
        {
            IList <RoutingAddress> decisionMakers = this.initiationMessage.DecisionMakers;

            byte[] conversationIndex = this.initiationMessageItem.ConversationIndex;
            (string)this.initiationMessage.Requestor;
            using (MessageItemApprovalRequest messageItemApprovalRequest = this.requestCreate(this.mbxTransportMailItem))
            {
                messageItemApprovalRequest.SetSender(this.approvalRequestSender);
                foreach (RoutingAddress routingAddress in decisionMakers)
                {
                    bool flag = p1DecisionMakers == null || p1DecisionMakers.Contains(routingAddress);
                    messageItemApprovalRequest.AddRecipient(routingAddress, flag);
                    InitiationProcessor.diag.TraceDebug <RoutingAddress, bool>(0L, "Added recipient '{0}' with promote to P1={1}.", routingAddress, flag);
                }
                CultureInfo cultureInfo2;
                if (!writer.WriteSubjectAndBody(messageItemApprovalRequest, cultureInfo, out cultureInfo2))
                {
                    InitiationProcessor.diag.TraceError <ApprovalRequestWriter>(0L, "Approval request body cannot be written with writer {0}", writer);
                }
                messageItemApprovalRequest.ApprovalRequestor = this.initiationMessage.Requestor;
                messageItemApprovalRequest.MessageItem[ItemSchema.NormalizedSubject] = this.initiationMessageItem.ConversationTopic;
                messageItemApprovalRequest.MessageItem.Importance = this.initiationMessageItem.Importance;
                messageItemApprovalRequest.MessageItem.References = InitiationProcessor.ConstructApprovalRequestReferences(this.initiationMessageItem);
                ConversationIndex o = ConversationIndex.CreateFromParent(conversationIndex);
                if (!ConversationIndex.Empty.Equals(o))
                {
                    messageItemApprovalRequest.MessageItem.ConversationIndex = o.ToByteArray();
                }
                if (cultureInfo2 != null)
                {
                    InitiationProcessor.diag.TraceDebug <CultureInfo>(0L, "Approval request written in {0}", cultureInfo2);
                    messageItemApprovalRequest.MessageItem[MessageItemSchema.MessageLocaleId] = cultureInfo2.LCID;
                }
                foreach (Attachment attachment in this.initiationMessage.EmailMessage.Attachments)
                {
                    messageItemApprovalRequest.AddAttachment(attachment, this.mbxTransportMailItem.ADRecipientCache.ADSession);
                }
                if (this.initiationMessage.EmailMessage.RootPart != null && this.initiationMessage.EmailMessage.RootPart.Headers != null)
                {
                    HeaderList headers = this.initiationMessage.EmailMessage.RootPart.Headers;
                    Header[]   array   = headers.FindAll("X-MS-Exchange-Inbox-Rules-Loop");
                    if (array != null && array.Length > 0)
                    {
                        string[] array2 = new string[array.Length];
                        for (int i = 0; i < array.Length; i++)
                        {
                            array2[i] = array[i].Value;
                        }
                        messageItemApprovalRequest.MessageItem.SafeSetProperty(MessageItemSchema.XLoop, array2);
                    }
                }
                InitiationProcessor.AddVotingToApprovalRequest(messageItemApprovalRequest, this.initiationMessage.VotingActions, cultureInfo2);
                messageItemApprovalRequest.Send(messageId, corelationBlob, this.mbxTransportMailItem);
            }
        }
Exemple #2
0
 private void HandleResults(ApprovalEngine.ApprovalProcessResults resultInfo, MessageItem messageItem, MbxTransportMailItem rmi, MailRecipient recipient)
 {
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationMessageOk)
     {
         messageItem.VotingInfo.MessageCorrelationBlob              = resultInfo.ApprovalTrackingBlob;
         messageItem[MessageItemSchema.ApprovalRequestMessageId]    = resultInfo.ApprovalRequestMessageId;
         messageItem[MessageItemSchema.ApprovalDecisionMakersNdred] = NdrOofHandler.FormatNdrOofProperty(resultInfo.TotalDecisionMakers, 0, 0);
         messageItem[MessageItemSchema.ApprovalStatus]              = ApprovalStatus.Unhandled;
         this.perfCounter.InitiationMessages.Increment();
         return;
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.UnauthorizedMessage)
     {
         throw new SmtpResponseException(AckReason.ApprovalUnAuthorizedMessage);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationMessageDuplicate)
     {
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalDuplicateInitiation, base.Name);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.DecisionMarked)
     {
         this.perfCounter.DecisionUsed.Increment();
         this.perfCounter.DecisionMessages.Increment();
         this.perfCounter.DecisionInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds);
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalDecisionSuccsess, base.Name);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationNotFoundForDecision || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.DecisionAlreadyMade)
     {
         byte[] conversationIndex = messageItem.ConversationIndex;
         string threadIndex       = Convert.ToBase64String(ConversationIndex.CreateFromParent(conversationIndex).ToByteArray());
         this.SendNotifications(recipient.Email, (RoutingAddress)rmi.Message.Sender.SmtpAddress, rmi, threadIndex, messageItem.ConversationTopic, resultInfo.ExistingDecisionMakerAddress, resultInfo.ExistingApprovalStatus, resultInfo.ExistingDecisionTime);
         this.perfCounter.DecisionMessages.Increment();
         this.perfCounter.DecisionInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds);
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalDecisionSuccsess, base.Name);
     }
     if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdated || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdateSkipped || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationNotFoundForNdrOrOof || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofInvalid)
     {
         this.perfCounter.TotalNdrOofHandled.Increment();
         if (resultInfo.ProcessResults != ApprovalEngine.ProcessResult.NdrOrOofInvalid)
         {
             this.perfCounter.TotalSearchesForInitiationBasedOnNdrAndOof.Increment();
             this.perfCounter.NdrOofInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds);
         }
         if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdated)
         {
             this.perfCounter.TotalNdrOofUpdated.Increment();
         }
         recipient.DsnRequested = DsnRequestedFlags.Never;
         throw new SmtpResponseException(AckReason.ApprovalNdrOofUpdateSuccess, base.Name);
     }
     throw new SmtpResponseException(AckReason.ApprovalInvalidMessage);
 }
 // Token: 0x0600003C RID: 60 RVA: 0x00004230 File Offset: 0x00002430
 private void StampCommonNotificationProperties(MessageItem notificationItem, MessageItem initMessageItem, ICollection <RoutingAddress> notificationReceivers, string originalMessageId, CultureInfo cultureInfo)
 {
     foreach (RoutingAddress routingAddress in notificationReceivers)
     {
         Participant participant = new Participant(string.Empty, routingAddress.ToString(), ProxyAddressPrefix.Smtp.ToString());
         notificationItem.Recipients.Add(participant);
     }
     notificationItem.Sender = initMessageItem.Sender;
     notificationItem[MessageItemSchema.IsNonDeliveryReceiptRequested] = false;
     notificationItem[MessageItemSchema.IsDeliveryReceiptRequested]    = false;
     notificationItem[MessageItemSchema.MessageLocaleId] = cultureInfo.LCID;
     byte[] conversationIndex = initMessageItem.ConversationIndex;
     notificationItem.ConversationIndex             = ConversationIndex.CreateFromParent(conversationIndex).ToByteArray();
     notificationItem[ItemSchema.NormalizedSubject] = initMessageItem.ConversationTopic;
     if (!string.IsNullOrEmpty(originalMessageId))
     {
         notificationItem[ItemSchema.InReplyTo] = originalMessageId;
     }
 }
Exemple #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();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        private static bool FixupMeetingMessage(IXSOFactory xsoFactory, IMailboxSession session, AggregationByItemClassReferencesSubjectProcessor.PropertyDefinitionListConstructorDelegate propertyDefinitionListConstructorDelegate, ICorePropertyBag corePropertyBag, ref ConversationIndex newIndex, ref ConversationIndex.FixupStage stage, out IStorePropertyBag parentItemPropertyBag)
        {
            corePropertyBag.Load(propertyDefinitionListConstructorDelegate(new PropertyDefinition[]
            {
                CalendarItemBaseSchema.GlobalObjectId,
                CalendarItemBaseSchema.CleanGlobalObjectId,
                CalendarItemBaseSchema.OwnerCriticalChangeTime,
                InternalSchema.AppointmentSequenceNumber
            }));
            byte[] array = corePropertyBag.TryGetProperty(CalendarItemBaseSchema.GlobalObjectId) as byte[];
            if (array == null)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            GlobalObjectId globalObjectId;
            GlobalObjectId globalObjectId3;

            try
            {
                globalObjectId  = new GlobalObjectId(array);
                globalObjectId3 = new GlobalObjectId(array);
            }
            catch (CorruptDataException)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            globalObjectId3.Date = ExDateTime.MinValue;
            string     valueOrDefault          = corePropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);
            bool       isRequest               = ObjectClass.IsMeetingRequest(valueOrDefault);
            object     fixupStage              = null;
            ExDateTime ownerCriticalChangeTime = corePropertyBag.GetValueOrDefault <ExDateTime>(CalendarItemBaseSchema.OwnerCriticalChangeTime, ExDateTime.MaxValue);
            int        sequenceNumber          = corePropertyBag.GetValueOrDefault <int>(InternalSchema.AppointmentSequenceNumber, -1);

            if (sequenceNumber == -1)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            parentItemPropertyBag = xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(session, AllItemsFolderHelper.SupportedSortBy.CleanGlobalObjectId, globalObjectId3.Bytes, null, delegate(QueryResult queryResult)
            {
                IStorePropertyBag result = null;
                bool flag2 = false;
                while (!flag2)
                {
                    IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(50);
                    flag2 = (propertyBags.Length == 0);
                    IStorePropertyBag[] array2 = propertyBags;
                    int i = 0;
                    while (i < array2.Length)
                    {
                        IStorePropertyBag storePropertyBag = array2[i];
                        VersionedId versionedId            = (VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id);
                        byte[] array3 = (storePropertyBag.TryGetProperty(CalendarItemBaseSchema.GlobalObjectId) as byte[]) ?? (storePropertyBag.TryGetProperty(CalendarItemBaseSchema.CleanGlobalObjectId) as byte[]);
                        if (array3 != null && GlobalObjectId.CompareCleanGlobalObjectIds(array3, globalObjectId.Bytes))
                        {
                            GlobalObjectId globalObjectId2 = new GlobalObjectId(array3);
                            if (versionedId.ObjectId.ObjectType == StoreObjectType.MeetingRequest)
                            {
                                ConversationId conversationId = storePropertyBag.TryGetProperty(ConversationItemSchema.ConversationId) as ConversationId;
                                if (conversationId != null)
                                {
                                    if (isRequest)
                                    {
                                        fixupStage = ConversationIndex.FixupStage.M1;
                                        return(storePropertyBag);
                                    }
                                    if (AggregationByItemClassReferencesSubjectProcessor.IsMatchForMeetingResponse(globalObjectId, ownerCriticalChangeTime, sequenceNumber, storePropertyBag))
                                    {
                                        if (globalObjectId.Date != ExDateTime.MinValue && globalObjectId.Date == globalObjectId2.Date)
                                        {
                                            fixupStage = ConversationIndex.FixupStage.M3;
                                            return(storePropertyBag);
                                        }
                                        if (globalObjectId.Date == ExDateTime.MinValue)
                                        {
                                            fixupStage = ConversationIndex.FixupStage.M2;
                                            return(storePropertyBag);
                                        }
                                        fixupStage = ConversationIndex.FixupStage.M4;
                                        result     = storePropertyBag;
                                    }
                                }
                            }
                            i++;
                            continue;
                        }
                        return(result);
                    }
                }
                return(result);
            }, propertyDefinitionListConstructorDelegate(new PropertyDefinition[]
            {
                CalendarItemBaseSchema.GlobalObjectId,
                CalendarItemBaseSchema.CleanGlobalObjectId,
                InternalSchema.AppointmentSequenceNumber,
                CalendarItemBaseSchema.OwnerCriticalChangeTime,
                ConversationItemSchema.ConversationId
            }));
            if (parentItemPropertyBag == null)
            {
                return(false);
            }
            ConversationIndex conversationIndex;

            if (!ConversationIndex.TryCreate(parentItemPropertyBag.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex))
            {
                return(false);
            }
            bool?flag = parentItemPropertyBag.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;

            stage = ((flag == null || !flag.Value) ? ConversationIndex.FixupStage.L1 : ((ConversationIndex.FixupStage)fixupStage));
            if (isRequest)
            {
                byte[]            valueOrDefault2 = corePropertyBag.GetValueOrDefault <byte[]>(ItemSchema.ConversationIndex);
                ConversationIndex conversationIndex2;
                if (valueOrDefault2 != null && ConversationIndex.TryCreate(valueOrDefault2, out conversationIndex2))
                {
                    newIndex = conversationIndex.UpdateHeader(conversationIndex2.Components[0]);
                }
                else
                {
                    newIndex = ConversationIndex.Create(conversationIndex.Guid);
                }
            }
            else
            {
                newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes);
            }
            return(true);
        }
Exemple #6
0
        private bool CalculateBasedOnReferenceMessage(ICorePropertyBag message, IStorePropertyBag referenceItem, out ConversationIndex.FixupStage stage, out ConversationIndex newIndex)
        {
            bool result = true;

            newIndex = ConversationIndex.Empty;
            stage    = ConversationIndex.FixupStage.Unknown;
            if (this.indexTrackingEx != null)
            {
                string text = referenceItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                if (text != null)
                {
                    this.indexTrackingEx.Trace("S1", text);
                }
            }
            string            text2 = message.TryGetProperty(ItemSchema.NormalizedSubject) as string;
            ConversationIndex conversationIndex;
            bool flag = ConversationIndex.TryCreate(referenceItem.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex);
            ConversationIndex conversationIndex2;
            bool flag2 = ConversationIndex.TryCreate(message.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex2);
            bool?flag3 = referenceItem.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;
            bool flag4 = flag3 == null || !flag3.Value;

            if (flag)
            {
                string value = referenceItem.TryGetProperty(ItemSchema.ConversationTopic) as string;
                if (string.IsNullOrEmpty(value) || (!string.IsNullOrEmpty(text2) && text2.EndsWith(value, StringComparison.OrdinalIgnoreCase)))
                {
                    string text3 = message.TryGetProperty(ItemSchema.InReplyTo) as string;
                    string text4 = referenceItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                    if (!string.IsNullOrEmpty(text3) && !string.IsNullOrEmpty(text4) && string.Compare(text3, text4, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (conversationIndex.IsParentOf(conversationIndex2))
                        {
                            newIndex = conversationIndex2;
                            stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H1);
                            result   = false;
                        }
                        else
                        {
                            ExDateTime?valueAsNullable = message.GetValueAsNullable <ExDateTime>(ItemSchema.SentTime);
                            if (valueAsNullable != null)
                            {
                                newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes, valueAsNullable.Value);
                            }
                            else
                            {
                                newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes);
                            }
                            stage = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H2);
                        }
                    }
                    else if (flag2)
                    {
                        if (conversationIndex.IsAncestorOf(conversationIndex2))
                        {
                            newIndex = conversationIndex2;
                            stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H1);
                            result   = false;
                        }
                        else
                        {
                            newIndex = conversationIndex2.UpdateGuid(conversationIndex.Guid);
                            newIndex = newIndex.UpdateHeader(conversationIndex.Header);
                            stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H10);
                        }
                    }
                    else
                    {
                        newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes);
                        stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H2);
                    }
                }
                else
                {
                    newIndex = ConversationIndex.CreateNew();
                    stage    = ConversationIndex.FixupStage.H3;
                }
            }
            return(result);
        }