public ApprovalEngine.ApprovalProcessResults Process() { MailboxSession mailboxSession = (MailboxSession)this.messageItem.Session; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox); VersionedId correlatedItem = this.messageItem.VotingInfo.GetCorrelatedItem(defaultFolderId); stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; if (correlatedItem == null) { DecisionHandler.diag.TraceDebug((long)this.GetHashCode(), "Initiation message not found"); return(new ApprovalEngine.ApprovalProcessResults(ApprovalEngine.ProcessResult.InitiationNotFoundForDecision, elapsedMilliseconds)); } string existingDecisionMakerAddress; ApprovalStatus? existingApprovalStatus; ExDateTime? existingDecisionTime; DecisionConflict conflict; if (DecisionHandler.ApproveTextList.Contains(this.messageItem.VotingInfo.Response)) { conflict = ApprovalProcessor.ApproveRequest(mailboxSession, correlatedItem.ObjectId, (SmtpAddress)this.sender, this.messageItem.Body, out existingDecisionMakerAddress, out existingApprovalStatus, out existingDecisionTime); } else { conflict = ApprovalProcessor.RejectRequest(mailboxSession, correlatedItem.ObjectId, (SmtpAddress)this.sender, this.messageItem.Body, out existingDecisionMakerAddress, out existingApprovalStatus, out existingDecisionTime); } return(DecisionHandler.GetApprovalProcessResults(conflict, existingDecisionMakerAddress, existingApprovalStatus, existingDecisionTime, elapsedMilliseconds)); }
public override bool WriteSubjectAndBody(MessageItemApprovalRequest approvalRequest, CultureInfo cultureInfo, out CultureInfo cultureInfoWritten) { approvalRequest.MessageItem.Subject = this.initiationMessage.Subject; cultureInfoWritten = null; int? messageItemLocale = this.initiationMessage.MessageItemLocale; string address = (string)this.initiationMessage.Requestor; string approvalData = this.initiationMessage.ApprovalData; if (string.IsNullOrEmpty(approvalData)) { return(false); } Culture culture = null; if (messageItemLocale != null && Culture.TryGetCulture(messageItemLocale.Value, out culture)) { cultureInfoWritten = culture.GetCultureInfo(); } else { cultureInfoWritten = cultureInfo; } string displayNameFromSmtpAddress = ApprovalProcessor.GetDisplayNameFromSmtpAddress(address); string group = ApprovalProcessor.ResolveDisplayNameForDistributionGroupFromApprovalData(approvalData, ApprovalProcessor.CreateRecipientSessionFromSmtpAddress(address)); string body = ApprovalProcessor.GenerateMessageBodyForRequestMessage(Strings.AutoGroupRequestHeader(displayNameFromSmtpAddress, group), Strings.AutoGroupRequestBody, LocalizedString.Empty, cultureInfoWritten); approvalRequest.SetBody(body); return(true); }
private void BulkQueueOperation(bool isJoin, bool isApprove) { if (this.DataObject.ArbitrationMailbox == null) { base.WriteError(new RecipientTaskException(Strings.ErrorArbitrationMailboxNotSet(this.Identity.ToString())), ExchangeErrorCategory.Client, this.Identity); } ADRecipient adrecipient = (ADRecipient)base.GetDataObject <ADRecipient>(new MailboxIdParameter(this.DataObject.ArbitrationMailbox), base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.DataObject.ArbitrationMailbox.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.DataObject.ArbitrationMailbox.ToString())), ExchangeErrorCategory.Client); if (adrecipient.RecipientTypeDetails != RecipientTypeDetails.ArbitrationMailbox) { base.WriteError(new RecipientTaskException(Strings.ErrorInvalidArbitrationMbxType(adrecipient.Identity.ToString())), ExchangeErrorCategory.Client, this.DataObject.Identity); } if (!adrecipient.IsValid) { base.WriteError(new RecipientTaskException(Strings.ErrorInvalidArbitrationMailbox(adrecipient.Identity.ToString())), ExchangeErrorCategory.Client, this.DataObject.Identity); } ADObjectId identity; if (!base.TryGetExecutingUserId(out identity)) { this.WriteWarning(Strings.WarningBulkOperationCannotDetermineRequester); return; } ADRecipient adrecipient2 = (ADRecipient)base.TenantGlobalCatalogSession.Read <ADRecipient>(identity); string text; if (isJoin) { text = AutoGroupApplication.BuildApprovalData("Add-DistributionGroupMember", this.DataObject.Id); } else { text = AutoGroupApplication.BuildApprovalData("Remove-DistributionGroupMember", this.DataObject.Id); } QueryFilter additionalFilter = new AndFilter(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, MessageItemSchema.ApprovalApplicationId, 0), new TextFilter(MessageItemSchema.ApprovalApplicationData, text, MatchOptions.FullString, MatchFlags.IgnoreCase) }); StoreObjectId[] array = ApprovalProcessor.QueryRequests(adrecipient.PrimarySmtpAddress, SmtpAddress.Empty, SmtpAddress.Empty, SmtpAddress.Empty, new ApprovalStatus?(ApprovalStatus.Unhandled), additionalFilter, null); if (array == null || array.Length == 0) { return; } foreach (StoreObjectId itemId in array) { if (isApprove) { ApprovalProcessor.ApproveRequest(adrecipient.PrimarySmtpAddress, itemId, adrecipient2.PrimarySmtpAddress, null); } else { ApprovalProcessor.RejectRequest(adrecipient.PrimarySmtpAddress, itemId, adrecipient2.PrimarySmtpAddress, null); } } }
public void SetBody(Body body) { BodyWriteConfiguration configuration = new BodyWriteConfiguration(this.GetXsoBodyFormat(body), body.CharsetName); Body body2 = this.messageItem.Body; using (Stream stream = body2.OpenWriteStream(configuration)) { using (Stream contentReadStream = body.GetContentReadStream()) { ApprovalProcessor.CopyStream(contentReadStream, stream, this.Buffer); } stream.Flush(); } }
internal ApprovalEngine.ProcessResult CreateAndSubmitApprovalRequests(int?messageLocaleId) { this.initiationMessageItem.Load(InitiationProcessor.PropertiesFromInitiationForApprovalRequestCreation); this.CopyPropertiesToInitiationMessageFromMessageItem(); this.initiationMessage.MessageItemLocale = messageLocaleId; ApprovalApplicationId?valueAsNullable = this.initiationMessageItem.GetValueAsNullable <ApprovalApplicationId>(MessageItemSchema.ApprovalApplicationId); string valueOrDefault = this.initiationMessageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalRequestMessageId); if (string.IsNullOrEmpty(valueOrDefault) || this.initiationMessageItem.VotingInfo == null) { return(ApprovalEngine.ProcessResult.Invalid); } string local; string domain; if (!FindMessageUtils.TryParseMessageId(valueOrDefault, out local, out domain)) { return(ApprovalEngine.ProcessResult.Invalid); } byte[] messageCorrelationBlob = this.initiationMessageItem.VotingInfo.MessageCorrelationBlob; using (ApprovalRequestWriter instance = ApprovalRequestWriter.GetInstance(valueAsNullable, this.mbxTransportMailItem.OrganizationId, this.initiationMessage)) { Dictionary <CultureInfo, List <RoutingAddress> > dictionary = null; if (instance.SupportMultipleRequestsForDifferentCultures && ApprovalProcessor.TryGetCulturesForDecisionMakers(this.initiationMessage.DecisionMakers, this.mbxTransportMailItem.ADRecipientCache.ADSession, this.organizationFallbackCulture, out dictionary)) { int num = 0; using (Dictionary <CultureInfo, List <RoutingAddress> > .KeyCollection.Enumerator enumerator = dictionary.Keys.GetEnumerator()) { while (enumerator.MoveNext()) { CultureInfo cultureInfo = enumerator.Current; IList <RoutingAddress> list = dictionary[cultureInfo]; string text = ApprovalRequestWriter.FormatApprovalRequestMessageId(local, num++, domain, false); this.SendApprovalRequest(instance, list, cultureInfo, text, messageCorrelationBlob); InitiationProcessor.diag.TraceDebug <string, int, long>((long)this.GetHashCode(), "Approval request '{0}' submitted for {1} decision makers, init message internal id '{2}'", text, list.Count, this.mbxTransportMailItem.RecordId); } goto IL_19C; } } string text2 = ApprovalRequestWriter.FormatApprovalRequestMessageId(local, 0, domain, false); this.SendApprovalRequest(instance, null, this.organizationFallbackCulture, text2, messageCorrelationBlob); InitiationProcessor.diag.TraceDebug <string, long>((long)this.GetHashCode(), "Approval request '{0}' submitted for all decision makers for init message with internal id '{1}'", text2, this.mbxTransportMailItem.RecordId); IL_19C :; } return(ApprovalEngine.ProcessResult.InitiationMessageOk); }
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); } }
// Token: 0x06000039 RID: 57 RVA: 0x00003EA4 File Offset: 0x000020A4 private void SendRejectNotification(MessageItem messageItem) { ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Entering SendRejectNotification"); if (!this.ShouldSendNotification(messageItem)) { return; } RoutingAddress routingAddress; if (!this.TryGetOriginalSender(messageItem, out routingAddress)) { return; } MailboxSession mailboxSession = (MailboxSession)messageItem.Session; messageItem.Load(ModeratedDLApplication.NotificationPropertiesFromInitMessage); string valueOrDefault = messageItem.GetValueOrDefault <string>(MessageItemSchema.AcceptLanguage, string.Empty); DsnHumanReadableWriter defaultDsnHumanReadableWriter = DsnHumanReadableWriter.DefaultDsnHumanReadableWriter; ICollection <string> moderatedRecipients = this.GetModeratedRecipients(messageItem, false); string valueOrDefault2 = messageItem.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty); StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox); using (MessageItem messageItem2 = MessageItem.Create(mailboxSession, defaultFolderId)) { StreamAttachment streamAttachment = null; try { bool flag = ModeratedDLApplication.TryGetCommentAttachment(messageItem, out streamAttachment) && streamAttachment.Size > 0L; messageItem2.ClassName = "IPM.Note.Microsoft.Approval.Reply.Reject"; bool flag2 = true; ApprovalInformation approvalInformation = null; if (flag) { approvalInformation = defaultDsnHumanReadableWriter.GetModerateRejectInformation(messageItem.Subject, moderatedRecipients, flag, valueOrDefault2, valueOrDefault); messageItem2.Subject = approvalInformation.Subject; flag2 = this.TryWriteNotificationWithAppendedComments(defaultDsnHumanReadableWriter, messageItem2, streamAttachment, approvalInformation); } if (!flag || !flag2) { approvalInformation = defaultDsnHumanReadableWriter.GetModerateRejectInformation(messageItem.Subject, moderatedRecipients, false, valueOrDefault2, valueOrDefault); messageItem2.Subject = approvalInformation.Subject; BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, approvalInformation.MessageCharset.Name); using (Stream stream = messageItem2.Body.OpenWriteStream(configuration)) { defaultDsnHumanReadableWriter.WriteHtmlModerationBody(stream, approvalInformation); stream.Flush(); } } if (flag && !flag2) { using (StreamAttachment streamAttachment2 = messageItem2.AttachmentCollection.Create(AttachmentType.Stream) as StreamAttachment) { streamAttachment2.FileName = defaultDsnHumanReadableWriter.GetModeratorsCommentFileName(approvalInformation.Culture); using (Stream contentStream = streamAttachment2.GetContentStream()) { using (Stream contentStream2 = streamAttachment.GetContentStream(PropertyOpenMode.ReadOnly)) { byte[] buffer = new byte[8192]; ApprovalProcessor.CopyStream(contentStream2, contentStream, buffer); } contentStream.Flush(); } streamAttachment2.Save(); } } this.StampCommonNotificationProperties(messageItem2, messageItem, new RoutingAddress[] { routingAddress }, valueOrDefault2, approvalInformation.Culture); messageItem2.SendWithoutSavingMessage(); } finally { if (streamAttachment != null) { streamAttachment.Dispose(); } } } }
// Token: 0x06000038 RID: 56 RVA: 0x00003BFC File Offset: 0x00001DFC private void SendModeratorExpiryNotification(MessageItem messageItem, ApprovalInformation.ApprovalNotificationType notificationType) { ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Entering SendModeratorExpiryNotification"); if (!this.ShouldSendNotification(messageItem)) { return; } string valueOrDefault = messageItem.GetValueOrDefault <string>(MessageItemSchema.ApprovalAllowedDecisionMakers); RoutingAddress[] collection; if (!ApprovalUtils.TryGetDecisionMakers(valueOrDefault, out collection)) { return; } MailboxSession mailboxSession = (MailboxSession)messageItem.Session; messageItem.Load(ModeratedDLApplication.NotificationPropertiesFromInitMessage); ICollection <string> moderatedRecipients = this.GetModeratedRecipients(messageItem, false); string valueOrDefault2 = messageItem.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty); int value = messageItem.GetValueAsNullable <int>(StoreObjectSchema.RetentionPeriod) ?? 2; Dictionary <CultureInfo, List <RoutingAddress> > dictionary = null; IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.FullyConsistent, mailboxSession.GetADSessionSettings(), 587, "SendModeratorExpiryNotification", "f:\\15.00.1497\\sources\\dev\\Approval\\src\\Applications\\ModeratedDLApplication\\ModeratedDLApplication.cs"); DsnHumanReadableWriter defaultDsnHumanReadableWriter = DsnHumanReadableWriter.DefaultDsnHumanReadableWriter; StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox); if (ClientCultures.IsCultureSupportedForDsn(CultureInfo.CurrentCulture)) { this.defaultFallBackCulture = CultureInfo.CurrentCulture; } else { this.defaultFallBackCulture = CultureInfo.GetCultureInfo("en-US"); } if (ApprovalProcessor.TryGetCulturesForDecisionMakers(new List <RoutingAddress>(collection), tenantOrRootOrgRecipientSession, this.defaultFallBackCulture, out dictionary)) { foreach (CultureInfo cultureInfo in dictionary.Keys) { IList <RoutingAddress> list = dictionary[cultureInfo]; using (MessageItem messageItem2 = MessageItem.Create(mailboxSession, defaultFolderId)) { ApprovalInformation approvalInformation = null; string text; this.AttachOriginalMessageToNotification(messageItem, messageItem2, out text); if (string.IsNullOrEmpty(text)) { RoutingAddress routingAddress; if (!this.TryGetOriginalSender(messageItem, out routingAddress)) { break; } text = routingAddress.ToString(); } approvalInformation = defaultDsnHumanReadableWriter.GetMessageInModerationModeratorExpiredInformation(notificationType, messageItem.Subject, moderatedRecipients, text, new int?(value), cultureInfo.Name, this.defaultFallBackCulture); messageItem2.Subject = approvalInformation.Subject; BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, approvalInformation.MessageCharset.Name); using (Stream stream = messageItem2.Body.OpenWriteStream(configuration)) { defaultDsnHumanReadableWriter.WriteHtmlModerationBody(stream, approvalInformation); } this.StampCommonNotificationProperties(messageItem2, messageItem, list, valueOrDefault2, approvalInformation.Culture); messageItem2.ClassName = "IPM.Note.Microsoft.Approval.Reply.Reject"; messageItem2.SendWithoutSavingMessage(); ModeratedDLApplication.diag.TraceDebug <int, string>((long)this.GetHashCode(), "Expiry Notification sent for {0} decision makers, original message id '{1}'", list.Count, valueOrDefault2); } } } }
internal override bool OnExpire(MessageItem message, out bool sendUpdate) { AutoGroupApplication.diag.TraceFunction((long)this.GetHashCode(), "AutoGroupApplication.OnExpire"); sendUpdate = true; message.Load(new PropertyDefinition[] { MessageItemSchema.ReceivedBy, MessageItemSchema.ApprovalDecisionMaker, MessageItemSchema.ApprovalRequestor, MessageItemSchema.ApprovalAllowedDecisionMakers, MessageItemSchema.ApprovalApplicationData }); CultureInfo messageCulture = null; string arg; SmtpAddress arg2; SmtpAddress smtpAddress; SmtpAddress[] array; if (!AutoGroupApplication.GetItemRecipients(message, out arg, out arg2, out smtpAddress, out array)) { AutoGroupApplication.diag.TraceError <string, SmtpAddress, SmtpAddress>((long)this.GetHashCode(), "'{0}' message has invalid approver '{1}', requester '{2}', or empty moderators list.", arg, arg2, smtpAddress); return(false); } SmtpAddress emailAddressFromMailboxItem = AutoGroupApplication.GetEmailAddressFromMailboxItem(message); if (emailAddressFromMailboxItem == SmtpAddress.Empty) { AutoGroupApplication.diag.TraceError <string>((long)this.GetHashCode(), "'{0}' cannot get arbitration mailbox SMTP address from message.", arg); return(false); } string valueOrDefault = message.GetValueOrDefault <string>(MessageItemSchema.ApprovalApplicationData); string text; ADObjectId adobjectId; if (string.IsNullOrEmpty(valueOrDefault) || !AutoGroupApplication.ParseApprovalData(valueOrDefault, out text, out adobjectId)) { AutoGroupApplication.diag.TraceError <string, string>((long)this.GetHashCode(), "'{0}' applicationData '{1}' cannot be parsed", arg, valueOrDefault); return(false); } IRecipientSession recipientSession = ApprovalProcessor.CreateRecipientSessionFromSmtpAddress(smtpAddress); MiniRecipient miniRecipient = recipientSession.ReadMiniRecipient(adobjectId, null); if (miniRecipient == null) { AutoGroupApplication.diag.TraceError <string, ADObjectId>((long)this.GetHashCode(), "'{0}' group '{1}' not found in AD.", arg, adobjectId); return(false); } string group; if (string.IsNullOrEmpty(miniRecipient.DisplayName)) { group = miniRecipient.Name; } else { group = miniRecipient.DisplayName; } ADRawEntry adrawEntry = recipientSession.FindByProxyAddress(new SmtpProxyAddress(smtpAddress.ToString(), true), new PropertyDefinition[] { ADObjectSchema.Id, ADUserSchema.Languages }); if (adrawEntry != null) { MultiValuedProperty <CultureInfo> multiValuedProperty = (MultiValuedProperty <CultureInfo>)adrawEntry[ADUserSchema.Languages]; if (multiValuedProperty.Count > 0) { messageCulture = multiValuedProperty[0]; } } ApprovalProcessor.SendNotification(emailAddressFromMailboxItem, message.Id.ObjectId, new SmtpAddress[] { smtpAddress }, Strings.AutoGroupRequestExpiredSubject(group), Strings.AutoGroupRequestExpiredBody(group), LocalizedString.Empty, LocalizedString.Empty, messageCulture); return(true); }
internal override bool OnApprove(MessageItem message) { AutoGroupApplication.diag.TraceFunction((long)this.GetHashCode(), "AutoGroupApplication.OnApprove"); message.Load(new PropertyDefinition[] { MessageItemSchema.ReceivedBy, MessageItemSchema.ApprovalDecisionMaker, MessageItemSchema.ApprovalRequestor, MessageItemSchema.ApprovalAllowedDecisionMakers, MessageItemSchema.ApprovalApplicationData }); CultureInfo cultureInfo = null; CultureInfo messageCulture = null; string arg; SmtpAddress smtpAddress; SmtpAddress smtpAddress2; SmtpAddress[] array; if (!AutoGroupApplication.GetItemRecipients(message, out arg, out smtpAddress, out smtpAddress2, out array)) { AutoGroupApplication.diag.TraceError <string, SmtpAddress, SmtpAddress>((long)this.GetHashCode(), "'{0}' message has invalid approver '{1}', requester '{2}', or empty moderators list.", arg, smtpAddress, smtpAddress2); return(false); } SmtpAddress emailAddressFromMailboxItem = AutoGroupApplication.GetEmailAddressFromMailboxItem(message); if (emailAddressFromMailboxItem == SmtpAddress.Empty) { AutoGroupApplication.diag.TraceError <string>((long)this.GetHashCode(), "'{0}' cannot get arbitration mailbox SMTP address from message.", arg); return(false); } string valueOrDefault = message.GetValueOrDefault <string>(MessageItemSchema.ApprovalApplicationData); string text; ADObjectId adobjectId; if (string.IsNullOrEmpty(valueOrDefault) || !AutoGroupApplication.ParseApprovalData(valueOrDefault, out text, out adobjectId)) { AutoGroupApplication.diag.TraceError <string, string>((long)this.GetHashCode(), "'{0}' applicationData '{1}' cannot be parsed", arg, valueOrDefault); return(false); } IRecipientSession recipientSession = ApprovalProcessor.CreateRecipientSessionFromSmtpAddress(smtpAddress); ADRawEntry adrawEntry = null; bool flag = true; try { adrawEntry = recipientSession.FindByProxyAddress(new SmtpProxyAddress(smtpAddress.ToString(), true), new PropertyDefinition[] { ADObjectSchema.Id, ADUserSchema.Languages }); } catch (NonUniqueRecipientException) { flag = false; } ADRawEntry adrawEntry2 = null; bool flag2 = true; try { adrawEntry2 = recipientSession.FindByProxyAddress(new SmtpProxyAddress(smtpAddress2.ToString(), true), new PropertyDefinition[] { ADObjectSchema.Id, ADRecipientSchema.PrimarySmtpAddress, ADUserSchema.Languages }); } catch (NonUniqueRecipientException) { flag2 = false; } MiniRecipient miniRecipient = recipientSession.ReadMiniRecipient(adobjectId, null); if (miniRecipient == null) { AutoGroupApplication.diag.TraceError <string, ADObjectId>((long)this.GetHashCode(), "'{0}' group '{1}' not found in AD.", arg, adobjectId); return(false); } string group; if (string.IsNullOrEmpty(miniRecipient.DisplayName)) { group = miniRecipient.Name; } else { group = miniRecipient.DisplayName; } if (adrawEntry == null) { if (flag) { AutoGroupApplication.diag.TraceError <string, SmtpAddress>((long)this.GetHashCode(), "'{0}' approver '{1}' not found in AD.", arg, smtpAddress); } else { AutoGroupApplication.diag.TraceError <string, SmtpAddress>((long)this.GetHashCode(), "'{0}' approver '{1}' not unique in AD.", arg, smtpAddress); } ApprovalProcessor.SendNotification(emailAddressFromMailboxItem, message.Id.ObjectId, new SmtpAddress[] { smtpAddress }, Strings.AutoGroupRequestFailedSubject(group), Strings.AutoGroupRequestFailedHeader(group), Strings.AutoGroupRequestFailedBodyBadApprover(group, ApprovalProcessor.GetDisplayNameFromSmtpAddress(smtpAddress2.ToString()), ApprovalProcessor.GetDisplayNameFromSmtpAddress(smtpAddress.ToString())), LocalizedString.Empty, null); return(false); } MultiValuedProperty <CultureInfo> multiValuedProperty = (MultiValuedProperty <CultureInfo>)adrawEntry[ADUserSchema.Languages]; if (multiValuedProperty.Count > 0) { cultureInfo = multiValuedProperty[0]; } if (adrawEntry2 == null) { if (flag2) { AutoGroupApplication.diag.TraceError <string, SmtpAddress>((long)this.GetHashCode(), "'{0}' requester '{1}' not found in AD.", arg, smtpAddress2); } else { AutoGroupApplication.diag.TraceError <string, SmtpAddress>((long)this.GetHashCode(), "'{0}' requester '{1}' not unique in AD.", arg, smtpAddress2); } ApprovalProcessor.SendNotification(emailAddressFromMailboxItem, message.Id.ObjectId, new SmtpAddress[] { smtpAddress }, Strings.AutoGroupRequestFailedSubject(group), Strings.AutoGroupRequestFailedHeader(group), Strings.AutoGroupRequestFailedBodyBadRequester(group, ApprovalProcessor.GetDisplayNameFromSmtpAddress(smtpAddress2.ToString())), LocalizedString.Empty, cultureInfo); return(false); } MultiValuedProperty <CultureInfo> multiValuedProperty2 = (MultiValuedProperty <CultureInfo>)adrawEntry2[ADUserSchema.Languages]; if (multiValuedProperty2.Count > 0) { messageCulture = multiValuedProperty2[0]; } bool flag3 = false; string a; if ((a = text) != null) { if (!(a == "Add-DistributionGroupMember")) { if (!(a == "Remove-DistributionGroupMember")) { goto IL_393; } flag3 = true; } PSCommand pscommand = new PSCommand().AddCommand(text); pscommand.AddParameter("Identity", adobjectId); pscommand.AddParameter("Member", adrawEntry2.Id); if (flag3) { pscommand.AddParameter("Confirm", new SwitchParameter(false)); } AutoGroupApplication.diag.Information <string, string>((long)this.GetHashCode(), "'{0}' executing command '{1}'.", arg, pscommand.ToString()); string text2; string text3; ApprovalApplication.ExecuteCommandsInRunspace(smtpAddress, pscommand, cultureInfo, out text2, out text3); if (!text2.Equals(string.Empty)) { AutoGroupApplication.diag.TraceError <string, string, string>((long)this.GetHashCode(), "'{0}' command '{1}' failed with error {2}.", arg, pscommand.ToString(), text2); ApprovalProcessor.SendNotification(emailAddressFromMailboxItem, message.Id.ObjectId, new SmtpAddress[] { smtpAddress }, Strings.AutoGroupRequestFailedSubject(group), Strings.AutoGroupRequestFailedHeader(group), Strings.AutoGroupRequestFailedBodyTaskError(text2), LocalizedString.Empty, cultureInfo); return(false); } AutoGroupApplication.diag.Information <string, string>((long)this.GetHashCode(), "'{0}' command '{1}' completed successfully.", arg, pscommand.ToString()); ApprovalProcessor.SendApproveNotification(emailAddressFromMailboxItem, message.Id.ObjectId, new SmtpAddress[] { (SmtpAddress)adrawEntry2[ADRecipientSchema.PrimarySmtpAddress] }, Strings.AutoGroupRequestApprovedSubject(group), Strings.AutoGroupRequestApprovedHeader(ApprovalProcessor.GetDisplayNameFromSmtpAddress(smtpAddress.ToString()), group), Strings.AutoGroupRequestApprovedBody, LocalizedString.Empty, messageCulture); return(true); } IL_393: AutoGroupApplication.diag.TraceError <string, string>((long)this.GetHashCode(), "'{0}' command '{1}' not recognized.", arg, text); return(false); }
// Token: 0x06000018 RID: 24 RVA: 0x0000252C File Offset: 0x0000072C internal static Collection <PSObject> ExecuteCommandsInRunspace(SmtpAddress user, PSCommand command, CultureInfo executingCulture, out string errorMessage, out string warningMessage) { Collection <PSObject> result = null; StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder2 = new StringBuilder(); errorMessage = string.Empty; warningMessage = string.Empty; IRecipientSession recipientSession = ApprovalProcessor.CreateRecipientSessionFromSmtpAddress(user); ADUser aduser = recipientSession.FindByProxyAddress(ProxyAddress.Parse((string)user)) as ADUser; if (aduser == null) { errorMessage = Strings.ErrorUserNotFound((string)user); return(null); } GenericIdentity identity = new GenericIdentity(aduser.Sid.ToString()); InitialSessionState initialSessionState = null; try { initialSessionState = new ExchangeRunspaceConfiguration(identity).CreateInitialSessionState(); initialSessionState.LanguageMode = PSLanguageMode.FullLanguage; } catch (CmdletAccessDeniedException) { errorMessage = Strings.ErrorNoRBACRoleAssignment((string)user); return(null); } CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture; try { if (executingCulture != null) { Thread.CurrentThread.CurrentCulture = executingCulture; Thread.CurrentThread.CurrentUICulture = executingCulture; } using (RunspaceProxy runspaceProxy = new RunspaceProxy(new RunspaceMediator(new ForestScopeRunspaceFactory(new BasicInitialSessionStateFactory(initialSessionState), new BasicPSHostFactory(typeof(RunspaceHost), true)), new EmptyRunspaceCache()))) { try { PowerShellProxy powerShellProxy = new PowerShellProxy(runspaceProxy, command); result = powerShellProxy.Invoke <PSObject>(); if (powerShellProxy.Errors != null) { foreach (ErrorRecord errorRecord in powerShellProxy.Errors) { stringBuilder.Append(errorRecord.ToString()); } } if (powerShellProxy.Warnings != null) { foreach (WarningRecord warningRecord in powerShellProxy.Warnings) { stringBuilder2.Append(warningRecord.ToString()); } } } catch (CmdletInvocationException) { stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture)); } catch (ParameterBindingException) { stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture)); } catch (CommandNotFoundException) { stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture)); } catch (RuntimeException) { stringBuilder.Append(Strings.ErrorTaskInvocationFailed((string)user).ToString(executingCulture)); } finally { errorMessage = stringBuilder.ToString(); warningMessage = stringBuilder2.ToString(); } } } finally { if (executingCulture != null) { Thread.CurrentThread.CurrentCulture = currentCulture; Thread.CurrentThread.CurrentUICulture = currentUICulture; } } return(result); }
protected string SubmitApprovalRequest(string command) { if (this.DataObject.ArbitrationMailbox == null) { base.WriteError(new RecipientTaskException(Strings.ErrorArbitrationMailboxNotSet(this.Identity.ToString())), ErrorCategory.InvalidArgument, this.Identity); } ADRecipient adrecipient = (ADRecipient)base.GetDataObject <ADRecipient>(new MailboxIdParameter(this.DataObject.ArbitrationMailbox), base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.DataObject.ArbitrationMailbox.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.DataObject.ArbitrationMailbox.ToString()))); if (adrecipient.RecipientTypeDetails != RecipientTypeDetails.ArbitrationMailbox) { base.WriteError(new RecipientTaskException(Strings.ErrorInvalidArbitrationMbxType(adrecipient.Identity.ToString())), ErrorCategory.InvalidData, this.DataObject.Identity); } if (!adrecipient.IsValid) { base.WriteError(new RecipientTaskException(Strings.ErrorInvalidArbitrationMailbox(adrecipient.Identity.ToString())), ErrorCategory.InvalidData, this.DataObject.Identity); } QueryFilter filter = new AndFilter(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, ApprovalApplicationSchema.ArbitrationMailboxesBacklink, adrecipient.Id), new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, "AutoGroup") }); ApprovalApplication[] array = this.ConfigurationSession.Find <ApprovalApplication>(null, QueryScope.SubTree, filter, null, 1); if (array == null || array.Length == 0) { base.WriteError(new RecipientTaskException(Strings.ErrorNoAutoGroupApprovalApplicationInOrg(adrecipient.OrganizationId.ToString())), ErrorCategory.InvalidData, null); } Guid policyTag = Guid.Empty; int? retentionPeriod = null; RetentionPolicyTag retentionPolicyTag = null; if (array[0].ELCRetentionPolicyTag != null) { this.ConfigurationSession.SessionSettings.IsSharedConfigChecked = true; retentionPolicyTag = this.ConfigurationSession.Read <RetentionPolicyTag>(array[0].ELCRetentionPolicyTag); } else { IConfigurationSession configurationSession = SharedConfiguration.CreateScopedToSharedConfigADSession(adrecipient.OrganizationId); if (configurationSession != null) { IList <RetentionPolicyTag> defaultRetentionPolicyTag = ApprovalUtils.GetDefaultRetentionPolicyTag(configurationSession, ApprovalApplicationId.AutoGroup, 1); if (defaultRetentionPolicyTag != null && defaultRetentionPolicyTag.Count > 0) { retentionPolicyTag = defaultRetentionPolicyTag[0]; } } } if (retentionPolicyTag == null) { this.WriteWarning(Strings.WarningRetentionPolicyTagNotFoundForApproval(array[0].Name, adrecipient.OrganizationId.ToString())); } else { policyTag = retentionPolicyTag.RetentionId; EnhancedTimeSpan?timeSpanForRetention = retentionPolicyTag.TimeSpanForRetention; retentionPeriod = ((timeSpanForRetention != null) ? new int?((int)timeSpanForRetention.Value.TotalDays) : null); } Result <ADRawEntry>[] array2 = base.TenantGlobalCatalogSession.ReadMultiple(this.DataObject.ManagedBy.ToArray(), new PropertyDefinition[] { ADObjectSchema.Id, ADRecipientSchema.PrimarySmtpAddress, ADUserSchema.Languages, ADRecipientSchema.RecipientTypeDetails }); ADRawEntry[] array3 = new ADRawEntry[array2.Length]; for (int i = 0; i < array3.Length; i++) { array3[i] = array2[i].Data; } SmtpAddress[] array4 = (from approver in array3 where (RecipientTypeDetails)approver[ADRecipientSchema.RecipientTypeDetails] != RecipientTypeDetails.MailUniversalSecurityGroup && (RecipientTypeDetails)approver[ADRecipientSchema.RecipientTypeDetails] != RecipientTypeDetails.UniversalSecurityGroup select(SmtpAddress) approver[ADRecipientSchema.PrimarySmtpAddress]).ToArray <SmtpAddress>(); if (array4.Length == 0) { base.WriteError(new RecipientTaskException(Strings.ErrorApproversNotSet(this.Identity.ToString())), ErrorCategory.InvalidArgument, this.Identity); } base.WriteVerbose(Strings.VerboseStartToSubmitApprovalRequest(this.DataObject.DisplayName, string.Join <SmtpAddress>(", ", array4))); CultureInfo moderatorCommonCulture = this.SelectApproverCommonCulture(array3); string text = ApprovalProcessor.SubmitRequest(0, adrecipient.PrimarySmtpAddress, this.requester.PrimarySmtpAddress, array4, moderatorCommonCulture, policyTag, retentionPeriod, this.ApprovalMessageSubject(), AutoGroupApplication.BuildApprovalData(command, this.DataObject.Id)); base.WriteVerbose(Strings.VerboseApprovalRequestSubmitted(this.DataObject.DisplayName, text)); return(text); }
public void AddAttachment(Attachment attachment, IRecipientSession adRecipientSession) { bool flag = false; MimePart mimePart = attachment.MimePart; Header header = null; if (mimePart != null) { header = mimePart.Headers.FindFirst("X-MS-Exchange-Organization-Approval-AttachToApprovalRequest"); } string text; if (header != null && header.TryGetValue(out text)) { if (text.Equals("Never")) { return; } if (text.Equals("AsMessage")) { flag = true; } } if (flag) { using (Stream contentReadStream = attachment.GetContentReadStream()) { using (ItemAttachment itemAttachment = (ItemAttachment)this.messageItem.AttachmentCollection.Create(AttachmentType.EmbeddedMessage)) { using (Item item = itemAttachment.GetItem()) { ItemConversion.ConvertAnyMimeToItem(item, contentReadStream, new InboundConversionOptions(Components.Configuration.FirstOrgAcceptedDomainTable.DefaultDomainName) { UserADSession = adRecipientSession }); item[MessageItemSchema.Flags] = MessageFlags.None; item.Save(SaveMode.NoConflictResolution); string valueOrDefault = item.GetValueOrDefault <string>(ItemSchema.Subject); if (!string.IsNullOrEmpty(valueOrDefault)) { itemAttachment[AttachmentSchema.DisplayName] = valueOrDefault; } itemAttachment.Save(); } } return; } } using (StreamAttachment streamAttachment = (StreamAttachment)this.messageItem.AttachmentCollection.Create(AttachmentType.Stream)) { streamAttachment.FileName = attachment.FileName; using (Stream contentStream = streamAttachment.GetContentStream()) { using (Stream contentReadStream2 = attachment.GetContentReadStream()) { ApprovalProcessor.CopyStream(contentReadStream2, contentStream, this.Buffer); } contentStream.Flush(); } streamAttachment.Save(); } }