Example #1
0
        private void ChangeDestinationFolder(DefaultFolderType folderType, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            string         text           = args.MailItem.FromAddress.ToString();
            MailboxSession mailboxSession = storeDriverDeliveryEventArgsImpl.MailboxSession;
            string         text2          = storeDriverDeliveryEventArgsImpl.MailRecipient.MsgId.ToString();
            bool           flag           = this.IsSourceEhaMigration(storeDriverDeliveryEventArgsImpl.MailItem, text2);

            UnJournalAgent.Tracer.TraceDebug(0L, "ChangeDestinationFolder: MessageId {0}, Sender {1}, isSourceEha {2}, folderType {3} ", new object[]
            {
                text2,
                text,
                flag.ToString(),
                folderType.ToString()
            });
            if (DefaultFolderType.LegacyArchiveJournals == folderType || !flag)
            {
                UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "ChangeDestinationFolder: MessageId {0}, Sender {1}, Source is not EHA or this is directed to legacyarchivejournals folder in journalndr mailbox", text2, text);
                StoreId storeId = mailboxSession.GetDefaultFolderId(folderType);
                if (storeId == null)
                {
                    storeId = mailboxSession.CreateDefaultFolder(folderType);
                }
                if (storeId != null)
                {
                    storeDriverDeliveryEventArgsImpl.DeliverToFolder = storeId;
                    return;
                }
            }
            else
            {
                UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "ChangeDestinationFolder: MessageId {0}, Sender {1}, This is a migration message from EHA, put it in the hidden folder", text2, text);
                storeDriverDeliveryEventArgsImpl.DeliverToFolder = this.GetCreateFolderIdUnderGivenParentFolder("MigrationFolder", folderType.ToString(), mailboxSession);
            }
        }
 public AgentInfoWriter(StoreDriverDeliveryEventArgs eventArgs, string agentName)
 {
     ArgumentValidator.ThrowIfNull("eventArgs", eventArgs);
     ArgumentValidator.ThrowIfNull("agentName", agentName);
     this.eventArgs = eventArgs;
     this.agentName = agentName;
 }
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs e)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)e;

            if (storeDriverDeliveryEventArgsImpl.IsPublicFolderRecipient || storeDriverDeliveryEventArgsImpl.IsJournalReport)
            {
                UMPlayonPhoneAgent.Tracer.TraceError((long)this.GetHashCode(), "not supported for public folder or journal reports");
                return;
            }
            if (!storeDriverDeliveryEventArgsImpl.ReplayItem.IsRestricted || !storeDriverDeliveryEventArgsImpl.ReplayItem.ClassName.StartsWith("IPM.Note.rpmsg.Microsoft.Voicemail.UM", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            UMMailboxPolicy ummailboxPolicy;

            if (!UMAgentUtil.TryGetUMMailboxPolicy(UMPlayonPhoneAgent.Tracer, storeDriverDeliveryEventArgsImpl.ADRecipientCache, storeDriverDeliveryEventArgsImpl.MailRecipient, out ummailboxPolicy))
            {
                return;
            }
            if (storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies == null)
            {
                storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies = new Dictionary <PropertyDefinition, object>();
            }
            if (ummailboxPolicy.RequireProtectedPlayOnPhone)
            {
                storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[MessageItemSchema.RequireProtectedPlayOnPhone] = "true";
            }
        }
Example #4
0
 public void OnCompletedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
 {
     if (this.logValues != null)
     {
         this.classificationAgentLogger.LogClassificationProperties(this.logValues, (!this.wasMessageDelivered) ? InferenceClassificationAgentLogger.Status.DeliveryFailed.ToString() : null);
     }
 }
Example #5
0
        public override void SubmitMailItem(TransportMailItem mailItem, bool suppressDSNs)
        {
            StoreDriverDeliveryEventArgs storeDriverDeliveryEventArgs = null;

            if (base.AssociatedAgent != null && base.AssociatedAgent.Session != null && base.AssociatedAgent.Session.CurrentEventArgs != null)
            {
                storeDriverDeliveryEventArgs = (base.AssociatedAgent.Session.CurrentEventArgs as StoreDriverDeliveryEventArgs);
            }
            bool flag  = this.agentLoopChecker.IsEnabledInSubmission();
            bool flag2 = false;

            if (storeDriverDeliveryEventArgs != null && !string.IsNullOrEmpty(base.AssociatedAgent.Name))
            {
                flag2 = this.agentLoopChecker.CheckAndStampInSubmission(storeDriverDeliveryEventArgs.MailItem.Message.RootPart.Headers, mailItem.RootPart.Headers, base.AssociatedAgent.Name);
                if (flag2)
                {
                    MessageTrackingLog.TrackAgentGeneratedMessageRejected(MessageTrackingSource.STOREDRIVER, flag, mailItem);
                }
            }
            if (flag2 && flag)
            {
                using (IEnumerator <MailRecipient> enumerator = mailItem.Recipients.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        MailRecipient mailRecipient = enumerator.Current;
                        mailRecipient.Ack(AckStatus.Fail, SmtpResponse.AgentGeneratedMessageDepthExceeded);
                    }
                    return;
                }
            }
            Utils.SubmitMailItem(mailItem, suppressDSNs);
        }
Example #6
0
        private void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;

            if (MeetingSeriesMessageOrderingAgent.SeriesMessageOrderingEnabled(storeDriverDeliveryEventArgsImpl.MailboxOwner))
            {
                this.OrderMessages(storeDriverDeliveryEventArgsImpl);
            }
        }
        public void OnCreatedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;

            if (RetentonPolicyTagProcessingAgent.IsRetentionPolicyEnabled(storeDriverDeliveryEventArgsImpl.ADRecipientCache, storeDriverDeliveryEventArgsImpl.MailRecipient.Email))
            {
                RetentionTagHelper.ApplyPolicy(storeDriverDeliveryEventArgsImpl.MailboxSession, storeDriverDeliveryEventArgsImpl.RetentionPolicyTag, storeDriverDeliveryEventArgsImpl.RetentionFlags, storeDriverDeliveryEventArgsImpl.RetentionPeriod, storeDriverDeliveryEventArgsImpl.ArchiveTag, storeDriverDeliveryEventArgsImpl.ArchivePeriod, storeDriverDeliveryEventArgsImpl.CompactDefaultRetentionPolicy, storeDriverDeliveryEventArgsImpl.MessageItem);
            }
        }
