private StoreId GetMessageStoreId(string internetId, IMailboxSession session)
        {
            if (string.IsNullOrEmpty(internetId))
            {
                return(null);
            }
            IStorePropertyBag[] array = AllItemsFolderHelper.FindItemsFromInternetId((MailboxSession)session, internetId, new StorePropertyDefinition[]
            {
                CoreItemSchema.Id
            });
            if (array == null || array.Length == 0)
            {
                return(null);
            }
            IStorePropertyBag storePropertyBag = array[0];

            if (storePropertyBag == null)
            {
                return(null);
            }
            VersionedId valueOrDefault = storePropertyBag.GetValueOrDefault <VersionedId>(CoreItemSchema.Id, null);

            if (valueOrDefault == null)
            {
                return(null);
            }
            return(valueOrDefault.ObjectId);
        }
Example #2
0
        private static StoreObjectId FindInitiationMessage(MailboxSession session, string initiationMessageId, string approvalRequestMessageId, out long messageSearchElapsedMilliseconds)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            IStorePropertyBag[] array  = AllItemsFolderHelper.FindItemsFromInternetId(session, initiationMessageId, NdrOofHandler.PropertiesNeededFromInitiationForFinding);
            StoreObjectId       result = null;

            if (array != null)
            {
                NdrOofHandler.diag.TraceDebug <int, string>(0L, "Found {0} initiation messages for this NDR/OOF. Init messageId={1}.", array.Length, initiationMessageId);
                for (int i = 0; i < array.Length; i++)
                {
                    string text = array[i].TryGetProperty(MessageItemSchema.ApprovalRequestMessageId) as string;
                    string value;
                    string text2;
                    if (!string.IsNullOrEmpty(text) && FindMessageUtils.TryParseMessageId(text, out value, out text2))
                    {
                        approvalRequestMessageId.StartsWith(value, StringComparison.Ordinal);
                        result = ((VersionedId)array[i][ItemSchema.Id]).ObjectId;
                        break;
                    }
                }
            }
            stopwatch.Stop();
            messageSearchElapsedMilliseconds = stopwatch.ElapsedMilliseconds;
            return(result);
        }
Example #3
0
        public void LoadMailboxMessage(string internetMessageId)
        {
            MailboxSession session = (MailboxSession)this.storeSession;

            try
            {
                this.context.BeginTrackLatency(LatencyComponent.StoreDriverDeliveryRpc);
                IEnumerable <IStorePropertyBag> source = AllItemsFolderHelper.FindItemsFromInternetId(session, internetMessageId, ItemQueryType.NoNotifications, new PropertyDefinition[]
                {
                    ItemSchema.Id
                });
                if (source.Count <IStorePropertyBag>() != 1)
                {
                    throw new UnexpectedMessageCountException(string.Format("The number of messages found was unexpected. Count: {0}", source.Count <IStorePropertyBag>()));
                }
                IStorePropertyBag storePropertyBag = source.First <IStorePropertyBag>();
                StoreObjectId     objectId         = ((VersionedId)storePropertyBag[ItemSchema.Id]).ObjectId;
                this.messageItem = MessageItem.Bind(session, objectId);
                if (this.messageItem == null)
                {
                    throw new System.Data.ObjectNotFoundException("The requested message was not loaded.");
                }
                this.messageItem.OpenAsReadWrite();
            }
            catch (Microsoft.Exchange.Data.Storage.ObjectNotFoundException innerException)
            {
                throw new System.Data.ObjectNotFoundException("The requested message was not loaded.", innerException);
            }
            finally
            {
                TimeSpan additionalLatency = this.context.EndTrackLatency(LatencyComponent.StoreDriverDeliveryRpc);
                this.context.AddRpcLatency(additionalLatency, "Load message");
            }
        }
        internal static bool CheckDuplicateInitiationAndUpdateIdIfNecessary(MessageItem message)
        {
            message.Load(InitiationProcessor.PropertiesForUniquenessCheck);
            string internetMessageId = message.InternetMessageId;
            string text;

            if (!InitiationProcessor.TryGetIdentiferFromInitiationMessageId(internetMessageId, out text))
            {
                return(false);
            }
            InitiationProcessor.diag.TraceDebug <string, string>(0L, "Find dup for init message messageid='{0}' identifier='{1}'.", internetMessageId, text);
            string         text2   = message.TryGetProperty(MessageItemSchema.ApprovalRequestor) as string;
            string         text3   = message.TryGetProperty(MessageItemSchema.ApprovalApplicationData) as string;
            MailboxSession session = (MailboxSession)message.Session;

            IStorePropertyBag[] array;
            try
            {
                array = AllItemsFolderHelper.FindItemsFromInternetId(session, text, InitiationProcessor.PropertiesForUniquenessCheck);
            }
            catch (ObjectNotFoundException arg)
            {
                InitiationProcessor.diag.TraceError <ObjectNotFoundException>(0L, "Exception - {0}", arg);
                return(false);
            }
            bool flag  = false;
            bool flag2 = false;

            if (array != null && array.Length > 0)
            {
                InitiationProcessor.diag.TraceDebug <int, string>(0L, "Found {0} initiation messages with the message id. messageId={1}.", array.Length, text);
                for (int i = 0; i < array.Length; i++)
                {
                    flag = true;
                    string text4 = array[i].TryGetProperty(MessageItemSchema.ApprovalRequestor) as string;
                    string text5 = array[i].TryGetProperty(MessageItemSchema.ApprovalApplicationData) as string;
                    if (string.Equals(text4, text2, StringComparison.OrdinalIgnoreCase) && string.Equals(text5, text3, StringComparison.OrdinalIgnoreCase))
                    {
                        flag2 = true;
                        break;
                    }
                    InitiationProcessor.diag.TraceDebug(0L, "Matching message-id={0} unmatched data requestor={1} data={2} found: requestor={3} data={4}.", new object[]
                    {
                        text,
                        text2,
                        text3,
                        text4,
                        text5
                    });
                }
            }
            InitiationProcessor.diag.TraceDebug <string, bool, bool>(0L, "'{0}' found={1}, duplicateInitiation = {2}", text, flag, flag2);
            if (!flag2)
            {
                if (flag)
                {
                    message.InternetMessageId = Guid.NewGuid().ToString().Substring(0, 5) + "_" + internetMessageId;
                    InitiationProcessor.diag.TraceDebug <string, string>(0L, "Rewriting from message id from {0} to {1}", internetMessageId, message.InternetMessageId);
                }
                else if (!flag)
                {
                    message.InternetMessageId = text;
                }
            }
            return(flag2);
        }
Example #5
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);
        }