private bool IsJournalReport(MbxTransportMailItem mailItem) { if (mailItem != null && mailItem.RootPart != null) { Header header = mailItem.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Journal-Report"); return(header != null); } return(false); }
public void Send(string messageId, byte[] corelationBlob, MbxTransportMailItem mbxTransportMailItem) { this.messageItem.VotingInfo.MessageCorrelationBlob = corelationBlob; this.messageItem.ClassName = "IPM.Note.Microsoft.Approval.Request"; this.messageItem.InternetMessageId = messageId; this.messageItem.Save(SaveMode.NoConflictResolution); using (MemorySubmissionItem memorySubmissionItem = new MemorySubmissionItem(this.messageItem, this.organizationId)) { memorySubmissionItem.Submit(MessageTrackingSource.APPROVAL, new MemorySubmissionItem.OnConvertedToTransportMailItemDelegate(this.TransportMailItemHandler), mbxTransportMailItem); } }
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); }
private bool TryGetDeliveryFolderId(MbxTransportMailItem rmi, MailboxSession mailBoxSession, out StoreId deliveryFolderId) { deliveryFolderId = null; string textHeaderValue = ContentAggregationAgentFactory.ContentAggregationAgent.GetTextHeaderValue(rmi, "X-MS-Exchange-Organization-DeliveryFolder"); if (string.IsNullOrEmpty(textHeaderValue)) { ExTraceGlobals.DeliveryAgentTracer.TraceDebug(rmi.RecordId, "Delivery Folder ID property is empty."); return(false); } byte[] array = null; try { array = HexConverter.HexStringToByteArray(textHeaderValue); } catch (FormatException arg) { ExTraceGlobals.DeliveryAgentTracer.TraceError <FormatException>(rmi.RecordId, "Could not get Delivery Folder ID due to an invalid Mail Item header - Exception: {0}", arg); return(false); } if (!IdConverter.IsFolderId(array)) { ExTraceGlobals.DeliveryAgentTracer.TraceError <string>(rmi.RecordId, "Can't open folder, id {0} is not a valid Exchange folder entry id.", array.ToString()); return(false); } try { deliveryFolderId = StoreObjectId.FromProviderSpecificId(array); } catch (ArgumentException arg2) { ExTraceGlobals.DeliveryAgentTracer.TraceError <ArgumentException>(rmi.RecordId, "Could not get Delivery Folder ID. Can't convert header value to StoreObjectId - Exception: {0}", arg2); return(false); } bool result; try { using (Folder.Bind(mailBoxSession, deliveryFolderId)) { result = true; } } catch (ObjectNotFoundException arg3) { ExTraceGlobals.DeliveryAgentTracer.TraceError <StoreId, ObjectNotFoundException>(rmi.RecordId, "Can't open folder. Folder id {0} does not exist - Exception: {1}", deliveryFolderId, arg3); result = false; } return(result); }
internal InitiationProcessor(MbxTransportMailItem mbxTransportMailItem, InitiationMessage initiationMessage, MessageItem initiationMessageItem, ApprovalEngine.ApprovalRequestCreateDelegate requestCreate, RoutingAddress approvalRequestSender) { this.mbxTransportMailItem = mbxTransportMailItem; this.initiationMessage = initiationMessage; this.initiationMessageItem = initiationMessageItem; this.requestCreate = requestCreate; this.approvalRequestSender = approvalRequestSender; CultureInfo internalDsnDefaultLanguage = this.mbxTransportMailItem.TransportSettings.InternalDsnDefaultLanguage; if (internalDsnDefaultLanguage == null || !ClientCultures.IsCultureSupportedForDsn(internalDsnDefaultLanguage)) { this.organizationFallbackCulture = InitiationProcessor.DefaultFallBackCulture; return; } this.organizationFallbackCulture = internalDsnDefaultLanguage; }
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); }
private static string GetTextHeaderValue(MbxTransportMailItem rmi, string headerName) { TextHeader textHeader = rmi.RootPart.Headers.FindFirst(headerName) as TextHeader; if (textHeader == null) { ExTraceGlobals.DeliveryAgentTracer.TraceDebug <string>(rmi.RecordId, "Header not found: {0}", headerName); return(null); } DecodingResults decodingResults; string result; if (!textHeader.TryGetValue(DecodingOptions.None, out decodingResults, out result)) { ExTraceGlobals.DeliveryAgentTracer.TraceDebug <string>(rmi.RecordId, "Could not decode the header value for header: {0}", headerName); return(null); } return(result); }
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); }
private static Guid?GetGuidHeaderValue(MbxTransportMailItem rmi, string headerName) { string textHeaderValue = ContentAggregationAgentFactory.ContentAggregationAgent.GetTextHeaderValue(rmi, headerName); if (!string.IsNullOrEmpty(textHeaderValue)) { try { return(new Guid?(new Guid(textHeaderValue))); } catch (FormatException arg) { ExTraceGlobals.DeliveryAgentTracer.TraceError <FormatException>(rmi.RecordId, "Could not make into Guid due to FormatException: {0}", arg); } catch (OverflowException arg2) { ExTraceGlobals.DeliveryAgentTracer.TraceError <OverflowException>(rmi.RecordId, "Could not make into Guid due to OverflowException: {0}", arg2); } } ExTraceGlobals.DeliveryAgentTracer.TraceDebug <string>(rmi.RecordId, "Header not found: {0}", headerName); return(null); }
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); } }
public static ApprovalEngine GetApprovalEngineInstance(EmailMessage incomingMessage, RoutingAddress sender, RoutingAddress recipient, MessageItem messageItem, MbxTransportMailItem mbxTransportMailItem, ApprovalEngine.ApprovalRequestCreateDelegate requestCreate) { return(new ApprovalEngine(incomingMessage, sender, recipient, messageItem, mbxTransportMailItem, requestCreate)); }
private ApprovalEngine(EmailMessage incomingMessage, RoutingAddress sender, RoutingAddress recipient, MessageItem messageItem, MbxTransportMailItem mbxTransportMailItem, ApprovalEngine.ApprovalRequestCreateDelegate requestCreate) { this.message = incomingMessage; this.sender = sender; this.recipient = recipient; this.requestCreate = requestCreate; this.messageItem = messageItem; this.mbxTransportMailItem = mbxTransportMailItem; }
private void SendNotifications(RoutingAddress from, RoutingAddress recipient, MbxTransportMailItem rmi, string threadIndex, string threadTopic, string existingDecisionMakerAddress, ApprovalStatus?existingApprovalStatus, ExDateTime?existingDecisionTime) { HeaderList headers = rmi.RootPart.Headers; Header acceptLanguageHeader = headers.FindFirst("Accept-Language"); Header contentLanguageHeader = headers.FindFirst(HeaderId.ContentLanguage); string decisionMakerDisplayName = existingDecisionMakerAddress; bool? flag = null; if (existingApprovalStatus != null) { if ((existingApprovalStatus.Value & ApprovalStatus.Approved) == ApprovalStatus.Approved) { flag = new bool?(true); } else if ((existingApprovalStatus.Value & ApprovalStatus.Rejected) == ApprovalStatus.Rejected) { flag = new bool?(false); } } if (!string.IsNullOrEmpty(existingDecisionMakerAddress)) { ADNotificationAdapter.TryRunADOperation(delegate() { IRecipientSession recipientSession = ApprovalProcessor.CreateRecipientSessionFromSmtpAddress(existingDecisionMakerAddress); ADRawEntry adrawEntry = recipientSession.FindByProxyAddress(new SmtpProxyAddress(existingDecisionMakerAddress, true), ApprovalProcessingAgent.DisplayNameProperty); if (adrawEntry != null) { string text = (string)adrawEntry[ADRecipientSchema.DisplayName]; if (!string.IsNullOrEmpty(text)) { decisionMakerDisplayName = text; } } }, 1); } ApprovalProcessingAgent.diag.TraceDebug <bool?, string>(0L, "Generating conflict notification. Decision='{0}', DecisionMaker='{1}'", flag, decisionMakerDisplayName); EmailMessage emailMessage = NotificationGenerator.GenerateDecisionNotTakenNotification(from, recipient, rmi.Subject, threadIndex, threadTopic, decisionMakerDisplayName, flag, existingDecisionTime, acceptLanguageHeader, contentLanguageHeader, rmi.TransportSettings.InternalDsnDefaultLanguage); if (emailMessage != null) { this.server.SubmitMessage(rmi, emailMessage, rmi.OrganizationId, rmi.ExternalOrganizationId, false); } }
private void HandleResults(ApprovalEngine.ApprovalProcessResults resultInfo, MessageItem messageItem, MbxTransportMailItem rmi, MailRecipient recipient) { if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationMessageOk) { messageItem.VotingInfo.MessageCorrelationBlob = resultInfo.ApprovalTrackingBlob; messageItem[MessageItemSchema.ApprovalRequestMessageId] = resultInfo.ApprovalRequestMessageId; messageItem[MessageItemSchema.ApprovalDecisionMakersNdred] = NdrOofHandler.FormatNdrOofProperty(resultInfo.TotalDecisionMakers, 0, 0); messageItem[MessageItemSchema.ApprovalStatus] = ApprovalStatus.Unhandled; this.perfCounter.InitiationMessages.Increment(); return; } if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.UnauthorizedMessage) { throw new SmtpResponseException(AckReason.ApprovalUnAuthorizedMessage); } if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationMessageDuplicate) { recipient.DsnRequested = DsnRequestedFlags.Never; throw new SmtpResponseException(AckReason.ApprovalDuplicateInitiation, base.Name); } if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.DecisionMarked) { this.perfCounter.DecisionUsed.Increment(); this.perfCounter.DecisionMessages.Increment(); this.perfCounter.DecisionInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds); recipient.DsnRequested = DsnRequestedFlags.Never; throw new SmtpResponseException(AckReason.ApprovalDecisionSuccsess, base.Name); } if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationNotFoundForDecision || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.DecisionAlreadyMade) { byte[] conversationIndex = messageItem.ConversationIndex; string threadIndex = Convert.ToBase64String(ConversationIndex.CreateFromParent(conversationIndex).ToByteArray()); this.SendNotifications(recipient.Email, (RoutingAddress)rmi.Message.Sender.SmtpAddress, rmi, threadIndex, messageItem.ConversationTopic, resultInfo.ExistingDecisionMakerAddress, resultInfo.ExistingApprovalStatus, resultInfo.ExistingDecisionTime); this.perfCounter.DecisionMessages.Increment(); this.perfCounter.DecisionInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds); recipient.DsnRequested = DsnRequestedFlags.Never; throw new SmtpResponseException(AckReason.ApprovalDecisionSuccsess, base.Name); } if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdated || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdateSkipped || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.InitiationNotFoundForNdrOrOof || resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofInvalid) { this.perfCounter.TotalNdrOofHandled.Increment(); if (resultInfo.ProcessResults != ApprovalEngine.ProcessResult.NdrOrOofInvalid) { this.perfCounter.TotalSearchesForInitiationBasedOnNdrAndOof.Increment(); this.perfCounter.NdrOofInitiationMessageSearchTimeMilliseconds.IncrementBy(resultInfo.InitiationMessageSearchTimeMilliseconds); } if (resultInfo.ProcessResults == ApprovalEngine.ProcessResult.NdrOrOofUpdated) { this.perfCounter.TotalNdrOofUpdated.Increment(); } recipient.DsnRequested = DsnRequestedFlags.Never; throw new SmtpResponseException(AckReason.ApprovalNdrOofUpdateSuccess, base.Name); } throw new SmtpResponseException(AckReason.ApprovalInvalidMessage); }
public static MessageItemApprovalRequest Create(MbxTransportMailItem mbxTransportMailItem) { MessageItem messageItem = MessageItem.CreateInMemory(MessageItemApprovalRequest.PrefetchProperties); return(new MessageItemApprovalRequest(messageItem, mbxTransportMailItem.OrganizationId)); }
public TransportGroupEscalation(MbxTransportMailItem mbxTransportMailItem, IXSOFactory xsoFactory, IGroupEscalationFlightInfo groupEscalationFlightInfo, IMailboxUrls mailboxUrls) : base(xsoFactory, groupEscalationFlightInfo, mailboxUrls) { this.mbxTransportMailItem = mbxTransportMailItem; }
private TestMessageConfig GetTestMessageConfig(StoreDriverDeliveryEventArgsImpl deliveryEventArguments) { MbxTransportMailItem mbxTransportMailItem = deliveryEventArguments.MailItemDeliver.MbxTransportMailItem; return(new TestMessageConfig(mbxTransportMailItem.Message)); }