Example #8
0
        internal override void Invoke(string eventTopic, object source, object e)
        {
            Delegate @delegate = (Delegate)base.Handlers[eventTopic];

            if (@delegate == null)
            {
                return;
            }
            StoreDriverEventSource       source2 = (StoreDriverEventSource)source;
            StoreDriverDeliveryEventArgs storeDriverDeliveryEventArgs = (StoreDriverDeliveryEventArgs)e;

            ((SmtpServer)this.HostState).AddressBook.RecipientCache = storeDriverDeliveryEventArgs.MailItem.RecipientCache;
            if (eventTopic != null)
            {
                if (!(eventTopic == "OnInitializedMessage"))
                {
                    if (!(eventTopic == "OnPromotedMessage"))
                    {
                        if (!(eventTopic == "OnCreatedMessage"))
                        {
                            if (!(eventTopic == "OnDeliveredMessage"))
                            {
                                if (!(eventTopic == "OnCompletedMessage"))
                                {
                                    goto IL_DA;
                                }
                                ((CompletedMessageEventHandler)@delegate)(source2, storeDriverDeliveryEventArgs);
                            }
                            else
                            {
                                ((DeliveredMessageEventHandler)@delegate)(source2, storeDriverDeliveryEventArgs);
                            }
                        }
                        else
                        {
                            ((CreatedMessageEventHandler)@delegate)(source2, storeDriverDeliveryEventArgs);
                        }
                    }
                    else
                    {
                        ((PromotedMessageEventHandler)@delegate)(source2, storeDriverDeliveryEventArgs);
                    }
                }
                else
                {
                    ((InitializedMessageEventHandler)@delegate)(source2, storeDriverDeliveryEventArgs);
                }
                if (base.Synchronous)
                {
                    ((SmtpServer)this.HostState).AddressBook.RecipientCache = null;
                }
                return;
            }
IL_DA:
            throw new InvalidOperationException("Internal error: unsupported event topic: " + (eventTopic ?? "null"));
        }
Example #9
0
        public void OnCreatedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;

            if (this.ShouldProcessMessage(storeDriverDeliveryEventArgsImpl))
            {
                MeetingMessageProcessing.ProcessMessage(storeDriverDeliveryEventArgsImpl.MessageItem, storeDriverDeliveryEventArgsImpl.MailRecipient, this.GetCachedCalendarItemIdFromHeaders(storeDriverDeliveryEventArgsImpl), storeDriverDeliveryEventArgsImpl.DeliverToFolder);
                this.SaveChangedPropertiesForDelegateForward(storeDriverDeliveryEventArgsImpl);
            }
        }
Example #10
0
        private void OnPromotedMessageImplementation(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            this.logger.TraceDebug(new string[]
            {
                "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: entering."
            });
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = args as StoreDriverDeliveryEventArgsImpl;

            if (storeDriverDeliveryEventArgsImpl == null)
            {
                this.logger.TraceDebug(new string[]
                {
                    "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: args is null or not a StoreDriverDeliveryEventArgsImpl; exiting."
                });
                return;
            }
            if (!SharedMailboxSentItemsAgent.IsSharedMailboxSentItemsDeliveryAgentFeatureEnabled(storeDriverDeliveryEventArgsImpl.MailboxOwner))
            {
                this.logger.TraceDebug(new string[]
                {
                    "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: Flight for the feature is not enabled; exiting."
                });
                return;
            }
            if (storeDriverDeliveryEventArgsImpl.MailboxSession == null)
            {
                this.logger.TraceDebug(new string[]
                {
                    "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: Mailbox session is null; exiting."
                });
                return;
            }
            if (args.MailItem.Message == null)
            {
                this.logger.TraceDebug(new string[]
                {
                    "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: Message is null; exiting."
                });
                return;
            }
            if (storeDriverDeliveryEventArgsImpl.ReplayItem == null)
            {
                this.logger.TraceDebug(new string[]
                {
                    "SharedMailboxSentItemsAgent.OnPromotedMessageHandler: ReplayItem is null; exiting."
                });
                return;
            }
            EmailMessage   message        = args.MailItem.Message;
            MailboxSession mailboxSession = storeDriverDeliveryEventArgsImpl.MailboxSession;
            MessageItem    replayItem     = storeDriverDeliveryEventArgsImpl.ReplayItem;
            string         mdbGuid        = storeDriverDeliveryEventArgsImpl.MailboxSession.MdbGuid.ToString();

            this.ProcessSentItemWrapperMessage(message, mdbGuid, replayItem, new StoreOperations(mailboxSession, this.logger), new AgentInfoWriter(args, "SharedMailboxSentItemsAgent"));
        }
