internal T ResolveRecipientIdParameter <T>(RecipientIdParameter recipientIdParameter, IRecipientSession recipientSession) where T : ADRecipient, new() { if (recipientIdParameter == null) { return(default(T)); } IEnumerable <T> objects = recipientIdParameter.GetObjects <T>(null, recipientSession); T result = default(T); using (IEnumerator <T> enumerator = objects.GetEnumerator()) { if (!enumerator.MoveNext()) { base.WriteError(new TaskException(Strings.NoRecipientsForRecipientId(recipientIdParameter.ToString())), ExchangeErrorCategory.Client, null); } result = enumerator.Current; if (enumerator.MoveNext()) { base.WriteError(new TaskException(Strings.MoreThanOneRecipientForRecipientId(recipientIdParameter.ToString())), ExchangeErrorCategory.Client, null); } } if (string.IsNullOrEmpty(result.ExternalDirectoryObjectId)) { base.WriteError(new TaskException(Strings.NoExternalDirectoryObjectIdForRecipientId(recipientIdParameter.ToString())), ExchangeErrorCategory.Client, null); } return(result); }
private static SmtpAddress ResolveRecipientIdParameter(IRecipientSession recipientSession, RecipientIdParameter recipientIdParameter, out LocalizedException resolutionError) { resolutionError = null; if (SmtpAddress.IsValidSmtpAddress(recipientIdParameter.RawIdentity)) { return(SmtpAddress.Parse(recipientIdParameter.RawIdentity)); } IEnumerable <ADRecipient> objects = recipientIdParameter.GetObjects <ADRecipient>(null, recipientSession); ADRecipient adrecipient = null; using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator()) { if (!enumerator.MoveNext()) { resolutionError = new NoRecipientsForRecipientIdException(recipientIdParameter.ToString()); return(SmtpAddress.Empty); } adrecipient = enumerator.Current; if (enumerator.MoveNext()) { resolutionError = new MoreThanOneRecipientForRecipientIdException(recipientIdParameter.ToString()); return(SmtpAddress.Empty); } } if (SmtpAddress.Empty.Equals(adrecipient.PrimarySmtpAddress)) { resolutionError = new NoSmtpAddressForRecipientIdException(recipientIdParameter.ToString()); return(SmtpAddress.Empty); } return(adrecipient.PrimarySmtpAddress); }
internal static SmtpAddress Lookup(RecipientIdParameter recipId, IRecipientSession recipSession, OrganizationId orgId, bool getRecipientType, out Microsoft.Exchange.Data.Directory.Recipient.RecipientType?recipientType) { recipientType = null; bool flag = SmtpAddress.IsValidSmtpAddress(recipId.RawIdentity); if (!getRecipientType && flag) { return(SmtpAddress.Parse(recipId.RawIdentity)); } if (flag) { SmtpAddress smtpAddress = SmtpAddress.Parse(recipId.RawIdentity); ADRecipient adrecipientBySmtpAddress = JournalRuleObject.GetADRecipientBySmtpAddress(smtpAddress); if (adrecipientBySmtpAddress != null) { recipientType = new Microsoft.Exchange.Data.Directory.Recipient.RecipientType?(adrecipientBySmtpAddress.RecipientType); } return(smtpAddress); } IEnumerable <ADRecipient> objects = recipId.GetObjects <ADRecipient>((null == orgId) ? null : orgId.OrganizationalUnit, recipSession ?? DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, orgId.ToADSessionSettings(), 429, "Lookup", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\JournalRule\\JournalRuleObject.cs")); ADRecipient adrecipient = null; using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator()) { if (!enumerator.MoveNext()) { MimeRecipient mimeRecipient = null; try { mimeRecipient = MimeRecipient.Parse(recipId.RawIdentity, AddressParserFlags.IgnoreComments | AddressParserFlags.AllowSquareBrackets); } catch (MimeException) { } if (mimeRecipient == null || string.IsNullOrEmpty(mimeRecipient.Email) || !SmtpAddress.IsValidSmtpAddress(mimeRecipient.Email)) { throw new RecipientInvalidException(Strings.NoRecipients); } return(new SmtpAddress(mimeRecipient.Email)); } else { adrecipient = enumerator.Current; if (enumerator.MoveNext()) { throw new RecipientInvalidException(Strings.MoreThanOneRecipient); } } } if (adrecipient is IADOrgPerson && adrecipient.PrimarySmtpAddress.Equals(SmtpAddress.Empty)) { throw new RecipientInvalidException(Strings.NoSmtpAddress); } recipientType = new Microsoft.Exchange.Data.Directory.Recipient.RecipientType?(adrecipient.RecipientType); return(adrecipient.PrimarySmtpAddress); }
public string[] Resolve(string identity) { RecipientIdParameter recipientIdParameter = new RecipientIdParameter(identity); IEnumerable <ADRecipient> objects = recipientIdParameter.GetObjects <ADRecipient>(null, this.recipientSession); if (objects == null) { return(null); } List <string> list = new List <string>(4); foreach (ADRecipient adrecipient in objects) { list.Add(adrecipient.DisplayName); list.Add(adrecipient.Alias); list.Add(adrecipient.LegacyExchangeDN); list.Add(adrecipient.PrimarySmtpAddress.ToString()); } return(list.ToArray()); }
internal static ADUser GetSoftDeletedADUser(OrganizationId organizationId, RecipientIdParameter identity, Task.ErrorLoggerDelegate errorLogger) { IRecipientSession sessionForSoftDeletedObjects = SoftDeletedTaskHelper.GetSessionForSoftDeletedObjects(organizationId, null); IEnumerable <ADUser> enumerable = identity.GetObjects <ADUser>(organizationId.OrganizationalUnit, sessionForSoftDeletedObjects) ?? new List <ADUser>(); ADUser result; using (IEnumerator <ADUser> enumerator = enumerable.GetEnumerator()) { if (!enumerator.MoveNext()) { errorLogger(new RecipientTaskException(Strings.ErrorMailboxNotFound(identity.ToString())), ExchangeErrorCategory.Client, null); } result = enumerator.Current; if (enumerator.MoveNext()) { errorLogger(new RecipientTaskException(Strings.ErrorMailboxNotUnique(identity.ToString())), ExchangeErrorCategory.Client, null); } } return(result); }
public string[] Resolve(string identity) { RecipientIdParameter recipientIdParameter = new RecipientIdParameter(identity); IEnumerable <ADRecipient> objects = recipientIdParameter.GetObjects <ADRecipient>(null, this.recipientSession); if (objects == null) { return(null); } List <string> list = new List <string>(); foreach (ADRecipient adrecipient in objects) { list.Add(adrecipient.DisplayName); list.Add(adrecipient.Alias); list.Add(adrecipient.LegacyExchangeDN); list.Add(adrecipient.PrimarySmtpAddress.ToString()); } SearchMailboxCriteria.Tracer.TraceDebug <string, List <string> >((long)this.GetHashCode(), "SearchMailboxCriteria resolving Identity {0} to {1}", identity, list); return(list.ToArray()); }
internal static LocalizedException SetUserInformation(TestCasConnectivity.TestCasConnectivityRunInstance instance, IConfigDataProvider session, ref ADUser user) { if (session == null) { throw new LocalizedException(Strings.ErrorNullParameter("session")); } if (instance == null) { throw new LocalizedException(Strings.ErrorNullParameter("instance")); } IRecipientSession recipientSession = session as IRecipientSession; if (recipientSession == null) { throw new LocalizedException(Strings.ErrorNullParameter("recipientSession")); } if (!string.IsNullOrEmpty(instance.credentials.Domain) && instance.credentials.UserName.IndexOf('@') == -1) { WindowsIdentity windowsIdentity = null; string text = instance.credentials.UserName + "@" + instance.credentials.Domain; try { windowsIdentity = new WindowsIdentity(text); } catch (SecurityException ex) { return(new CasHealthUserNotFoundException(text, ex.Message)); } using (windowsIdentity) { user = (recipientSession.FindBySid(windowsIdentity.User) as ADUser); if (user == null) { return(new AdUserNotFoundException(text, string.Empty)); } goto IL_174; } } user = null; RecipientIdParameter recipientIdParameter = RecipientIdParameter.Parse(instance.credentials.UserName); IEnumerable <ADUser> objects = recipientIdParameter.GetObjects <ADUser>(null, recipientSession); if (objects != null) { IEnumerator <ADUser> enumerator = objects.GetEnumerator(); if (enumerator != null && enumerator.MoveNext()) { user = enumerator.Current; } if (enumerator.MoveNext()) { user = null; return(new AdUserNotUniqueException(instance.credentials.UserName)); } } if (user == null) { return(new AdUserNotFoundException(instance.credentials.UserName, string.Empty)); } IL_174: return(null); }
private static NewExchangeNotification.LookupResult LookupSmtpAddressAndLanguage(IRecipientSession recipientSession, RecipientIdParameter recipientIdParameter) { IEnumerable <ADRecipient> objects = recipientIdParameter.GetObjects <ADRecipient>(null, recipientSession); ADRecipient adrecipient = null; using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator()) { if (!enumerator.MoveNext()) { if (SmtpAddress.IsValidSmtpAddress(recipientIdParameter.RawIdentity)) { return(new NewExchangeNotification.LookupResult { Success = true, SmtpAddress = SmtpAddress.Parse(recipientIdParameter.RawIdentity), Languages = new CultureInfo[0] }); } return(new NewExchangeNotification.LookupResult { Success = false, ErrorMessage = Strings.NoRecipientsForRecipientId(recipientIdParameter.ToString()) }); } else { adrecipient = enumerator.Current; if (enumerator.MoveNext()) { return(new NewExchangeNotification.LookupResult { Success = false, ErrorMessage = Strings.MoreThanOneRecipientForRecipientId(recipientIdParameter.ToString()) }); } } } if (SmtpAddress.Empty.Equals(adrecipient.PrimarySmtpAddress)) { return(new NewExchangeNotification.LookupResult { Success = false, ErrorMessage = Strings.NoSmtpAddressForRecipientId(recipientIdParameter.ToString()) }); } IADOrgPerson iadorgPerson = adrecipient as IADOrgPerson; if (iadorgPerson == null) { return(new NewExchangeNotification.LookupResult { Success = true, SmtpAddress = adrecipient.PrimarySmtpAddress, Languages = new CultureInfo[0] }); } return(new NewExchangeNotification.LookupResult { Success = true, SmtpAddress = adrecipient.PrimarySmtpAddress, Languages = iadorgPerson.Languages }); }