public static bool IsLegacyServer(this IMailboxLocation mailboxLocation)
        {
            int num = 0;

            if (mailboxLocation != null)
            {
                num = mailboxLocation.ServerVersion;
            }
            return(num <= Server.E2007MinVersion);
        }
        private IMailboxLocation CreateMailboxLocation(DatabaseLocationInfo databaseLocationInfo)
        {
            IMailboxLocation result = null;

            if (databaseLocationInfo != null)
            {
                result = new MailboxDatabaseLocation(databaseLocationInfo);
            }
            return(result);
        }
        private ExchangePrincipal CreateExchangePrincipal(string displayName, IMailboxLocation mailboxLocation, RemotingOptions remotingOptions, string mailboxLegacyDN, Guid mailboxGuid, Guid mdbGuid, string primarySmtpAddress, ADObjectId id, OrganizationId orgId, IEnumerable <CultureInfo> preferredCultures, bool bypassRemoteCheck, RecipientType recipientType, RecipientTypeDetails recipientTypeDetails, SecurityIdentifier masterAccountSid = null, bool isArchive = false, Guid?aggregatedMailboxGuid = null)
        {
            ADObjectId     adobjectId = new ADObjectId(mdbGuid);
            IGenericADUser recipient  = new GenericADUser
            {
                MailboxDatabase        = (isArchive ? null : adobjectId),
                ArchiveDatabase        = (isArchive ? adobjectId : null),
                LegacyDn               = mailboxLegacyDN,
                OrganizationId         = orgId,
                DisplayName            = displayName,
                PrimarySmtpAddress     = new SmtpAddress(primarySmtpAddress),
                MailboxGuid            = (isArchive ? Guid.Empty : mailboxGuid),
                ArchiveGuid            = (isArchive ? mailboxGuid : Guid.Empty),
                Languages              = preferredCultures,
                RecipientType          = recipientType,
                RecipientTypeDetails   = recipientTypeDetails,
                ObjectId               = id,
                MasterAccountSid       = masterAccountSid,
                AggregatedMailboxGuids = ((aggregatedMailboxGuid != null) ? new Guid[]
                {
                    aggregatedMailboxGuid.Value
                } : Array <Guid> .Empty)
            };
            ExchangePrincipalBuilder exchangePrincipalBuilder = this.GetExchangePrincipalBuilder(recipient);

            exchangePrincipalBuilder.SetRemotingOptions(remotingOptions);
            exchangePrincipalBuilder.BypassRecipientTypeValidation(true);
            if (mailboxLocation != null)
            {
                exchangePrincipalBuilder.SetSelectedMailboxLocation(mailboxLocation);
            }
            if (isArchive)
            {
                exchangePrincipalBuilder.SelectArchiveMailbox();
            }
            if (aggregatedMailboxGuid != null && aggregatedMailboxGuid != Guid.Empty)
            {
                exchangePrincipalBuilder.SelectMailbox(aggregatedMailboxGuid.Value);
            }
            return(exchangePrincipalBuilder.Build());
        }