Example #11
0
        private void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = args as StoreDriverDeliveryEventArgsImpl;

            if (storeDriverDeliveryEventArgsImpl.IsPublicFolderRecipient || !ObjectClass.IsSmsMessage(storeDriverDeliveryEventArgsImpl.MessageClass))
            {
                return;
            }
            SmsDeliveryAgent.Tracer.TraceDebug((long)this.GetHashCode(), "Processing incoming message");
            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                MimePart rootPart = storeDriverDeliveryEventArgsImpl.MailItem.Message.RootPart;
                Header   header   = rootPart.Headers.FindFirst("X-MS-Reply-To-Mobile");
                if (header == null || string.IsNullOrEmpty(header.Value))
                {
                    SmsDeliveryAgent.Tracer.TraceDebug <string>((long)this.GetHashCode(), "There's no {0} header or the header value is empty in MimePart of the inbound SMS message", "X-MS-Reply-To-Mobile");
                }
                else
                {
                    string value       = header.Value;
                    string displayName = value;
                    using (SmsRecipientInfoCache smsRecipientInfoCache = new SmsRecipientInfoCache(storeDriverDeliveryEventArgsImpl.MailboxSession, SmsDeliveryAgent.Tracer))
                    {
                        RecipientInfoCacheEntry recipientInfoCacheEntry = smsRecipientInfoCache.LookUp(value);
                        if (recipientInfoCacheEntry != null)
                        {
                            displayName = recipientInfoCacheEntry.DisplayName;
                        }
                    }
                    storeDriverDeliveryEventArgsImpl.ReplayItem.From = new Participant(displayName, value, "MOBILE");
                    SmsDeliveryAgent.Tracer.TraceDebug((long)this.GetHashCode(), "Found entry from SMS recipient which matches");
                    string text = storeDriverDeliveryEventArgsImpl.ReplayItem.Body.GetPartialTextBody(160);
                    if (!string.IsNullOrEmpty(text))
                    {
                        text = text.Replace("\r\n", " ").Trim();
                    }
                    storeDriverDeliveryEventArgsImpl.ReplayItem.Subject = (text ?? string.Empty);
                }
            }
            finally
            {
                stopwatch.Stop();
                MSExchangeInboundSmsDelivery.MessageReceived.Increment();
                if (MSExchangeInboundSmsDelivery.MaximumMessageProcessingTime.RawValue < stopwatch.ElapsedMilliseconds)
                {
                    MSExchangeInboundSmsDelivery.MaximumMessageProcessingTime.RawValue = stopwatch.ElapsedMilliseconds;
                }
                SmsDeliveryAgent.averageMessageProcessingTime.Update(stopwatch.ElapsedMilliseconds);
                SmsDeliveryAgent.Tracer.TraceDebug <long>((long)this.GetHashCode(), "Exiting ConversationsProcessing.ProcessMessage.  Total execution time = {0} ms.", stopwatch.ElapsedMilliseconds);
            }
        }
        public void OnCompletedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            using (new MailboxRulesPerformanceTracker(this.stopwatch))
            {
                this.DisposeAgentState();
            }
            long num = Math.Max(0L, this.stopwatch.ElapsedMilliseconds);

            MailboxRulesAgent.processingTime.AddValue(num);
            MSExchangeStoreDriver.MailboxRulesMilliseconds90thPercentile.RawValue = MailboxRulesAgent.processingTime.PercentileQuery(90.0);
            MailboxRulesAgent.averageMilliseconds.Update((float)num);
            MSExchangeStoreDriver.MailboxRulesMilliseconds.RawValue = (long)MailboxRulesAgent.averageMilliseconds.Value;
        }
Example #13
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 #14
0
        public void OnInitializedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            string arg  = args.MailItem.FromAddress.ToString();
            string text = storeDriverDeliveryEventArgsImpl.MailRecipient.MsgId.ToString();

            UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "OnInitializedMessageHandler: MessageId {0}, Invoked Sender {1}", text, arg);
            if (this.ShouldProcess(storeDriverDeliveryEventArgsImpl.ADRecipientCache.OrganizationId, args.MailItem, text) && this.IsSender(args))
            {
                AddressHeader addressHeader = args.MailItem.Message.MimeDocument.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-BCC") as AddressHeader;
                UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "OnInitializedMessageHandler: MessageId {0}, GetBccRecipients Sender {1}, BccHeader {2} = ", text, arg, (addressHeader == null) ? string.Empty : addressHeader.ToString());
                this.bccRecipients = this.GetBccRecipients(addressHeader);
            }
        }
 public void OnCreatedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
 {
     if (this.evaluationResult != null)
     {
         ExTraceGlobals.FaultInjectionTracer.TraceTest(40592U);
         using (new MailboxRulesPerformanceTracker(this.stopwatch))
         {
             StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
             this.evaluationResult.Context.FinalDeliveryFolderId = storeDriverDeliveryEventArgsImpl.DeliverToFolder;
             this.evaluationResult.Context.DeliveredMessage      = storeDriverDeliveryEventArgsImpl.MessageItem;
             this.evaluationResult.Execute(ExecutionStage.OnCreatedMessage);
         }
     }
 }
