Esempio n. 1
0
        public ApprovalEngine.ApprovalProcessResults Process()
        {
            MailboxSession session = (MailboxSession)this.messageItem.Session;
            string         text;
            string         approvalRequestMessageId;

            if (!this.TryGetInitiationAndApprovalRequestMessageId(out text, out approvalRequestMessageId))
            {
                NdrOofHandler.diag.TraceDebug((long)this.GetHashCode(), "Ignoring NDR/OOF. Cannot get initiation/approval request message id's");
                return(ApprovalEngine.ApprovalProcessResults.NdrOofInvalid);
            }
            long          num;
            StoreObjectId storeObjectId = NdrOofHandler.FindInitiationMessage(session, text, approvalRequestMessageId, out num);

            NdrOofHandler.diag.TraceDebug <long>((long)this.GetHashCode(), "Time searching for initiation = {0} ms", num);
            if (storeObjectId == null)
            {
                NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Initiation message not found, ignoring NDR/OOF, messageId={0}", text);
                return(new ApprovalEngine.ApprovalProcessResults(ApprovalEngine.ProcessResult.InitiationNotFoundForNdrOrOof, num));
            }
            if (!this.WriteToInitiationMessage(session, storeObjectId, text))
            {
                NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Initiation message cannot be updated with NDR/OOF, messageId={0}", text);
                return(new ApprovalEngine.ApprovalProcessResults(ApprovalEngine.ProcessResult.NdrOrOofUpdateSkipped, num));
            }
            return(new ApprovalEngine.ApprovalProcessResults(ApprovalEngine.ProcessResult.NdrOrOofUpdated, num));
        }
Esempio n. 2
0
 public static bool TryCreate(MessageItem messageItem, out NdrOofHandler ndrOofHandler)
 {
     ndrOofHandler = null;
     if (!NdrOofHandler.IsNdrOrOof(messageItem))
     {
         return(false);
     }
     ndrOofHandler = new NdrOofHandler(messageItem);
     return(true);
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
        public ApprovalEngine.ApprovalProcessResults ProcessMessage()
        {
            if (!MultilevelAuth.IsInternalMail(this.message))
            {
                return(ApprovalEngine.ApprovalProcessResults.Invalid);
            }
            DecisionHandler decisionHandler = null;

            ApprovalEngine.ApprovalProcessResults result;
            try
            {
                InitiationMessage initiationMessage;
                NdrOofHandler     ndrOofHandler;
                if (InitiationMessage.TryCreate(this.message, out initiationMessage))
                {
                    result = this.HandleInitiationMessage(initiationMessage);
                }
                else if (DecisionHandler.TryCreate(this.messageItem, this.sender.ToString(), this.mbxTransportMailItem.OrganizationId, out decisionHandler))
                {
                    ApprovalEngine.ApprovalProcessResults approvalProcessResults = decisionHandler.Process();
                    result = approvalProcessResults;
                }
                else if (NdrOofHandler.TryCreate(this.messageItem, out ndrOofHandler))
                {
                    result = ndrOofHandler.Process();
                }
                else
                {
                    result = ApprovalEngine.ApprovalProcessResults.Invalid;
                }
            }
            finally
            {
                if (decisionHandler != null)
                {
                    decisionHandler.Dispose();
                }
            }
            return(result);
        }
Esempio n. 5
0
        private bool WriteToInitiationMessage(MailboxSession session, StoreObjectId storeId, string initMessageId)
        {
            ConflictResolutionResult conflictResolutionResult = null;

            try
            {
                for (int i = 0; i < 5; i++)
                {
                    using (MessageItem messageItem = MessageItem.Bind(session, storeId, NdrOofHandler.PropertiesNeededToUpdateInitiation))
                    {
                        messageItem.OpenAsReadWrite();
                        string         ndrOofValue     = (string)messageItem[MessageItemSchema.ApprovalDecisionMakersNdred];
                        ApprovalStatus?valueAsNullable = messageItem.GetValueAsNullable <ApprovalStatus>(MessageItemSchema.ApprovalStatus);
                        if (valueAsNullable == null)
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Invalid approval status property in initation message {0}. Ignored", initMessageId);
                            return(false);
                        }
                        if ((valueAsNullable & (ApprovalStatus.Approved | ApprovalStatus.Rejected)) != (ApprovalStatus)0)
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "There is already a decision for {0}, there is no need to handle NDR or OOF", initMessageId);
                            return(false);
                        }
                        int num;
                        int num2;
                        int num3;
                        if (!NdrOofHandler.TryParseNdrOofProperty(ndrOofValue, out num, out num2, out num3))
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Invalid ndr/oof property in initation message {0}. Ignored", initMessageId);
                            return(false);
                        }
                        int num4;
                        int num5;
                        this.GetNdrOrOofCountInMessage(out num4, out num5);
                        num2 += num4;
                        num3 += num5;
                        messageItem[MessageItemSchema.ApprovalDecisionMakersNdred] = NdrOofHandler.FormatNdrOofProperty(num, num2, num3);
                        if (num3 + num2 == num)
                        {
                            if (num3 == 0)
                            {
                                messageItem[MessageItemSchema.ApprovalStatus] = (valueAsNullable.Value | ApprovalStatus.Ndred);
                            }
                            else
                            {
                                messageItem[MessageItemSchema.ApprovalStatus] = (valueAsNullable.Value | ApprovalStatus.Oofed);
                            }
                        }
                        conflictResolutionResult = messageItem.Save(SaveMode.ResolveConflicts);
                        if (SaveResult.IrresolvableConflict != conflictResolutionResult.SaveStatus)
                        {
                            NdrOofHandler.diag.TraceDebug <string>((long)this.GetHashCode(), "Saved initiation message '{0}' successfully.", initMessageId);
                            return(true);
                        }
                        NdrOofHandler.diag.TraceDebug <string, int, SaveResult>((long)this.GetHashCode(), "Saving message: '{0}' try {1}, resulted in an update conflict ({2}).", initMessageId, i, conflictResolutionResult.SaveStatus);
                    }
                }
            }
            catch (ObjectNotFoundException arg)
            {
                NdrOofHandler.diag.TraceDebug <string, ObjectNotFoundException>((long)this.GetHashCode(), "Initiation Message '{0}' is no longer there {1}", initMessageId, arg);
                return(false);
            }
            NdrOofHandler.diag.TraceDebug <string, SaveResult>((long)this.GetHashCode(), "Saving message failed after all retries. Init MessageId={0}, Save status={1}", initMessageId, conflictResolutionResult.SaveStatus);
            return(false);
        }