private bool ShouldProcessRuleInTransport(StoreDriverDeliveryEventArgsImpl deliveryEventArguments)
        {
            MailboxSession     mailboxSession = deliveryEventArguments.MailboxSession;
            IExchangePrincipal mailboxOwner   = mailboxSession.MailboxOwner;
            int serverVersion = mailboxOwner.MailboxInfo.Location.ServerVersion;

            if (serverVersion < Server.E14MinVersion)
            {
                this.evaluationContext.TraceDebug <int>("Will not process rules in transport for old server with version number {0}.", serverVersion);
                return(false);
            }
            if (string.IsNullOrEmpty(mailboxOwner.MailboxInfo.Location.ServerFqdn))
            {
                this.evaluationContext.TraceError("Server Fqdn is empty.");
                return(false);
            }
            DeliverableMailItem mailItem = deliveryEventArguments.MailItem;
            Header header  = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Unjournal-Processed");
            Header header2 = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Unjournal-ProcessedNdr");

            if (header != null || header2 != null)
            {
                this.evaluationContext.TraceError("This is an unwrapped message from legacy archive journals {0},{1}.");
                return(false);
            }
            if (MailboxRulesAgent.IsJournalNdrWithSkipRulesStamped(mailItem))
            {
                this.evaluationContext.TraceError("Message is destined to journal ndr mailbox. We dont journal messages to journal ndr mailbox as there is a potential of a loop PS 685340, skipping.");
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
 private bool IsSenderARecipient(DeliverableMailItem mailItem, string messageId)
 {
     if (mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.SenderIsRecipient) == null)
     {
         UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "IsSenderARecipient: MessageId {0}, Sender {1}, Sender is not the recipient", messageId, mailItem.FromAddress.ToString());
         return(false);
     }
     UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "IsSenderARecipient: MessageId {0}, Sender {1}, Sender is a recipient", messageId, mailItem.FromAddress.ToString());
     return(true);
 }
Esempio n. 3
0
 private bool IsSourceEhaMigration(DeliverableMailItem mailItem, string messageId)
 {
     if (mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.MessageOriginalDate) == null)
     {
         UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "IsSourceEhaMigration: MessageId {0}, Sender {1}, Header '{2}' not found.", messageId, mailItem.FromAddress.ToString(), UnJournalAgent.UnjournalHeaders.MessageOriginalDate);
         return(false);
     }
     UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "IsSourceEhaMigration: MessageId {0}, Sender {1}, Header '{2}' found.", messageId, mailItem.FromAddress.ToString(), UnJournalAgent.UnjournalHeaders.MessageOriginalDate);
     return(true);
 }
Esempio n. 4
0
        private bool IsProcessedByUnJournalAgentForNdr(DeliverableMailItem mailItem, string messageId)
        {
            Header header  = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.ProcessedByUnjournal);
            Header header2 = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.ProcessedByUnjournalForNdr);

            if (header == null && header2 != null)
            {
                UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "IsSourceEhaMigration: MessageId {0}, Sender {1}, This is a journal report targeted for journal ndr mailbox", messageId, mailItem.FromAddress.ToString());
                return(true);
            }
            UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "IsSourceEhaMigration: MessageId {0}, Sender {1}, This is NOT a journal ndr report targeted for journal ndr mailbox", messageId, mailItem.FromAddress.ToString());
            return(false);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private StoreId GetSentItemsFolderIdBySource(DeliverableMailItem mailItem, string messageId, MailboxSession session)
        {
            if (this.IsSourceEhaMigration(mailItem, messageId))
            {
                return(this.GetCreateFolderIdUnderGivenParentFolder("MigrationFolder", DefaultFolderType.SentItems.ToString(), session));
            }
            StoreId storeId = session.GetDefaultFolderId(DefaultFolderType.SentItems);

            if (storeId == null)
            {
                storeId = session.CreateDefaultFolder(DefaultFolderType.SentItems);
            }
            return(storeId);
        }
Esempio n. 7
0
        private bool TryGetExpiryDateForMigratedMessage(DeliverableMailItem mailItem, out ExDateTime migrationExpiryDate)
        {
            migrationExpiryDate = ExDateTime.MaxValue;
            Header header = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.MessageExpiryDate);

            if (header != null)
            {
                string value = header.Value;
                if (!string.IsNullOrEmpty(value))
                {
                    return(ExDateTime.TryParse(value, out migrationExpiryDate));
                }
            }
            return(false);
        }