Example #16
0
 private void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
 {
     if (StoreDriverConfig.Instance.IsAutoAcceptForGroupAndSelfForwardedEventEnabled)
     {
         StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
         if ((ObjectClass.IsMeetingRequest(storeDriverDeliveryEventArgsImpl.MessageClass) || ObjectClass.IsMeetingResponse(storeDriverDeliveryEventArgsImpl.MessageClass)) && !this.IsEHAMigrationMeetingMessage(storeDriverDeliveryEventArgsImpl.MailItem))
         {
             MailboxSession mailboxSession = storeDriverDeliveryEventArgsImpl.MailboxSession;
             if (mailboxSession == null || storeDriverDeliveryEventArgsImpl.ReplayItem == null)
             {
                 MeetingMessageProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "MeetingMessageProcessingAgent::OnPromotedMessageHandler() MailboxSession or StoreDriverDeliveryEventArgsImpl.ReplayItem is null");
                 return;
             }
             if (ObjectClass.IsMeetingRequest(storeDriverDeliveryEventArgsImpl.MessageClass) && !mailboxSession.IsGroupMailbox())
             {
                 MeetingRequest meetingRequest = null;
                 try
                 {
                     meetingRequest = (Item.ConvertFrom(storeDriverDeliveryEventArgsImpl.ReplayItem, mailboxSession) as MeetingRequest);
                     if (meetingRequest != null && MeetingMessageProcessing.IsSentToSelf(meetingRequest, mailboxSession))
                     {
                         MeetingMessageProcessingAgent.tracer.TraceDebug <string, IExchangePrincipal>((long)this.GetHashCode(), "Attempting to deliver self forwarded message {0} to mailbox {1} to Deleted Items", meetingRequest.InternetMessageId, mailboxSession.MailboxOwner);
                         this.DeliverToDeletedItems(mailboxSession, meetingRequest, storeDriverDeliveryEventArgsImpl);
                     }
                 }
                 finally
                 {
                     if (meetingRequest != null)
                     {
                         Item.SafeDisposeConvertedItem(storeDriverDeliveryEventArgsImpl.ReplayItem, meetingRequest);
                     }
                 }
             }
             if (ObjectClass.IsMeetingResponse(storeDriverDeliveryEventArgsImpl.MessageClass) && mailboxSession.IsGroupMailbox())
             {
                 MeetingResponse meetingResponse = Item.ConvertFrom(storeDriverDeliveryEventArgsImpl.ReplayItem, mailboxSession) as MeetingResponse;
                 if (meetingResponse != null && meetingResponse.IsSilent)
                 {
                     ADRecipient adrecipient = null;
                     if (meetingResponse.From.TryGetADRecipient(mailboxSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid), out adrecipient) && adrecipient != null && adrecipient.RecipientDisplayType != RecipientDisplayType.ConferenceRoomMailbox && adrecipient.RecipientDisplayType != RecipientDisplayType.SyncedConferenceRoomMailbox && adrecipient.RecipientDisplayType != RecipientDisplayType.EquipmentMailbox && adrecipient.RecipientDisplayType != RecipientDisplayType.SyncedEquipmentMailbox && !meetingResponse.IsCounterProposal)
                     {
                         MeetingMessageProcessingAgent.tracer.TraceDebug <string, IExchangePrincipal>((long)this.GetHashCode(), "Attempting to deliver empty response {0} to mailbox {1} to Deleted Items", meetingResponse.InternetMessageId, mailboxSession.MailboxOwner);
                         this.DeliverToDeletedItems(mailboxSession, meetingResponse, storeDriverDeliveryEventArgsImpl);
                     }
                 }
             }
         }
     }
 }
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;

            if (this.msgClassifications == null)
            {
                this.msgClassifications = ClassificationUtils.ExtractClassifications(storeDriverDeliveryEventArgsImpl.MailItemDeliver.MbxTransportMailItem.RootPart.Headers);
            }
            if (this.IsJournalReport(storeDriverDeliveryEventArgsImpl.MailItemDeliver.MbxTransportMailItem))
            {
                this.ProcessClassificationsForJournalReport(storeDriverDeliveryEventArgsImpl);
                return;
            }
            this.ProcessClassifications(storeDriverDeliveryEventArgsImpl);
        }
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            if (args == null)
            {
                return;
            }
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            MailboxSession mailboxSession = storeDriverDeliveryEventArgsImpl.MailboxSession;
            string         messageClass   = storeDriverDeliveryEventArgsImpl.MessageClass;

            if (GroupEscalationAgent.ShouldBlockMessageForGroup(mailboxSession, messageClass))
            {
                storeDriverDeliveryEventArgsImpl.DeliverToFolder = mailboxSession.GetDefaultFolderId(DefaultFolderType.DeletedItems);
                GroupEscalationAgent.Tracer.TraceDebug <string>((long)this.GetHashCode(), "GroupEscalationAgent.OnPromotedMessageHandler: message is blocked. Its class is {0}", messageClass);
            }
        }
 public void OnDeliveredMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
 {
     if (this.evaluationResult != null)
     {
         using (new MailboxRulesPerformanceTracker(this.stopwatch))
         {
             StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
             this.evaluationResult.Context.DeliveredMessage = storeDriverDeliveryEventArgsImpl.MessageItem;
             this.evaluationResult.Context.PropertiesForAllMessageCopies = storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies;
             this.evaluationResult.Context.PropertiesForDelegateForward  = storeDriverDeliveryEventArgsImpl.PropertiesForDelegateForward;
             this.evaluationResult.Execute(ExecutionStage.OnDeliveredMessage);
             this.evaluationContext.UpdateDeferredError();
             this.HandleTestMessage(storeDriverDeliveryEventArgsImpl);
             List <string> errorRecords = ((RuleEvaluationContext)this.evaluationResult.Context).ErrorRecords;
             storeDriverDeliveryEventArgsImpl.AddDeliveryErrors(errorRecords);
         }
     }
 }
            public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
            {
                StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
                MbxTransportMailItem             mbxTransportMailItem             = storeDriverDeliveryEventArgsImpl.MailItemDeliver.MbxTransportMailItem;

                if (storeDriverDeliveryEventArgsImpl.IsPublicFolderRecipient || storeDriverDeliveryEventArgsImpl.IsJournalReport)
                {
                    return;
                }
                Guid?guidHeaderValue = ContentAggregationAgentFactory.ContentAggregationAgent.GetGuidHeaderValue(mbxTransportMailItem, "X-MS-Exchange-Organization-Sharing-Instance-Guid");

                if (guidHeaderValue == null)
                {
                    return;
                }
                storeDriverDeliveryEventArgsImpl.ShouldRunMailboxRulesBasedOnDeliveryFolder = true;
                if (storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies == null)
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies = new Dictionary <PropertyDefinition, object>(3);
                }
                storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies.Add(MessageItemSchema.SharingInstanceGuid, guidHeaderValue.Value);
                ExTraceGlobals.DeliveryAgentTracer.TraceDebug <Guid?>(mbxTransportMailItem.RecordId, "Sharing Instance Guid: {0}", guidHeaderValue);
                string textHeaderValue = ContentAggregationAgentFactory.ContentAggregationAgent.GetTextHeaderValue(mbxTransportMailItem, "X-MS-Exchange-Organization-Cloud-Id");

                if (!string.IsNullOrEmpty(textHeaderValue))
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies.Add(ItemSchema.CloudId, textHeaderValue);
                }
                ExTraceGlobals.DeliveryAgentTracer.TraceDebug <string>(mbxTransportMailItem.RecordId, "Cloud Id: {0}", textHeaderValue);
                string textHeaderValue2 = ContentAggregationAgentFactory.ContentAggregationAgent.GetTextHeaderValue(mbxTransportMailItem, "X-MS-Exchange-Organization-Cloud-Version");

                if (!string.IsNullOrEmpty(textHeaderValue2))
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies.Add(ItemSchema.CloudVersion, textHeaderValue2);
                }
                ExTraceGlobals.DeliveryAgentTracer.TraceDebug <string>(mbxTransportMailItem.RecordId, "Cloud Version: {0}", textHeaderValue2);
                StoreId storeId;

                if (this.TryGetDeliveryFolderId(mbxTransportMailItem, storeDriverDeliveryEventArgsImpl.MailboxSession, out storeId))
                {
                    storeDriverDeliveryEventArgsImpl.DeliverToFolder = storeId;
                }
                ExTraceGlobals.DeliveryAgentTracer.TraceDebug <StoreId>(mbxTransportMailItem.RecordId, "Delivery Folder: {0}", storeId);
            }
