Example #1
0
        public static ApprovalRequestUpdater.Result TryUpdateExistingApprovalRequest(MessageItem updateMessage)
        {
            updateMessage.Load(ApprovalRequestUpdater.ApprovalRequestUpdateProperties);
            int?       valueAsNullable  = updateMessage.GetValueAsNullable <int>(MessageItemSchema.ApprovalDecision);
            string     valueOrDefault   = updateMessage.GetValueOrDefault <string>(MessageItemSchema.ApprovalDecisionMaker);
            string     valueOrDefault2  = updateMessage.GetValueOrDefault <string>(MessageItemSchema.ApprovalRequestMessageId);
            ExDateTime?valueAsNullable2 = updateMessage.GetValueAsNullable <ExDateTime>(MessageItemSchema.ApprovalDecisionTime);

            if (valueAsNullable == null)
            {
                ApprovalRequestUpdater.diag.TraceDebug(0L, "Invalid update becasue there's no decision.");
                return(ApprovalRequestUpdater.Result.InvalidUpdateMessage);
            }
            if (!ApprovalRequestUpdater.IsDecisionExpiry(valueAsNullable.Value) && string.IsNullOrEmpty(valueOrDefault))
            {
                ApprovalRequestUpdater.diag.TraceDebug(0L, "Invalid update becasue there's no decisionMaker");
                return(ApprovalRequestUpdater.Result.InvalidUpdateMessage);
            }
            if (string.IsNullOrEmpty(valueOrDefault2))
            {
                ApprovalRequestUpdater.diag.TraceDebug(0L, "Invalid update becasue there's no messageId");
                return(ApprovalRequestUpdater.Result.InvalidUpdateMessage);
            }
            if (valueAsNullable2 == null)
            {
                ApprovalRequestUpdater.diag.TraceDebug(0L, "Invalid update becasue there's no decisionTime");
                return(ApprovalRequestUpdater.Result.InvalidUpdateMessage);
            }
            return(ApprovalRequestUpdater.FindAndUpdateExistingApprovalRequest(updateMessage, valueAsNullable.Value, valueOrDefault, valueAsNullable2.Value, valueOrDefault2));
        }
Example #2
0
 private static bool VerifyAndUpdateApprovalRequest(MailboxSession session, Participant updateMessageSender, int decision, string decisionMaker, ExDateTime decisionTime, MessageItem approvalRequest)
 {
     if (!object.Equals("IPM.Note.Microsoft.Approval.Request", approvalRequest.ClassName))
     {
         ApprovalRequestUpdater.diag.TraceDebug(0L, "not a approval request, ignore.");
         return(false);
     }
     if (!Participant.HasSameEmail(updateMessageSender, approvalRequest.Sender))
     {
         ApprovalRequestUpdater.diag.TraceDebug(0L, "not the same sender, ignore.");
         return(false);
     }
     approvalRequest.OpenAsReadWrite();
     if (ApprovalRequestUpdater.IsDecisionExpiry(decision))
     {
         approvalRequest[MessageItemSchema.ExpiryTime] = decisionTime;
     }
     else
     {
         approvalRequest[MessageItemSchema.ApprovalDecision]      = decision;
         approvalRequest[MessageItemSchema.ApprovalDecisionMaker] = decisionMaker;
         approvalRequest[MessageItemSchema.ApprovalDecisionTime]  = decisionTime;
     }
     return(true);
 }
Example #3
0
        public void OnCreatedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            MailRecipient        mailRecipient        = storeDriverDeliveryEventArgsImpl.MailRecipient;
            DeliverableMailItem  mailItem             = storeDriverDeliveryEventArgsImpl.MailItem;
            MbxTransportMailItem mbxTransportMailItem = storeDriverDeliveryEventArgsImpl.MailItemDeliver.MbxTransportMailItem;
            MessageItem          messageItem          = storeDriverDeliveryEventArgsImpl.MessageItem;
            bool flag  = false;
            bool flag2 = ApprovalInitiation.IsArbitrationMailbox(mbxTransportMailItem.ADRecipientCache, mailRecipient.Email);

            if (!flag2 && string.Equals(messageItem.ClassName, "IPM.Note.Microsoft.Approval.Request.Recall", StringComparison.OrdinalIgnoreCase))
            {
                flag = true;
            }
            EmailMessage      message           = mailItem.Message;
            TestMessageConfig testMessageConfig = new TestMessageConfig(message);

            if (testMessageConfig.IsTestMessage && (testMessageConfig.LogTypes & LogTypesEnum.Arbitration) != LogTypesEnum.None)
            {
                EmailMessage emailMessage = ArbitrationMailboxReport.GenerateContentReport(new SmtpAddress(mailRecipient.Email.ToString()), testMessageConfig.ReportToAddress, messageItem.Session, flag2);
                if (emailMessage != null)
                {
                    ApprovalProcessingAgent.diag.TraceDebug(0L, "Submit arbitration mailbox content report message");
                    this.server.SubmitMessage(mbxTransportMailItem, emailMessage, mbxTransportMailItem.OrganizationId, mbxTransportMailItem.ExternalOrganizationId, false);
                }
                else
                {
                    ApprovalProcessingAgent.diag.TraceDebug(0L, "Failed to generate arbitration mailbox content report");
                }
                throw new SmtpResponseException(AckReason.ApprovalUpdateSuccess, base.Name);
            }
            if (!flag)
            {
                if (flag2)
                {
                    ApprovalEngine approvalEngineInstance            = ApprovalEngine.GetApprovalEngineInstance(message, (RoutingAddress)message.From.SmtpAddress, mailRecipient.Email, messageItem, mbxTransportMailItem, ApprovalProcessingAgent.MessageItemCreationDelegate);
                    ApprovalEngine.ApprovalProcessResults resultInfo = approvalEngineInstance.ProcessMessage();
                    this.HandleResults(resultInfo, messageItem, mbxTransportMailItem, mailRecipient);
                }
                return;
            }
            if (!MultilevelAuth.IsInternalMail(message))
            {
                return;
            }
            if (ApprovalRequestUpdater.Result.InvalidUpdateMessage == ApprovalRequestUpdater.TryUpdateExistingApprovalRequest(messageItem))
            {
                throw new SmtpResponseException(AckReason.ApprovalInvalidMessage);
            }
            throw new SmtpResponseException(AckReason.ApprovalUpdateSuccess, base.Name);
        }