Esempio n. 8
0
        internal override void Invoke(string eventTopic, object source, object e)
        {
            Delegate @delegate = (Delegate)base.Handlers[eventTopic];

            if (@delegate == null)
            {
                return;
            }
            DeliverableMailItem mailItem = DeliveryAgent.GetMailItem(e);

            if (mailItem != null)
            {
                ((SmtpServer)this.HostState).AddressBook.RecipientCache = mailItem.RecipientCache;
            }
            if (eventTopic != null)
            {
                if (!(eventTopic == "OnOpenConnection"))
                {
                    if (!(eventTopic == "OnDeliverMailItem"))
                    {
                        if (!(eventTopic == "OnCloseConnection"))
                        {
                            goto IL_B4;
                        }
                        ((CloseConnectionEventHandler)@delegate)((CloseConnectionEventSource)source, (CloseConnectionEventArgs)e);
                    }
                    else
                    {
                        ((DeliverMailItemEventHandler)@delegate)((DeliverMailItemEventSource)source, (DeliverMailItemEventArgs)e);
                    }
                }
                else
                {
                    ((OpenConnectionEventHandler)@delegate)((OpenConnectionEventSource)source, (OpenConnectionEventArgs)e);
                }
                if (base.Synchronous)
                {
                    this.Cleanup();
                }
                return;
            }
IL_B4:
            throw new InvalidOperationException("Internal error: unsupported event topic: " + (eventTopic ?? "null"));
        }
Esempio n. 9
0
        private bool IsLegacyArchiveJournalingEnabled(OrganizationId orgId, DeliverableMailItem mailItem, string messageId)
        {
            string text = mailItem.FromAddress.ToString();
            PerTenantTransportSettings tenantConfig = this.GetTenantConfig(orgId, messageId, text);

            if (tenantConfig != null)
            {
                UnJournalAgent.Tracer.TraceDebug(0L, "IsLegacyArchiveJournalingEnabled: MessageId {0}, Invoked, Sender {1}, Legacy archive journaling setting for organization {2} is set to {3}", new object[]
                {
                    messageId,
                    text,
                    orgId,
                    tenantConfig.LegacyArchiveJournalingEnabled
                });
                return(tenantConfig.LegacyArchiveJournalingEnabled || tenantConfig.LegacyArchiveLiveJournalingEnabled || tenantConfig.JournalArchivingEnabled);
            }
            UnJournalAgent.Tracer.TraceDebug <string, string, OrganizationId>(0L, "IsLegacyArchiveJournalingEnabled: MessageId {0}, Invoked, Sender {1}, Legacy archive journaling setting for organization {2} not found", messageId, text, orgId);
            return(false);
        }
Esempio n. 10
0
        private bool IsParkingRequired(StoreDriverDeliveryEventArgsImpl args, out MeetingSeriesMessageOrderingAgent.SeriesHeadersData headersData, out bool canBeParked)
        {
            DeliverableMailItem mailItem = args.MailItem;
            HeaderList          headers  = mailItem.Message.MimeDocument.RootPart.Headers;

            headersData = MeetingSeriesMessageOrderingAgent.SeriesHeadersData.FromHeaderList(headers, args.MailItemDeliver.MbxTransportMailItem.NetworkMessageId);
            bool flag = !string.IsNullOrEmpty(headersData.SeriesId);

            canBeParked = (flag && this.CanMessageBeParked(args.MessageClass));
            if (headersData.UnparkedMessage || !flag)
            {
                return(false);
            }
            MailboxSession mailboxSession = args.MailboxSession;

            if (headersData.SeriesSequenceNumber > 0 && headersData.InstanceGoid != null && headersData.MasterGoid != null)
            {
                StoreId storeId;
                if (!this.MasterMessageArrived(mailboxSession, headersData, out storeId))
                {
                    return(true);
                }
                if (storeId != null)
                {
                    this.CacheInstanceId(headers, storeId);
                }
            }
            else if (MeetingSeriesMessageOrderingAgent.tracer.IsTraceEnabled(TraceType.WarningTrace))
            {
                MeetingSeriesMessageOrderingAgent.tracer.TraceWarning((long)this.GetHashCode(), "Series instance message is missing required information to be used for ordering detection. Mailbox = {0}, messageId = {1}, seriesId = {2}, SSN = {3}, instanceGoid = {4}, masterGoid = {5}", new object[]
                {
                    mailboxSession.MailboxOwnerLegacyDN,
                    mailItem.Message.MessageId,
                    headersData.SeriesId,
                    headersData.SeriesSequenceNumber,
                    (headersData.InstanceGoid != null) ? Convert.ToBase64String(headersData.InstanceGoid) : string.Empty,
                    (headersData.MasterGoid != null) ? Convert.ToBase64String(headersData.MasterGoid) : string.Empty
                });
            }
            return(false);
        }