Example #21
0
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs e)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)e;
            Header header = storeDriverDeliveryEventArgsImpl.MailItem.Message.MimeDocument.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Network-Message-Id");

            this.diagnosticsSession.TraceDebug <string>("Processing message {0}", (header != null) ? header.Value : "unknown");
            if (this.mimeHeaders != null)
            {
                this.diagnosticsSession.TraceDebug("Already processed this message", new object[0]);
                return;
            }
            this.mimeHeaders = storeDriverDeliveryEventArgsImpl.MailItem.Message.MimeDocument.RootPart.Headers;
            string property = this.GetProperty("X-MS-Exchange-Forest-IndexAgent");

            if (property == null || !XHeaderStream.IsVersionSupported(property))
            {
                this.diagnosticsSession.TraceDebug("X-header not present.", new object[0]);
                return;
            }
            bool             invalidAnnotationToken = false;
            EmailMessageHash emailMessageHash;

            if (EmailMessageHash.TryGetFromHeader(this.mimeHeaders, out emailMessageHash))
            {
                EmailMessageHash emailMessageHash2 = new EmailMessageHash(storeDriverDeliveryEventArgsImpl.MailItem.Message);
                this.diagnosticsSession.TraceDebug <EmailMessageHash>("Computed hash value for current message: {0}.", emailMessageHash2);
                if (!StringComparer.OrdinalIgnoreCase.Equals(emailMessageHash.ToString(), emailMessageHash2.ToString()))
                {
                    this.diagnosticsSession.TraceDebug <EmailMessageHash, EmailMessageHash>("The current hash value ({0}) doesn't match the original({1})", emailMessageHash2, emailMessageHash);
                    invalidAnnotationToken = true;
                }
            }
            try
            {
                using (XHeaderStream xheaderStream = new XHeaderStream(new Func <string, string>(this.GetProperty)))
                {
                    this.PromoteProperties(xheaderStream, storeDriverDeliveryEventArgsImpl.ReplayItem, invalidAnnotationToken);
                }
            }
            catch (Exception arg)
            {
                this.diagnosticsSession.TraceError <Exception>("Exception during PromoteProperties: {0}", arg);
            }
        }
        public void OnDeliveredMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            MailboxSession mailboxSession = storeDriverDeliveryEventArgsImpl.MailboxSession;

            if (mailboxSession == null || !mailboxSession.IsGroupMailbox())
            {
                GroupEscalationAgent.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalationAgent.OnDeliveredMessageHandler: Session null or not a group mailbox.");
                return;
            }
            MessageItem messageItem = storeDriverDeliveryEventArgsImpl.MessageItem;

            messageItem.Load(new PropertyDefinition[]
            {
                ItemSchema.InternetMessageId,
                ItemSchema.SentTime
            });
            this.processedMessages.ClearMessageFromProcessedList(messageItem.InternetMessageId, messageItem.SentTime, mailboxSession.MailboxGuid);
        }
        public void OnCreatedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            MessageItem          messageItem          = storeDriverDeliveryEventArgsImpl.MessageItem;
            MbxTransportMailItem mbxTransportMailItem = storeDriverDeliveryEventArgsImpl.MailItemDeliver.MbxTransportMailItem;

            if (messageItem == null || mbxTransportMailItem == null)
            {
                GroupEscalationAgent.Tracer.TraceError((long)this.GetHashCode(), "No message to process");
                return;
            }
            MailboxSession mailboxSession = messageItem.Session as MailboxSession;

            if (GroupEscalationAgent.ShouldGenerateIrmNdr(mailboxSession, messageItem, storeDriverDeliveryEventArgsImpl.MailboxOwner))
            {
                GroupEscalationAgent.Tracer.TraceDebug((long)this.GetHashCode(), "GroupEscalationAgent.ShouldProcessMessage: NDR the message since it's irm message sent to group");
                throw new SmtpResponseException(GroupEscalationAgent.IrmMessageDeliveryToGroupMailBoxError);
            }
            if (!this.ShouldProcessMessage(mailboxSession, storeDriverDeliveryEventArgsImpl))
            {
                return;
            }
            IGroupEscalationFlightInfo groupEscalationFlightInfo = new GroupEscalationFlightInfo(storeDriverDeliveryEventArgsImpl.MailboxOwner.GetContext(null));
            TransportGroupEscalation   transportGroupEscalation  = new TransportGroupEscalation(mbxTransportMailItem, XSOFactory.Default, groupEscalationFlightInfo, new MailboxUrls(mailboxSession.MailboxOwner, false));
            bool flag;

            if (transportGroupEscalation.EscalateItem(messageItem, mailboxSession, out flag, false))
            {
                GroupEscalationAgent.Tracer.TraceDebug <string>((long)this.GetHashCode(), "GroupEscalationAgent.EscalateItem: Escalation of message {0} from group mailbox successful", messageItem.InternetMessageId);
                this.processedMessages.AddMessageToProcessedList(messageItem.InternetMessageId, messageItem.SentTime, mailboxSession.MailboxGuid, DeliveryStage.CreatedMessageEventHandled);
                return;
            }
            GroupEscalationAgent.Tracer.TraceError <string, bool>((long)this.GetHashCode(), "GroupEscalationAgent.EscalateItem: Escalation of message {0} from group mailbox failed. IsTransientError: {1}", messageItem.InternetMessageId, flag);
            this.processedMessages.ClearMessageFromProcessedList(messageItem.InternetMessageId, messageItem.SentTime, mailboxSession.MailboxGuid);
            if (flag)
            {
                throw new SmtpResponseException(GroupEscalationAgent.EscalationFailedTransientError);
            }
            throw new SmtpResponseException(GroupEscalationAgent.EscalationFailedPermanentError);
        }
Example #24
0
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            string arg  = args.MailItem.FromAddress.ToString();
            string text = storeDriverDeliveryEventArgsImpl.MailRecipient.MsgId.ToString();

            UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "OnPromotedMessageHandler: MessageId {0}, Sender {1}", text, arg);
            if (this.IsSender(args) && this.ShouldProcess(storeDriverDeliveryEventArgsImpl.ADRecipientCache.OrganizationId, args.MailItem, text) && !this.IsSenderARecipient(args.MailItem, text))
            {
                this.ChangeDestinationFolder(DefaultFolderType.SentItems, args);
                return;
            }
            if (this.ShouldProcessWithNdrCheck(storeDriverDeliveryEventArgsImpl.ADRecipientCache.OrganizationId, args.MailItem, text))
            {
                this.ChangeDestinationFolder(DefaultFolderType.LegacyArchiveJournals, args);
                return;
            }
            if (this.ShouldProcess(storeDriverDeliveryEventArgsImpl.ADRecipientCache.OrganizationId, args.MailItem, text))
            {
                this.ChangeDestinationFolder(DefaultFolderType.Inbox, args);
            }
        }
