Пример #1
0
        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);
            }
        }
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }