示例#1
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);
        }
示例#2
0
 public static EmailMessage GenerateContentReport(SmtpAddress arbitrationAddress, SmtpAddress reportToAddress, StoreSession session, bool isArbitration)
 {
     if (arbitrationAddress.IsValidAddress && reportToAddress.IsValidAddress)
     {
         EmailMessage   emailMessage = EmailMessage.Create();
         RoutingAddress address      = GlobalConfigurationBase <MicrosoftExchangeRecipient, MicrosoftExchangeRecipientConfiguration> .Instance.Address;
         emailMessage.From = new EmailRecipient(null, (string)address);
         emailMessage.To.Add(new EmailRecipient(null, (string)reportToAddress));
         emailMessage.Subject = "Arbitration Mailbox Content Report: " + arbitrationAddress.ToString();
         using (Stream contentWriteStream = emailMessage.Body.GetContentWriteStream())
         {
             using (StreamWriter streamWriter = new StreamWriter(contentWriteStream))
             {
                 if (!isArbitration)
                 {
                     streamWriter.WriteLine("This mailbox is not an approval arbitration mailbox. This report is only generated for approval arbitration mailboxes.");
                     return(emailMessage);
                 }
                 Attachment attachment = emailMessage.Attachments.Add("formattedDetails.txt");
                 using (Stream contentWriteStream2 = attachment.GetContentWriteStream())
                 {
                     using (Folder folder = Folder.Bind((MailboxSession)session, DefaultFolderType.Inbox))
                     {
                         using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, null, new PropertyDefinition[]
                         {
                             ItemSchema.Id
                         }))
                         {
                             object[][] rows = queryResult.GetRows(10000);
                             int        num  = 0;
                             int        num2 = 0;
                             TimeSpan   t    = default(TimeSpan);
                             TimeSpan   t2   = default(TimeSpan);
                             while (rows != null && rows.Length > 0)
                             {
                                 foreach (object[] array2 in rows)
                                 {
                                     StoreObjectId objectId = ((VersionedId)array2[0]).ObjectId;
                                     using (MessageItem messageItem = MessageItem.Bind(session, objectId, ArbitrationMailboxReport.ApprovalProperties))
                                     {
                                         string         valueOrDefault   = messageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalRequestor);
                                         string         valueOrDefault2  = messageItem.GetValueOrDefault <string>(ItemSchema.DisplayCc);
                                         string         valueOrDefault3  = messageItem.GetValueOrDefault <string>(ItemSchema.Subject);
                                         string         valueOrDefault4  = messageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalAllowedDecisionMakers);
                                         string         valueOrDefault5  = messageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalDecisionMakersNdred);
                                         string         valueOrDefault6  = messageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalRequestMessageId);
                                         string         valueOrDefault7  = messageItem.GetValueOrDefault <string>(ItemSchema.InternetMessageId);
                                         string         valueOrDefault8  = messageItem.GetValueOrDefault <string>(ItemSchema.InternetReferences);
                                         string         valueOrDefault9  = messageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalDecisionMaker);
                                         ApprovalStatus?valueAsNullable  = messageItem.GetValueAsNullable <ApprovalStatus>(MessageItemSchema.ApprovalStatus);
                                         ExDateTime?    valueAsNullable2 = messageItem.GetValueAsNullable <ExDateTime>(MessageItemSchema.ApprovalDecisionTime);
                                         ExDateTime?    valueAsNullable3 = messageItem.GetValueAsNullable <ExDateTime>(ItemSchema.ReceivedTime);
                                         ExDateTime?    valueAsNullable4 = messageItem.GetValueAsNullable <ExDateTime>(ItemSchema.RetentionDate);
                                         if (valueAsNullable3 != null)
                                         {
                                             if (valueAsNullable2 == null)
                                             {
                                                 ExDateTime utcNow = ExDateTime.UtcNow;
                                                 t2 += utcNow - valueAsNullable3.Value;
                                                 num2++;
                                             }
                                             else if (valueAsNullable3 <= valueAsNullable2)
                                             {
                                                 t += valueAsNullable2.Value - valueAsNullable3.Value;
                                                 num++;
                                             }
                                         }
                                         streamWriter.WriteLine("Initiation Message ID:" + valueOrDefault7);
                                         streamWriter.WriteLine("Original Message ID:" + valueOrDefault8);
                                         streamWriter.WriteLine("Sender:" + valueOrDefault);
                                         streamWriter.WriteLine("Moderated Recipient Addresses:" + valueOrDefault2);
                                         streamWriter.WriteLine("Message Subject:" + valueOrDefault3);
                                         streamWriter.WriteLine("Moderators:" + valueOrDefault4);
                                         streamWriter.WriteLine("Moderators (total; not delivered; away):" + valueOrDefault5);
                                         streamWriter.WriteLine("Approval Request Message ID:" + valueOrDefault6);
                                         streamWriter.WriteLine("Decision maker:" + valueOrDefault9);
                                         streamWriter.WriteLine("Decision status:" + valueAsNullable);
                                         streamWriter.WriteLine("Decision Time:" + valueAsNullable2);
                                         streamWriter.WriteLine("Received Time:" + valueAsNullable3);
                                         streamWriter.WriteLine("Expiry Time:" + valueAsNullable4);
                                         streamWriter.WriteLine();
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault7);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault8);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault2);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault3);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault4);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault5);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault6);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault9);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueAsNullable);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueOrDefault6);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueAsNullable2);
                                         ArbitrationMailboxReport.CheckAndWrite(contentWriteStream2, valueAsNullable3);
                                         Utf8Csv.EncodeEscapeAndWriteLine(contentWriteStream2, (valueAsNullable4 != null) ? valueAsNullable4.ToString() : string.Empty);
                                     }
                                 }
                                 rows = queryResult.GetRows(10000);
                             }
                             streamWriter.WriteLine("Summary:");
                             streamWriter.WriteLine("Messages with a decision:" + num);
                             if (num > 0)
                             {
                                 streamWriter.WriteLine("Average decision time:" + TimeSpan.FromSeconds(t.TotalSeconds / (double)num));
                             }
                             streamWriter.WriteLine("Messages without a decision:" + num2);
                             if (num2 > 0)
                             {
                                 streamWriter.WriteLine("Average waiting time:" + TimeSpan.FromSeconds(t2.TotalSeconds / (double)num2));
                             }
                         }
                     }
                 }
                 return(emailMessage);
             }
         }
     }
     return(null);
 }