Example #25
0
        private bool IsSender(StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            string              arg           = storeDriverDeliveryEventArgsImpl.MailRecipient.MsgId.ToString();
            MailRecipient       mailRecipient = storeDriverDeliveryEventArgsImpl.MailRecipient;
            DeliverableMailItem mailItem      = args.MailItem;
            Header              header        = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.SenderAddress);
            bool result;

            if (header != null)
            {
                string value = header.Value;
                if (!string.IsNullOrEmpty(value))
                {
                    if (string.Compare(value, mailRecipient.Email.ToString(), StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "IsSender: MessageId {0}, Original Sender found in header matched with the current recipient address {1}", arg, value);
                        result = true;
                    }
                    else
                    {
                        UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "IsSender: MessageId {0}, Original Sender found in header doesnot match with the current recipient address : Original sender {1} , Current Recipient {2}", arg, value, mailRecipient.Email.ToString());
                        result = false;
                    }
                }
                else
                {
                    UnJournalAgent.Tracer.TraceDebug <string>(0L, "IsSender: MessageId {0}, Original Sender not found in mailitem unjournal headers, header value is empty", arg);
                    result = false;
                }
            }
            else
            {
                UnJournalAgent.Tracer.TraceDebug <string>(0L, "IsSender: MessageId {0}, Original Sender not found in mailitem unjournal headers, header doesnot exist", arg);
                result = false;
            }
            return(result);
        }
Example #26
0
        public void OnDeliveredMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            MailRecipient        mailRecipient        = storeDriverDeliveryEventArgsImpl.MailRecipient;
            MbxTransportMailItem mbxTransportMailItem = storeDriverDeliveryEventArgsImpl.MailItemDeliver.MbxTransportMailItem;

            if (!ApprovalInitiation.IsArbitrationMailbox(mbxTransportMailItem.ADRecipientCache, mailRecipient.Email))
            {
                return;
            }
            DeliverableMailItem mailItem    = storeDriverDeliveryEventArgsImpl.MailItem;
            MessageItem         messageItem = storeDriverDeliveryEventArgsImpl.MessageItem;
            EmailMessage        message     = mailItem.Message;
            int?messageLocaleId             = (storeDriverDeliveryEventArgsImpl.ReplayItem != null) ? storeDriverDeliveryEventArgsImpl.ReplayItem.GetValueAsNullable <int>(MessageItemSchema.MessageLocaleId) : null;

            this.CheckArbitrationMailboxCapacity(messageItem.Session as MailboxSession, mbxTransportMailItem.OrganizationId);
            ApprovalEngine approvalEngineInstance = ApprovalEngine.GetApprovalEngineInstance(message, (RoutingAddress)message.From.SmtpAddress, mailRecipient.Email, messageItem, mbxTransportMailItem, ApprovalProcessingAgent.MessageItemCreationDelegate);

            if (approvalEngineInstance.CreateAndSubmitApprovalRequests(messageLocaleId) != ApprovalEngine.ProcessResult.InitiationMessageOk)
            {
                throw new SmtpResponseException(AckReason.ApprovalInvalidMessage);
            }
        }
Example #27
0
        private void AddBccRecipientsToMessage(StoreDriverDeliveryEventArgs args, MessageItem messageItem)
        {
            ADRecipientCache <TransportMiniRecipient> adrecipientCache = (ADRecipientCache <TransportMiniRecipient>)args.MailItem.RecipientCache;

            foreach (MimeRecipient mimeRecipient in this.bccRecipients)
            {
                Participant participant = null;
                Result <TransportMiniRecipient> result;
                if (adrecipientCache.TryGetValue(ProxyAddress.Parse(mimeRecipient.Email), out result))
                {
                    TransportMiniRecipient data = result.Data;
                    if (data != null)
                    {
                        participant = new Participant(data);
                    }
                }
                if (participant == null)
                {
                    participant = new Participant(mimeRecipient.DisplayName, mimeRecipient.Email, "SMTP");
                }
                messageItem.Recipients.Add(participant, RecipientItemType.Bcc);
            }
        }
Example #28
0
        public void OnCreatedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            string arg  = args.MailItem.FromAddress.ToString();
            string text = storeDriverDeliveryEventArgsImpl.MailRecipient.MsgId.ToString();

            UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "OnCreatedMessageHandler: MessageId {0}, Invoked, Sender {1}", text, arg);
            if (this.ShouldProcess(storeDriverDeliveryEventArgsImpl.ADRecipientCache.OrganizationId, args.MailItem, text))
            {
                UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "OnCreatedMessageHandler: MessageId {0}, Sender {1}: This message is coming from unjournal routing agent, we need to process it", text, arg);
                if (this.IsSender(args))
                {
                    UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "OnCreatedMessageHandler: MessageId {0}, Sender {1} : This is a sender, trying to add bcc recipients if needed", text, arg);
                    this.AddBccRecipientsToMessage(args, ((StoreDriverDeliveryEventArgsImpl)args).MessageItem);
                }
                MailboxSession mailboxSession = storeDriverDeliveryEventArgsImpl.MailboxSession;
                ExDateTime     exDateTime;
                if (this.TryGetExpiryDateForMigratedMessage(storeDriverDeliveryEventArgsImpl.MailItem, out exDateTime))
                {
                    UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "OnCreatedMessageHandler: MessageId {0}, Sender {1}: This is a migrated message , expiry date exists on this message. ExpiryDate = {2}", text, arg, exDateTime.ToString());
                    MessageItem messageItem = storeDriverDeliveryEventArgsImpl.MessageItem;
                    if (RetentonPolicyTagProcessingAgent.IsRetentionPolicyEnabled(storeDriverDeliveryEventArgsImpl.ADRecipientCache, storeDriverDeliveryEventArgsImpl.MailRecipient.Email))
                    {
                        messageItem.DeleteProperties(new PropertyDefinition[]
                        {
                            StoreObjectSchema.PolicyTag,
                            StoreObjectSchema.ArchiveTag,
                            ItemSchema.RetentionDate,
                            ItemSchema.ArchiveDate
                        });
                        UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "OnCreatedMessageHandler: MessageId {0}, Sender {1}: Deleted Retention Policy Guids", text, arg);
                    }
                    messageItem[ItemSchema.EHAMigrationExpiryDate] = exDateTime;
                    UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "OnCreatedMessageHandler: MessageId {0}, Sender {1}: Stamped migration date", text, arg);
                }
            }
        }