Esempio n. 11
0
        private bool IsProcessedByUnJournalAgent(DeliverableMailItem mailItem, string messageId)
        {
            string text = mailItem.FromAddress.ToString();

            UnJournalAgent.Tracer.TraceDebug <string, string>(0L, "IsProcessedByUnJournalAgent: MessageId {0}, Invoked, Sender {1}", messageId, text);
            Header header  = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.ProcessedByUnjournal);
            Header header2 = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.ProcessedByUnjournalForNdr);

            if (header != null && header2 == null)
            {
                UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "IsProcessedByUnJournalAgent: MessageId {0}, Sender {1}, Able to find '{2}' header on mailItem", messageId, text, UnJournalAgent.UnjournalHeaders.ProcessedByUnjournal);
                return(true);
            }
            UnJournalAgent.Tracer.TraceDebug(0L, "IsProcessedByUnJournalAgent: MessageId {0}, Sender {1}, processedByUnjournal value {2}, processedByUnjournalAgentForNdrHeader value {3}", new object[]
            {
                messageId,
                text,
                (header == null) ? "null" : header.ToString(),
                (header2 == null) ? "null" : header2.ToString()
            });
            return(false);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        private bool TryGetOriginalDateForMigratedMessage(DeliverableMailItem mailItem, out ExDateTime migrationDate, string messageId)
        {
            migrationDate = ExDateTime.MinValue;
            Header header = mailItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.MessageOriginalDate);

            if (header != null)
            {
                string value = header.Value;
                if (!string.IsNullOrEmpty(value))
                {
                    UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "TryGetOriginalDateForMigratedMessage: MessageId {0}, Sender {1}, Original message date found : {2}", messageId, mailItem.FromAddress.ToString(), value);
                    if (ExDateTime.TryParse(value, out migrationDate))
                    {
                        UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "TryGetOriginalDateForMigratedMessage: MessageId {0}, Sender {1}, Original message date parsed successfully: {2}", messageId, mailItem.FromAddress.ToString(), migrationDate.ToString());
                        return(true);
                    }
                    UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "TryGetOriginalDateForMigratedMessage: MessageId {0}, Sender {1}, Unable to parse original message date from the string: {2}", messageId, mailItem.FromAddress.ToString(), value);
                    return(false);
                }
                else
                {
                    UnJournalAgent.Tracer.TraceDebug(0L, "TryGetOriginalDateForMigratedMessage: MessageId {0}, Sender {1}, Original message receive date is empty , {2} header found , header value is {3}", new object[]
                    {
                        messageId,
                        mailItem.FromAddress.ToString(),
                        UnJournalAgent.UnjournalHeaders.MessageOriginalDate,
                        value
                    });
                }
            }
            else
            {
                UnJournalAgent.Tracer.TraceDebug <string, string, string>(0L, "TryGetOriginalDateForMigratedMessage: MessageId {0}, Sender {1}, Original receive date header not found : header name is  {2}", messageId, mailItem.FromAddress.ToString(), UnJournalAgent.UnjournalHeaders.MessageOriginalDate);
            }
            return(false);
        }
 public EmailItem(DeliverableMailItem mailItem)
     : this(mailItem, mailItem.Message, mailItem.FromAddress, mailItem.GetMimeReadStream())
 {
 }
 public EmailItem(DeliverableMailItem mailItem)
     : this(mailItem, mailItem.Message, mailItem.FromAddress, mailItem.GetMimeReadStream())
 {
 }
Esempio n. 17
0
 private static bool IsJournalNdrWithSkipRulesStamped(DeliverableMailItem mailItem)
 {
     return(null != mailItem.Message.MimeDocument.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-JournalNdr-Skip-TransportMailboxRules"));
 }
Esempio n. 18
0
 private bool IsEHAMigrationMeetingMessage(DeliverableMailItem messageItem)
 {
     return(messageItem.Message.MimeDocument.RootPart.Headers.FindFirst(UnJournalAgent.UnjournalHeaders.MessageOriginalDate) != null);
 }
Esempio n. 19
0
 private bool ShouldProcessWithNdrCheck(OrganizationId orgId, DeliverableMailItem mailItem, string messageId)
 {
     UnJournalAgent.Tracer.TraceDebug <string>(0L, "IsProcessedByUnJournalAgent: MessageId {0}, Invoked ShouldProcess", messageId);
     return(this.IsLegacyArchiveJournalingEnabled(orgId, mailItem, messageId) && this.IsProcessedByUnJournalAgentForNdr(mailItem, messageId));
 }