Example #4
0
        private static ApprovalRequestUpdater.Result FindAndUpdateExistingApprovalRequest(MessageItem updateMessage, int decision, string decisionMaker, ExDateTime decisionTime, string messageId)
        {
            bool   updated = false;
            string local;
            string domain;

            if (!FindMessageUtils.TryParseMessageId(messageId, out local, out domain))
            {
                return(ApprovalRequestUpdater.Result.InvalidUpdateMessage);
            }
            ApprovalRequestUpdater.diag.TraceDebug <string>(0L, "Update approval request: messageid={0}", messageId);
            MessageStatus messageStatus = StorageExceptionHandler.RunUnderExceptionHandler(ApprovalRequestUpdater.MessageConverterInstance, delegate
            {
                MailboxSession mailboxSession = (MailboxSession)updateMessage.Session;
                StoreObjectId storeObjectId   = null;
                for (int i = 0; i < 25; i++)
                {
                    string internetMessageId  = ApprovalRequestWriter.FormatApprovalRequestMessageId(local, i, domain, false);
                    IStorePropertyBag[] array = AllItemsFolderHelper.FindItemsFromInternetId(mailboxSession, internetMessageId, new PropertyDefinition[]
                    {
                        ItemSchema.Id
                    });
                    if (array != null && array.Length > 0)
                    {
                        ApprovalRequestUpdater.diag.TraceDebug <int>(0L, "Found {0} to update, picking the first.", array.Length);
                        storeObjectId = ((VersionedId)array[0][ItemSchema.Id]).ObjectId;
                        break;
                    }
                }
                if (storeObjectId != null)
                {
                    using (MessageItem messageItem = MessageItem.Bind(mailboxSession, storeObjectId))
                    {
                        if (ApprovalRequestUpdater.VerifyAndUpdateApprovalRequest(mailboxSession, updateMessage.Sender, decision, decisionMaker, decisionTime, messageItem))
                        {
                            ConflictResolutionResult conflictResolutionResult = messageItem.Save(SaveMode.ResolveConflicts);
                            if (conflictResolutionResult.SaveStatus != SaveResult.Success)
                            {
                                ApprovalRequestUpdater.diag.TraceDebug <string, SaveResult>(0L, "Saving message: {0}, resulted in an update conflict ({1}). Ignored", messageId, conflictResolutionResult.SaveStatus);
                            }
                            AggregateOperationResult aggregateOperationResult = mailboxSession.Delete(DeleteItemFlags.MoveToDeletedItems, new StoreId[]
                            {
                                storeObjectId
                            });
                            if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
                            {
                                ApprovalRequestUpdater.diag.TraceDebug <string, OperationResult>(0L, "Delete message: {0}, resulted in failure {1} Ignored", messageId, aggregateOperationResult.OperationResult);
                            }
                            updated = true;
                        }
                    }
                }
            });

            if (!updated)
            {
                ApprovalRequestUpdater.diag.TraceDebug <string>(0L, "Couldn't find message: {0}, ignored", messageId);
                return(ApprovalRequestUpdater.Result.NotFound);
            }
            if (MessageStatus.Success != messageStatus)
            {
                ApprovalRequestUpdater.diag.TraceDebug <string, string>(0L, "Message ({0}) processing was not successful ({1}), ignoring..", messageId, (messageStatus.Exception == null) ? "NULL exception" : messageStatus.Exception.Message);
                return(ApprovalRequestUpdater.Result.SaveConflict);
            }
            return(ApprovalRequestUpdater.Result.UpdatedSucessfully);
        }