Example #29
0
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            WorkingSetAgent.tracer.TraceDebug((long)this.traceId, "WorkingSetAgent.OnPromotedMessageHandler: entering");
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = args as StoreDriverDeliveryEventArgsImpl;

            if (storeDriverDeliveryEventArgsImpl == null)
            {
                WorkingSetAgent.tracer.TraceError((long)this.traceId, "WorkingSetAgent.OnPromotedMessageHandler: args is null or not a StoreDriverDeliveryEventArgsImpl; exiting");
                return;
            }
            if (!this.Validate(storeDriverDeliveryEventArgsImpl))
            {
                return;
            }
            string arg = storeDriverDeliveryEventArgsImpl.MailboxSession.MdbGuid.ToString();

            WorkingSetAgent.tracer.TraceDebug <string>((long)this.traceId, "WorkingSetAgent.OnPromotedMessageHandler: mdbGuid is {0}", arg);
            WorkingSetAgentPerfLogging logger = new WorkingSetAgentPerfLogging();
            DateTime utcNow = DateTime.UtcNow;
            bool     workingSetSignalMailProcessed = false;

            try
            {
                WorkingSet.ProcessingAccepted.Increment();
                using (new StopwatchPerformanceTracker("OnPromotedMessageHandler", logger))
                {
                    using (new CpuPerformanceTracker("OnPromotedMessageHandler", logger))
                    {
                        using (new StorePerformanceTracker("OnPromotedMessageHandler", logger))
                        {
                            this.Process(storeDriverDeliveryEventArgsImpl);
                            workingSetSignalMailProcessed = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is OutOfMemoryException || ex is StackOverflowException || ex is ThreadAbortException)
                {
                    throw;
                }
                if (ex is SmtpResponseException)
                {
                    workingSetSignalMailProcessed = true;
                    throw;
                }
                WorkingSetAgent.tracer.TraceError <Exception>((long)this.traceId, "WorkingSetAgent.OnPromotedMessageHandler encountered an exception: {0}", ex);
                StoreDriverDeliveryDiagnostics.LogEvent(MailboxTransportEventLogConstants.Tuple_WorkingSetAgentException, ex.Message, new object[]
                {
                    ex
                });
                storeDriverDeliveryEventArgsImpl.MailRecipient.DsnRequested = DsnRequestedFlags.Never;
                throw new SmtpResponseException(WorkingSetAgent.UnprocessedSignalMailResponse, base.Name);
            }
            finally
            {
                this.UpdatePerfCounters(utcNow, workingSetSignalMailProcessed, logger);
                WorkingSetAgent.tracer.TraceDebug((long)this.traceId, "WorkingSetAgent.OnPromotedMessageHandler: exiting");
            }
        }
Example #30
0
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            this.wasMessageDelivered = false;
            this.logValues           = null;
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;
            Stopwatch                    stopwatch                    = Stopwatch.StartNew();
            InferencePropertyBag         inferencePropertyBag         = new InferencePropertyBag();
            MdbDocument                  mdbDocument                  = null;
            VariantConfigurationSnapshot variantConfigurationSnapshot = null;

            try
            {
                InferenceClassificationAgent.tracer.TraceDebug(0L, "Called InferenceClassificationAgent.OnPromotedMessageHandler");
                inferencePropertyBag.Add(InferenceSchema.MessageClassificationTime, ExDateTime.UtcNow);
                inferencePropertyBag.Add(InferenceSchema.ServerName, this.server.Name);
                if (storeDriverDeliveryEventArgsImpl.MailboxSession != null)
                {
                    inferencePropertyBag.Add(DocumentSchema.MailboxId, storeDriverDeliveryEventArgsImpl.MailboxSession.MailboxGuid.ToString());
                    inferencePropertyBag.Add(InferenceSchema.ClutterEnabled, storeDriverDeliveryEventArgsImpl.MailboxSession.Mailbox.GetValueOrDefault <bool>(MailboxSchema.InferenceClutterEnabled, false));
                    inferencePropertyBag.Add(InferenceSchema.ClassificationEnabled, storeDriverDeliveryEventArgsImpl.MailboxSession.Mailbox.GetValueOrDefault <bool>(MailboxSchema.InferenceClassificationEnabled, false));
                    inferencePropertyBag.Add(InferenceSchema.HasBeenClutterInvited, storeDriverDeliveryEventArgsImpl.MailboxSession.Mailbox.GetValueOrDefault <bool>(MailboxSchema.InferenceHasBeenClutterInvited, false));
                }
                inferencePropertyBag.Add(InferenceSchema.InternetMessageId, storeDriverDeliveryEventArgsImpl.ReplayItem.InternetMessageId);
                inferencePropertyBag.Add(InferenceSchema.Locale, InferenceClassificationAgent.GetLocale(storeDriverDeliveryEventArgsImpl));
                if (storeDriverDeliveryEventArgsImpl.MailboxOwner != null && storeDriverDeliveryEventArgsImpl.MailboxOwner.OrganizationId != null && storeDriverDeliveryEventArgsImpl.MailboxOwner.OrganizationId.OrganizationalUnit != null)
                {
                    inferencePropertyBag.Add(InferenceSchema.TenantName, storeDriverDeliveryEventArgsImpl.MailboxOwner.OrganizationId.OrganizationalUnit.Name);
                }
                if (!InferenceClassificationAgent.IsMailboxInteresting(storeDriverDeliveryEventArgsImpl))
                {
                    inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped);
                    inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "MailboxNotInteresting");
                }
                else if (!InferenceClassificationAgent.IsMessageInteresting(storeDriverDeliveryEventArgsImpl))
                {
                    inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped);
                    inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "MessageNotInteresting");
                }
                else
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies = (storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies ?? new Dictionary <PropertyDefinition, object>());
                    Guid guid = Guid.NewGuid();
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[MessageItemSchema.InferenceMessageIdentifier] = guid;
                    inferencePropertyBag.Add(InferenceSchema.MessageIdentifier, guid);
                    variantConfigurationSnapshot = FlightModule.GetFlightFeatures(storeDriverDeliveryEventArgsImpl.MailboxOwner);
                    if (variantConfigurationSnapshot != null)
                    {
                        inferencePropertyBag.Add(InferenceSchema.UserFlightFeatures, variantConfigurationSnapshot);
                    }
                    IDeliveryClassificationStrategy deliveryClassificationStrategy = ClassificationStrategyFactory.Create(storeDriverDeliveryEventArgsImpl.MailboxSession, variantConfigurationSnapshot);
                    inferencePropertyBag.Add(InferenceSchema.IsUiEnabled, deliveryClassificationStrategy != null);
                    OriginalDeliveryFolderInfo originalDeliveryFolderInfo = InferenceClassificationAgent.GetOriginalDeliveryFolderInfo(storeDriverDeliveryEventArgsImpl);
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.OriginalDeliveryFolderInfo] = originalDeliveryFolderInfo.Serialize();
                    inferencePropertyBag.Add(InferenceSchema.OriginalDeliveryFolder, originalDeliveryFolderInfo);
                    if (!InferenceClassificationAgent.IsDeliveryFolderInteresting(originalDeliveryFolderInfo))
                    {
                        inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Skipped);
                        inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "DeliveryFolderNotInteresting");
                    }
                    else if (!this.isPipelineEnabled)
                    {
                        inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Failed);
                        inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "PipelineDisabled");
                        InferenceClassificationProcessing.NumberOfItemsSkippedDueToDisabledPipeline.Increment();
                    }
                    else
                    {
                        ConversationClutterInformation conversationClutterInformation = null;
                        bool flag = false;
                        InferenceClassificationResult inferenceClassificationResult = InferenceClassificationResult.None;
                        if (this.RunClassificationPipeline(storeDriverDeliveryEventArgsImpl, inferencePropertyBag, variantConfigurationSnapshot, out mdbDocument, out flag, out conversationClutterInformation))
                        {
                            if (flag)
                            {
                                inferenceClassificationResult |= InferenceClassificationResult.IsClutterModel;
                            }
                            string value = string.Empty;
                            bool   flag2 = false;
                            bool   flag3;
                            InferenceClassificationResult inferenceClassificationResult2;
                            string text;
                            bool   flag4;
                            if (InferenceClassificationAgent.CheckForRuleAndConversationOverrides(storeDriverDeliveryEventArgsImpl.SharedPropertiesBetweenAgents, originalDeliveryFolderInfo, out flag3, out inferenceClassificationResult2, out text, out flag4))
                            {
                                flag  = flag3;
                                value = text;
                            }
                            inferenceClassificationResult |= inferenceClassificationResult2;
                            if (flag4 && conversationClutterInformation != null)
                            {
                                flag = conversationClutterInformation.IsNewMessageClutter(flag, out flag2);
                            }
                            inferencePropertyBag.Add(InferenceSchema.IsClutter, flag);
                            if (flag)
                            {
                                inferenceClassificationResult |= InferenceClassificationResult.IsClutterFinal;
                            }
                            if (deliveryClassificationStrategy != null)
                            {
                                deliveryClassificationStrategy.ApplyClassification(storeDriverDeliveryEventArgsImpl, inferenceClassificationResult);
                                if (flag2 && conversationClutterInformation != null)
                                {
                                    conversationClutterInformation.MarkItemsAsNotClutter();
                                }
                            }
                            storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.InferenceClassificationResult] = inferenceClassificationResult;
                            inferencePropertyBag.Add(InferenceSchema.InferenceClassificationResult, inferenceClassificationResult);
                            inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Succeeded);
                            inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is OutOfMemoryException || ex is StackOverflowException || ex is ThreadAbortException)
                {
                    throw;
                }
                Exception innerException = ex.InnerException;
                if (innerException is StorageTransientException)
                {
                    InferenceClassificationProcessing.NumberOfTransientExceptions.Increment();
                }
                else if (innerException is QuotaExceededException)
                {
                    InferenceClassificationProcessing.NumberOfQuotaExceededExceptions.Increment();
                }
                this.diagnosticsSession.LogDiagnosticsInfo(DiagnosticsLoggingTag.Failures, "Received exception {0}", new object[]
                {
                    ex
                });
                inferencePropertyBag.Add(InferenceSchema.ClassificationStatus, InferenceClassificationAgentLogger.Status.Failed);
                inferencePropertyBag.Add(InferenceSchema.ClassificationStatusMessage, "Exception");
                inferencePropertyBag.Add(InferenceSchema.ClassificationAgentException, ex);
            }
            finally
            {
                stopwatch.Stop();
                InferenceClassificationAgent.tracer.TraceDebug <long>((long)this.GetHashCode(), "InferenceClassification agent took {0} ms to process the item.", stopwatch.ElapsedMilliseconds);
                inferencePropertyBag.Add(InferenceSchema.TimeTakenToClassify, stopwatch.ElapsedMilliseconds);
                if (storeDriverDeliveryEventArgsImpl.MailboxSession != null)
                {
                    InferenceClassificationAgent.RecordPerformanceCounter(storeDriverDeliveryEventArgsImpl.MailboxSession.MdbGuid.ToString(), stopwatch.ElapsedMilliseconds);
                }
                InferenceClassificationTracking inferenceClassificationTracking = InferenceClassificationTracking.Create();
                this.logValues = this.classificationAgentLogger.ExtractClassificationProperties(inferencePropertyBag, mdbDocument, inferenceClassificationTracking);
                if (variantConfigurationSnapshot != null && variantConfigurationSnapshot.Inference.InferenceStampTracking.Enabled)
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[MessageItemSchema.InferenceClassificationTrackingEx] = inferenceClassificationTracking.ToString();
                }
                if (mdbDocument != null)
                {
                    mdbDocument.Dispose();
                    mdbDocument = null;
                }
            }
        }