示例#4
0
        private IMailboxInfo BuildMailboxInfo(Guid mailboxGuid, ADObjectId mailboxDatabase, bool isSelected, ADObjectId selectedMailboxDatabase, IMailboxLocation selectedMailboxLocation, IGenericADUser adUser, IMailboxConfiguration configuration, Func <ADObjectId, IMailboxLocation> locationFactory)
        {
            ADObjectId       adobjectId      = mailboxDatabase;
            IMailboxLocation mailboxLocation = null;

            if (isSelected)
            {
                if (!selectedMailboxDatabase.IsNullOrEmpty())
                {
                    adobjectId = selectedMailboxDatabase;
                }
                mailboxLocation = selectedMailboxLocation;
            }
            try
            {
                return(new MailboxInfo(mailboxGuid, adobjectId, adUser, configuration, mailboxLocation ?? locationFactory(adobjectId)));
            }
            catch (ObjectNotFoundException)
            {
            }
            return(null);
        }
 private ExchangePrincipal CreateExchangePrincipal(string displayName, IMailboxLocation mailboxLocation, RemotingOptions remotingOptions, string mailboxLegacyDN, Guid mailboxGuid, Guid mdbGuid, string primarySmtpAddress, ADObjectId id, IEnumerable <CultureInfo> preferredCultures, RecipientType recipientType, SecurityIdentifier masterAccountSid, OrganizationId organizationId, bool isArchive = false)
 {
     return(this.CreateExchangePrincipal(displayName, mailboxLocation, remotingOptions, mailboxLegacyDN, mailboxGuid, mdbGuid, primarySmtpAddress, id, organizationId, preferredCultures, false, recipientType, RecipientTypeDetails.None, masterAccountSid, isArchive, null));
 }
 private ExchangePrincipal CreateExchangePrincipal(string displayName, IMailboxLocation mailboxLocation, RemotingOptions remotingOptions, string mailboxLegacyDN, Guid mailboxGuid, Guid mdbGuid, string primarySmtpAddress, ADObjectId id, OrganizationId orgId, IEnumerable <CultureInfo> preferredCultures, bool bypassRemoteCheck = false, RecipientType userRecipientType = RecipientType.Invalid, Guid?aggregatedMailboxGuid = null)
 {
     return(this.CreateExchangePrincipal(displayName, mailboxLocation, remotingOptions, mailboxLegacyDN, mailboxGuid, mdbGuid, primarySmtpAddress, id, orgId, preferredCultures, bypassRemoteCheck, userRecipientType, RecipientTypeDetails.None, null, false, aggregatedMailboxGuid));
 }
        private ExchangePrincipal CreateExchangePrincipal(IGenericADUser user, ADObjectId mdb, IMailboxLocation mailboxLocation, RemotingOptions remotingOptions, bool asArchive, Guid?aggregatedMailboxGuid, IDatabaseLocationProvider databaseLocationProvider, bool isContentIndexing = false)
        {
            ExchangePrincipalBuilder exchangePrincipalBuilder = ((remotingOptions & RemotingOptions.AllowHybridAccess) == RemotingOptions.AllowHybridAccess) ? new RemoteUserMailboxPrincipalBuilder(user) : this.GetExchangePrincipalBuilder(user);

            exchangePrincipalBuilder.SetRemotingOptions(remotingOptions);
            exchangePrincipalBuilder.SetDatabaseLocationProvider(databaseLocationProvider);
            if (!mdb.IsNullOrEmpty())
            {
                exchangePrincipalBuilder.SetSelectedMailboxDatabase(mdb.ObjectGuid);
            }
            if (mailboxLocation != null)
            {
                exchangePrincipalBuilder.SetSelectedMailboxLocation(mailboxLocation);
            }
            if (asArchive)
            {
                exchangePrincipalBuilder.SelectArchiveMailbox();
            }
            exchangePrincipalBuilder.BypassRecipientTypeValidation(isContentIndexing);
            if (aggregatedMailboxGuid != null && aggregatedMailboxGuid != Guid.Empty)
            {
                exchangePrincipalBuilder.SelectMailbox(aggregatedMailboxGuid.Value);
            }
            return(exchangePrincipalBuilder.Build());
        }
 private ExchangePrincipal InternalFromMiniRecipient(IGenericADUser adUser, ADObjectId mdb, IMailboxLocation mailboxLocation, RemotingOptions remotingOptions, bool asArchive, Guid?aggregatedMailboxGuid = null)
 {
     if (adUser == null)
     {
         throw new ObjectNotFoundException(ServerStrings.ADUserNotFound);
     }
     if (mdb == null)
     {
         mdb = adUser.MailboxDatabase;
     }
     if (mailboxLocation == null && mdb != null)
     {
         mailboxLocation = this.CreateMailboxLocation(this.databaseLocationProvider.GetLocationInfo(mdb.ObjectGuid, false, (remotingOptions & RemotingOptions.AllowCrossSite) == RemotingOptions.AllowCrossSite));
     }
     return(this.CreateExchangePrincipal(adUser, mdb, mailboxLocation, remotingOptions, asArchive, aggregatedMailboxGuid, this.databaseLocationProvider, false));
 }
示例#9
0
        public MailboxInfo(Guid mailboxGuid, ADObjectId databaseId, IGenericADUser adUser, IMailboxConfiguration mailboxConfiguration, IMailboxLocation mailboxLocation)
        {
            ArgumentValidator.ThrowIfEmpty("mailboxGuid", mailboxGuid);
            ArgumentValidator.ThrowIfNull("adUser", adUser);
            ArgumentValidator.ThrowIfNull("mailboxConfiguration", mailboxConfiguration);
            ArgumentValidator.ThrowIfNull("mailboxLocation", mailboxLocation);
            MailboxLocationType?mailboxLocationType = adUser.GetMailboxLocationType(mailboxGuid);

            if (mailboxLocationType == null)
            {
                throw new ArgumentException("The provided mailbox guid doesn't match with any of the user's mailbox.");
            }
            this.MailboxType          = mailboxLocationType.Value;
            this.DisplayName          = adUser.DisplayName;
            this.PrimarySmtpAddress   = adUser.PrimarySmtpAddress;
            this.ExternalEmailAddress = adUser.ExternalEmailAddress;
            this.EmailAddresses       = (adUser.EmailAddresses ?? Array <ProxyAddress> .Empty);
            this.OrganizationId       = adUser.OrganizationId;
            this.MailboxGuid          = mailboxGuid;
            this.MailboxDatabase      = databaseId;
            if (this.IsArchive)
            {
                this.archiveName   = ((adUser.ArchiveName != null) ? (adUser.ArchiveName.FirstOrDefault <string>() ?? string.Empty) : string.Empty);
                this.archiveState  = adUser.ArchiveState;
                this.archiveStatus = adUser.ArchiveStatus;
                this.IsRemote      = adUser.IsArchiveMailboxRemote();
            }
            else
            {
                this.IsRemote = adUser.IsPrimaryMailboxRemote();
            }
            if (this.IsRemote)
            {
                this.remoteIdentity = this.GetRemoteIdentity(adUser, this.IsArchive);
            }
            else if (this.MailboxDatabase.IsNullOrEmpty())
            {
                throw new ObjectNotFoundException(ServerStrings.MailboxDatabaseRequired(mailboxGuid));
            }
            this.WhenMailboxCreated = adUser.WhenMailboxCreated;
            this.Location           = mailboxLocation;
            this.Configuration      = mailboxConfiguration;
        }
