private static RecipientTypeDetails CalculateLegacyMailboxRTD(ADUser user)
 {
     if (MailboxMoveHelper.IsLinkedAccount(user))
     {
         return(RecipientTypeDetails.LinkedMailbox);
     }
     if (MailboxMoveHelper.IsSelfSid(user.MasterAccountSid))
     {
         return(RecipientTypeDetails.SharedMailbox);
     }
     return(RecipientTypeDetails.UserMailbox);
 }
 private static void UpdateRecipientTypeProperties(ADUser source, int sourceServerVersion, ADUser target, int targetServerVersion, MailboxMoveHelper.Scenario scenario, MailboxMoveType moveType, MailboxMoveTransition transition)
 {
     if (!MailboxMoveHelper.IsMovingPrimary(moveType))
     {
         return;
     }
     if (scenario == MailboxMoveHelper.Scenario.CrossPremiseOnboarding && transition == MailboxMoveTransition.UpdateSourceUser && MailboxMoveHelper.IsRemoteMailboxTypeDefined(sourceServerVersion))
     {
         source.RemoteRecipientType = MailboxMoveHelper.CalculateSourceRRT(source.RecipientTypeDetails);
     }
     else if (scenario == MailboxMoveHelper.Scenario.CrossPremiseOffboarding && transition == MailboxMoveTransition.UpdateTargetUser && MailboxMoveHelper.IsRemoteMailboxTypeDefined(targetServerVersion))
     {
         target.RemoteRecipientType = RemoteRecipientType.Migrated;
     }
     if (transition == MailboxMoveTransition.UpdateTargetUser)
     {
         RecipientTypeDetails recipientTypeDetails = (source.RecipientTypeDetails != RecipientTypeDetails.None) ? source.RecipientTypeDetails : MailboxMoveHelper.CalculateLegacyMailboxRTD(source);
         if (target.MasterAccountSid == null && MailboxMoveHelper.IsResourceOrShared(recipientTypeDetails))
         {
             target.MasterAccountSid = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
         }
         if (MailboxMoveHelper.IsRTDRDTDefined(targetServerVersion))
         {
             target.RecipientTypeDetails = MailboxMoveHelper.CalculateTargetRTD(recipientTypeDetails, MailboxMoveHelper.IsLinkedAccount(target));
             target.RecipientDisplayType = new RecipientDisplayType?(MailboxMoveHelper.CalculateTargetRDT(target.RecipientTypeDetails, MailboxMoveHelper.IsSecurityPrincipal(target)));
         }
         else
         {
             target.RecipientTypeDetails = RecipientTypeDetails.None;
             target.RecipientDisplayType = null;
         }
     }
     if (transition == MailboxMoveTransition.UpdateSourceUser)
     {
         if (MailboxMoveHelper.IsRTDRDTDefined(sourceServerVersion))
         {
             source.RecipientDisplayType = new RecipientDisplayType?(MailboxMoveHelper.CalculateSourceRDT(source.RecipientTypeDetails, MailboxMoveHelper.IsACLableSyncedObjectEnabled(source, scenario) && MailboxMoveHelper.IsSecurityPrincipal(source)));
             source.RecipientTypeDetails = MailboxMoveHelper.CalculateSourceRTD(source, sourceServerVersion, scenario);
             return;
         }
         source.RecipientTypeDetails = RecipientTypeDetails.None;
         source.RecipientDisplayType = null;
     }
 }
 private static bool IsSecurityPrincipal(ADUser user)
 {
     return(!MailboxMoveHelper.IsSelfSid(user.MasterAccountSid) && ((user.UserAccountControl & UserAccountControlFlags.AccountDisabled) == UserAccountControlFlags.None || MailboxMoveHelper.IsLinkedAccount(user)));
 }