示例#10
0
        private static LocalizedException CheckHAState(LocalizedString exceptionMessage, LocalizedException mapiException, StoreSession session)
        {
            if (session != null && (mapiException is MapiExceptionBackupInProgress || mapiException is MapiExceptionEndOfSession || mapiException is MapiExceptionLogonFailed || mapiException is MapiExceptionExiting || mapiException is MapiExceptionMailboxInTransit || mapiException is MapiExceptionCanNotComplete || mapiException is MapiExceptionMdbOffline || mapiException is MapiExceptionWrongServer || mapiException is MapiExceptionUnconfigured || mapiException is MapiExceptionUnknownUser || mapiException is MapiExceptionConditionViolation || mapiException is MapiExceptionServerPaused || mapiException is MapiExceptionCallFailed))
            {
                ExTraceGlobals.SessionTracer.TraceDebug <LocalizedException>((long)session.GetHashCode(), "StorageGlobals::CheckHAState. Translating exception {0}.", mapiException);
                DatabaseLocationInfo databaseLocationInfoOnOperationFailure = session.GetDatabaseLocationInfoOnOperationFailure();
                ExTraceGlobals.SessionTracer.TraceDebug <DatabaseLocationInfoResult>((long)session.GetHashCode(), "StorageGlobals::CheckHAState. AM result {0}.", databaseLocationInfoOnOperationFailure.RequestResult);
                switch (databaseLocationInfoOnOperationFailure.RequestResult)
                {
                case DatabaseLocationInfoResult.Success:
                {
                    IExchangePrincipal mailboxOwner = session.MailboxOwner;
                    if (mailboxOwner != null)
                    {
                        IMailboxInfo mailboxInfo = mailboxOwner.MailboxInfo;
                        if (mailboxInfo != null)
                        {
                            IMailboxLocation location = mailboxInfo.Location;
                            if (location != null)
                            {
                                if (string.Equals(location.ServerFqdn, databaseLocationInfoOnOperationFailure.ServerFqdn, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (mapiException is MapiExceptionWrongServer)
                                    {
                                        return(new WrongServerException(exceptionMessage, mapiException));
                                    }
                                    return(null);
                                }
                                else
                                {
                                    if (location.ServerSite == null || databaseLocationInfoOnOperationFailure.ServerSite == null)
                                    {
                                        return(new MailboxInSiteFailoverException(exceptionMessage, mapiException));
                                    }
                                    if (ADObjectId.Equals(location.ServerSite, databaseLocationInfoOnOperationFailure.ServerSite))
                                    {
                                        return(new MailboxInSiteFailoverException(exceptionMessage, mapiException));
                                    }
                                    return(new MailboxCrossSiteFailoverException(exceptionMessage, mapiException, databaseLocationInfoOnOperationFailure));
                                }
                            }
                        }
                    }
                    break;
                }

                case DatabaseLocationInfoResult.Unknown:
                    return(new MailboxOfflineException(exceptionMessage, mapiException));

                case DatabaseLocationInfoResult.InTransitSameSite:
                    return(new MailboxInSiteFailoverException(exceptionMessage, mapiException));

                case DatabaseLocationInfoResult.InTransitCrossSite:
                    return(new MailboxCrossSiteFailoverException(exceptionMessage, mapiException, databaseLocationInfoOnOperationFailure));

                case DatabaseLocationInfoResult.SiteViolation:
                    return(new WrongServerException(exceptionMessage, mapiException));

                default:
                    throw new NotSupportedException(string.Format("DatabaseLocationInfoResult.{0} is not supported", databaseLocationInfoOnOperationFailure));
                }
            }
            return(null);
        }
        public static bool IsLocal(this IMailboxLocation mailboxLocation)
        {
            string serverFqdn = mailboxLocation.ServerFqdn;

            return(string.Equals(serverFqdn, ComputerInformation.DnsFullyQualifiedDomainName, StringComparison.OrdinalIgnoreCase) || string.Equals(serverFqdn, ComputerInformation.DnsHostName, StringComparison.OrdinalIgnoreCase) || string.Equals(serverFqdn, "localhost", StringComparison.OrdinalIgnoreCase) || string.Equals(serverFqdn, Environment.MachineName, StringComparison.OrdinalIgnoreCase));
        }
示例#12
0
 public void SetSelectedMailboxLocation(IMailboxLocation mailboxLocation)
 {
     ArgumentValidator.ThrowIfNull("mailboxLocation", mailboxLocation);
     this.selectedMailboxLocation = mailboxLocation;
 }
示例#13
0
        private ExchangePrincipal BuildExchangePrincipal(IGenericADUser user, bool isSelectedMailboxArchive, ADObjectId selectedDatabaseId, Guid?selectedMailboxGuid, MailboxConfiguration mailboxConfiguration, IMailboxLocation selectedMailboxLocation, Func <ADObjectId, IMailboxLocation> locationFactory, RemotingOptions remotingOptions)
        {
            List <IMailboxInfo> list = new List <IMailboxInfo>();

            if (user.ArchiveGuid != Guid.Empty)
            {
                IMailboxInfo mailboxInfo5 = this.BuildMailboxInfo(user.ArchiveGuid, user.ArchiveDatabase, isSelectedMailboxArchive, selectedDatabaseId, selectedMailboxLocation, user, mailboxConfiguration, locationFactory);
                if (mailboxInfo5 != null)
                {
                    list.Add(mailboxInfo5);
                }
            }
            bool flag = false;

            if (selectedMailboxGuid != null && selectedMailboxGuid.Value != Guid.Empty)
            {
                if (user.MailboxLocations != null)
                {
                    flag = user.MailboxLocations.Any((IMailboxLocationInfo mailboxInfo) => mailboxInfo.MailboxGuid == selectedMailboxGuid.Value);
                }
                if (!flag && user.AggregatedMailboxGuids != null)
                {
                    flag = user.AggregatedMailboxGuids.Any((Guid mailbox) => mailbox == selectedMailboxGuid.Value);
                }
            }
            if (user.MailboxGuid != Guid.Empty)
            {
                bool         isSelected   = (selectedMailboxGuid != null && user.MailboxGuid.Equals(selectedMailboxGuid.Value)) || !flag || !isSelectedMailboxArchive;
                IMailboxInfo mailboxInfo2 = this.BuildMailboxInfo(user.MailboxGuid, user.MailboxDatabase, isSelected, selectedDatabaseId, selectedMailboxLocation, user, mailboxConfiguration, locationFactory);
                if (mailboxInfo2 != null)
                {
                    list.Add(mailboxInfo2);
                }
            }
            if (user.MailboxLocations != null)
            {
                foreach (IMailboxLocationInfo mailboxLocationInfo in user.MailboxLocations)
                {
                    IMailboxInfo mailboxInfo3 = this.BuildMailboxInfo(mailboxLocationInfo.MailboxGuid, mailboxLocationInfo.DatabaseLocation, mailboxLocationInfo.MailboxLocationType.Equals(MailboxLocationType.MainArchive) ? isSelectedMailboxArchive : (mailboxLocationInfo.MailboxGuid == selectedMailboxGuid), mailboxLocationInfo.DatabaseLocation, selectedMailboxLocation, user, mailboxConfiguration, locationFactory);
                    if (mailboxInfo3 != null)
                    {
                        list.Add(mailboxInfo3);
                    }
                }
            }
            if (user.AggregatedMailboxGuids != null)
            {
                foreach (Guid guid in user.AggregatedMailboxGuids)
                {
                    IMailboxInfo mailboxInfo4 = this.BuildMailboxInfo(guid, user.MailboxDatabase, selectedMailboxGuid == guid, selectedDatabaseId, selectedMailboxLocation, user, mailboxConfiguration, locationFactory);
                    if (mailboxInfo4 != null)
                    {
                        list.Add(mailboxInfo4);
                    }
                }
            }
            Func <IMailboxInfo, bool> mailboxSelector;

            if (isSelectedMailboxArchive)
            {
                mailboxSelector = ((IMailboxInfo mailbox) => mailbox.MailboxType == MailboxLocationType.MainArchive);
            }
            else if (selectedMailboxGuid != null && selectedMailboxGuid != Guid.Empty)
            {
                mailboxSelector = ((IMailboxInfo mailbox) => mailbox.MailboxGuid == selectedMailboxGuid);
            }
            else
            {
                mailboxSelector = ((IMailboxInfo mailbox) => mailbox.MailboxGuid == user.MailboxGuid && mailbox.MailboxType == MailboxLocationType.Primary);
            }
            return(this.BuildPrincipal(user, list, mailboxSelector, remotingOptions));
        }