<ruleDefinition>
  <ConfigVersion>12.2.0.0</ConfigVersion>
  <!-- 
     Rules configuration best practices
     http://mswikis/mmsspp/MMSSPPWiki/Rule%31Config%31-%31Best%31Practices.aspx
   -->

  <conditions>
    <condition ref="1" paramname="CustomerMail" operator="EQ" value="NULL" />
    <condition ref="2" paramname="CustomerMail" operator="NOTEQ" value="NULL" />
    <condition ref="3" paramname="CustomerMail" operator="IN"  value="SUFFIX_IN_INCLUSIONLIST"/>
    <condition ref="4" paramname="CustomerMail" operator="NOTIN"  value="SUFFIX_IN_INCLUSIONLIST"/>
    <condition ref="5" paramname="CustomerMail" operator="IN"  value="MANAGED_ROUTING_ADDRESSLIST"/>
    <condition ref="6" paramname="CustomerMail" operator="NOTIN"  value="MANAGED_ROUTING_ADDRESSLIST"/>

    <condition ref="11" paramname="CustomerTargetAddress" operator="EQ"  value="NULL"/>
    <condition ref="12" paramname="CustomerTargetAddress" operator="NOTEQ"  value="NULL"/>
    <condition ref="13" paramname="CustomerTargetAddress" operator="IN"  value="SUFFIX_IN_INCLUSIONLIST"/>
    <condition ref="14" paramname="CustomerTargetAddress" operator="NOTIN"  value="SUFFIX_IN_INCLUSIONLIST"/>
    <condition ref="15" paramname="CustomerTargetAddress" operator="IN"  value="MANAGED_ROUTING_ADDRESSLIST"/>
    <condition ref="16" paramname="CustomerTargetAddress" operator="NOTIN"  value="MANAGED_ROUTING_ADDRESSLIST"/>

    <condition ref="21" paramname="homeMDB" operator="EQ"  value="NULL"/>
    <condition ref="22" paramname="homeMDB" operator="NOTEQ"  value="NULL"/>
    <condition ref="23" paramname="homeMTA" operator="NOTEQ"  value="NULL"/>
    <condition ref="24" paramname="CustomerHomeMDB" operator="EQ"  value="NULL"/>
    <condition ref="25" paramname="CustomerHomeMDB" operator="NOTEQ"  value="NULL"/>
    <condition ref="26" paramname="CustomerHomeMDB" operator="NOTEQ"  value="NULL"/>

    <condition ref="27" paramname="extensionAttribute9" operator="EQ" value="RemoveMsoMailbox"/>
    <condition ref="28" paramname="extensionAttribute9" operator="NOTEQ" value="RemoveMsoMailbox"/>
    <condition ref="29" paramname="extensionAttribute9" operator="EQ" value="CustomerMailboxExists"/>
    <condition ref="30" paramname="extensionAttribute9" operator="NOTEQ" value="CustomerMailboxExists"/>

    <condition ref="31" paramname="extensionAttribute10" operator="NOTEQ" value="RESMBX" />

    <condition ref="41" paramname="objectSID" operator="NOTWELLKNOWNSID"/>
    
    <condition ref="51" paramname="CustomerTargetAddress" operator="EXISTS"/>
    <condition ref="52" paramname="CustomerTargetAddress" operator="NOTEXISTS"/>
    <condition ref="53" paramname="CustomerTargetAddress" operator="VALIDSMTP" removeprefix="true"/>

    <condition ref="61" paramname="mail" operator="EXISTS"/>
    <condition ref="62" paramname="mail" operator="NOTEXISTS"/>
    <condition ref="63" paramname="mail" operator="VALIDSMTP"/>

    <condition ref="71" paramname="CustomerTargetAddress" operator="EQ" value="CustomerMail" valueisattribute="true" removeprefix="true"/>
    <condition ref="72" paramname="CustomerTargetAddress" operator="NOTEQ" value="CustomerMail" valueisattribute="true" removeprefix="true"/>

    <condition ref="81" paramname="groupType" operator="NOTEQ" value="-2147483646"/>

    <condition ref="91" paramname="CustomerMail" operator="EXISTS"/>
    <condition ref="92" paramname="CustomerMail" operator="NOTEXISTS"/>
    <condition ref="93" paramname="CustomerMail" operator="VALIDSMTP"/>
  </conditions>

  <!-- ******************************************************************************** -->
  <!-- 
    Filter Rules -  Rules that determine which objects are brought into the MV from 
                    the Customer Forests 
                    
    NOTE: These rules use the Customer CS Attributes for their values.
    -->
  <rule name="UserObjectFilter" returnValue="TRUE" verbose="TRUE">
    <!--
      This rule determines if the User Object should be brought into the MV 
      from the Customer Forests 
      
        (objectSID Not a Well-known SID) AND
        (mail exists)
      -->
    <commandExpression expression="{41}AND{61}"/>
  </rule>
  <rule name="ContactObjectFilter" returnValue="TRUE" verbose="TRUE">
    <!--
      This rule determines if the Contact Object should be brought into the MV 
      from the Customer Forests 
      
        (mail exists)
      -->
    <commandExpression expression="{61}"/>
  </rule>
  <rule name="GroupObjectFilter" returnValue="TRUE" verbose="TRUE">
    <!--
      This rule determines if the Group Object should be brought into the MV 
      from the Customer Forests 
      
        (objectSID Not a Well-known SID) AND
        (mail exists)
      -->
    <commandExpression expression="{41}AND{61}"/>
  </rule>

  <!-- ******************************************************************************** -->
  <!-- 
    Validation Rules -  Rules that determine if the object is a Valid User, Group or Contact
                        Object 
                        
    NOTE: These rules use the MV's attributes for their values.                        
  -->
  <rule name="IsUserObjectValid" returnValue="TRUE" verbose="TRUE">
    <!-- 
      This rule determines if the User Object is a valid User Object 

      (   (CustomerTargetAddress Exists) AND
          (CustomerTargetAddress is a Valid SMTP) AND
          (   (CustomerTargetAddress NOT IN Suffix Inclusion List) AND
              (CustomerMail Exists) AND
              (CustomerMail is a Valid SMTP) AND
              (   (   (CustomerMail IN Suffix Inclusion List) AND
                      (CustomerTargetAddress != CustomerMail)   ) OR
                  (   (CustomerMail NOT IN Suffix Inclusion List) AND
                      (CustomerTargetAddress == CustomerMail)   )   ) OR
          (   (CustomerTargetAddress IN Suffix Inclusion List) AND
              (CustomerTargetAddress == CustomerMail)   )   )   ) OR
      (   (CustomerTargetAddress Not Exists) AND
          (CustomerMail Exists) AND
          (CustomerMail is a Valid SMTP)    )   )
    -->
    <commandExpression expression="({51}AND{53}AND(({14}AND{91}AND{93}AND(({3}AND{72})OR({4}AND{71}))) OR ({13}AND{71}))) OR ({52}AND{91}AND{93})"/>
  </rule>

  <rule name="IsGroupObjectValid" returnValue="TRUE" verbose="TRUE">
    <!-- 
      This rule determines if the Group Object is a valid Group Object 

      (CustomerTargetAddress Does Not Exist) AND
      (CustomerMail Exists) AND
      (CustomerMail is a Valid SMTP)
    -->
    <commandExpression expression="{52}AND{91}AND{93}"/>
  </rule>

  <rule name="IsContactObjectValid" returnValue="TRUE" verbose="TRUE">
    <!-- 
      This rule determines if the Contact Object is a valid Contact Object 

      (   (CustomerTargetAddress Exists) AND
          (CustomerTargetAddress is a Valid SMTP) AND
          (   (CustomerTargetAddress NOT IN Suffix Inclusion List) AND
              (CustomerMail Exists) AND
              (CustomerMail is a Valid SMTP) AND
              (   (   (CustomerMail IN Suffix Inclusion List) AND
                      (CustomerTargetAddress != CustomerMail)   ) OR
                  (   (CustomerMail NOT IN Suffix Inclusion List) AND
                      (CustomerTargetAddress == CustomerMail)   )   ) OR
          (   (CustomerTargetAddress IN Suffix Inclusion List) AND
              (CustomerTargetAddress == CustomerMail)   )   )   )
      (   (CustomerTargetAddress Not Exists) AND
          (CustomerMail Exists) AND
          (CustomerMail is a Valid SMTP) AND
          (CustomerMail is NOT IN Suffix Inclusion List)   )
    -->
    <commandExpression expression="({51}AND{53}AND(({14}AND{91}AND{93}AND(({3}AND{72})OR({4}AND{71}))) OR ({13}AND{71}))) OR ({52}AND{91}AND{93}AND{4})"/>
  </rule>

  <!-- ******************************************************************************** -->
  <!--
      All of the following rules are checked when the ExchangeOnlineState determined by the 
      Customer AD attributes are changed.  
                        
      NOTE: These rules use the MV's Attributes for their values.                        
    -->
  
  <rule name="IsMailboxEnabledUser" returnValue="TRUE">
    <!--
        The following Rules determine if the User Object is for a Mailbox-Enabled User.
         
          (CustomerMail In Inclusion List) AND 
          (CustomerHomeMDB == NULL) AND
          ( (CustomerTargetAddress == null) OR (CustomerTargetAddress IN Managed Routing List) ) AND
          (ExtensionAttribute9 != "RemoveMsoMailbox") AND
          (ExtensionAttribute9 != "CustomerMailboxExists")
      -->
    <commandExpression expression="{3}AND{24}AND({11}OR{15})AND{28}AND{30}" />
  </rule>

  <rule name="DeprovisionMailboxEnabledUser" returnValue="TRUE">
    <!-- 
        The following Rules are used to determine if an existing Mailbox-Enabled User 
        should be deprovisioned (They are also used to verify an Object doesn't fulfill
        the deprovisioning rules when a new Mailbox-Enabled User is created).
      
          (ExtensionAttribute9 == "RemoveMsoMailbox") OR
          (CustomerMail Not In Inclusion List) OR
          ( (CustomerTargetAddress != null) AND 
            (CustomerTargetAddress Not In Inclusion List) AND 
            (CustomerTargetAddress Not In Managed Routing List) )
      -->
    <commandExpression expression="{27}OR({4}OR({12}AND{14}AND{16}))" /> 
  </rule>

  <rule name="IsMailEnabledUser" returnValue="TRUE">
    <!--  
        The following Rules determine if the User Object is for a Mail-Enabled User.

          (CustomerMail In Inclusion List) AND 
            (CustomerTargetAddress != null) AND 
            (CustomerTargetAddress Not In Managed Routing List) AND
            (CustomerHomeMDB == null) AND
            (ExtensionAttribute9 != "CustomerMailboxExists") 
          (CustomerMail In Inclusion List) AND (CustomerTargetAddress == null) AND ((CustomerHomeMDB != null) OR (ExtensionAttribute9 == "CustomerMailboxExists"))
          (CustomerMail != null) AND (CustomerMail Not In Inclusion List) AND (CustomerHomeMDB == null) AND (ExtensionAttribute9 != "CustomerMailboxExists") AND
            ( (CustomerTargetAddress == null) OR (CustomerTargetAddress Not In Inclusion List) )

        NOTE:     For the Lotus Notes Scenario (Mail In Inclusion List, TargetAddress == Mail and HomeMDB == null), we do not 
              provision nor deprovision any object.  Both the IsMailboxEnabledUser and IsMailEnabledUser Rules are false.
              As far as MMSSPP is concerned, the user is for Identity with ExchangeOnlineState set to Disabled (0).  Exchange, 
              on the other hand will see the targetAddress is set on the managed and will tag the User Object as a 
              Mail-Enabled User.
                  When the User is to be setup for migration (Lotus users copy the data from the one mailbox to the other), 
              the targetAddress is set to the Managed Routing List.  This does not cause MMSSPP to deprovision, since we never 
              have tagged this user as an MEU (ExchangeOnlineState was 0).  We will create a Mailbox User, though, as
              the IsMailboxEnabledUser Rule is now True.                
      -->
    <commandExpression expression="({3}AND{12}AND{16}AND{24}AND{30}) OR ({3}AND{11}AND({25}OR{29})) OR ({2}AND{4}AND{24}AND{30}AND({11}OR{14}))" />
  </rule>
  
  <rule name="DeprovisionMailEnabledUser" returnValue="TRUE">
    <!-- 
        This rule is checked when either an MEU is created (it is checked to verify that the deprovision logic is False) or
        when an existing MEU has an attribute change (Specifically DN, homeMDB, Mail, objectGUID, or TargetAddress) to 
        determine if the existing MEU should be deprovisioned.
          
        The deprovisioning rules are as follows:
          (CustomerMail == null) OR
            ( (CustomerMail In Inclusion List) AND (CustomerTargetAddress == null) AND (CustomerHomeMDB == NULL) AND (ExtensionAttribute9 != "CustomerMailboxExists") ) OR
            ( (CustomerMail In Inclusion List) AND (CustomerTargetAddress != null) AND ( (CustomerHomeMDB != NULL) OR (ExtensionAttribute9 == "CustomerMailboxExists") ) OR
            ( (CustomerMail In Inclusion List) AND (CustomerTargetAddress In Managed Routing List) AND (CustomerHomeMDB == NULL) AND (ExtensionAttribute9 != "CustomerMailboxExists")) OR
            ( (CustomerMail != null) AND (CustomerMail Not In Inclusion List) AND ( (CustomerHomeMDB != NULL) OR (ExtensionAttribute9 == "CustomerMailboxExists") )
            
        NOTE:     For the Lotus Notes Scenario (Mail In Inclusion List, TargetAddress == Mail and HomeMDB == null), we do not 
              provision nor deprovision any object.  Both the IsMailboxEnabledUser and IsMailEnabledUser Rules are false.
              As far as MMSSPP is concerned, the user is for Identity with ExchangeOnlineState set to Disabled (0).  Exchange, 
              on the other hand will see the targetAddress is set on the managed and will tag the User Object as a 
              Mail-Enabled User.
                  When the User is to be setup for migration (Lotus users copy the data from the one mailbox to the other), 
              the targetAddress is set to the Managed Routing List.  This does not cause MMSSPP to deprovision, since we never 
              have tagged this user as an MEU (ExchangeOnlineState was 0).  We will create a Mailbox User, though, as
              the IsMailboxEnabledUser Rule is now True.                
        -->
      <commandExpression expression="({1}) OR ({3}AND{11}AND{24}AND{30}) OR ({3}AND{12}AND({25}OR{29})) OR ({3}AND{15}AND{24}AND{30}) OR ({2}AND{4}AND({25}OR{29}))" />
    </rule>


  <rule name="IsMailEnabledContact" returnValue="TRUE">
    <!--  
        The following Rules determine if the User Object is for a Mail-Enabled User.

          (CustomerMail != null)
      -->
    <commandExpression expression="({2})" />
  </rule>

  <rule name="DeprovisionMailEnabledContact" returnValue="TRUE">
    <!-- 
        This rule is checked when either an MEU is created (it is checked to verify that the deprovision logic is False) or
        when an existing MEU has an attribute change (Specifically DN, homeMDB, Mail, objectGUID, or TargetAddress) to 
        determine if the existing MEU should be deprovisioned.
          
        The deprovisioning rules are as follows:
          (CustomerMail == null)
        -->
    <commandExpression expression="({1})" />
  </rule>

  <rule name="IsMailEnabledGroup" returnValue="TRUE">
    <!--  
        The following Rules determine if the User Object is for a Mail-Enabled User.

          (CustomerMail != null)
      -->
    <commandExpression expression="({2})" />
  </rule>

  <rule name="DeprovisionMailEnabledGroup" returnValue="TRUE">
    <!-- 
        This rule is checked when either an MEU is created (it is checked to verify that the deprovision logic is False) or
        when an existing MEU has an attribute change (Specifically DN, homeMDB, Mail, objectGUID, or TargetAddress) to 
        determine if the existing MEU should be deprovisioned.
          
        The deprovisioning rules are as follows:
          (CustomerMail == null)
        -->
    <commandExpression expression="({1})" />
  </rule>

  <!-- ******************************************************************************** -->
  <!--
      All of the following rules are used to determine if a user has a mailbox.  
                        
      NOTE: These rules use the either the Customer or the Managed CS's attributes for their values.                        
    -->

  <rule name="IsCustomerMailboxExists" returnValue="TRUE">
    <!-- 
        This rule is used in IAF-TargetAddress-IdIS and any change in below rule will result 
        in dependent attribute updates in IAF-TargetAddress-IdIS in customer MA.
        
          (CustomerHomeMDB != null) OR
          (ExtensionAttribute9 == CustomerMailboxExists)
      -->
    <commandExpression expression="{25}OR{29}" />
  </rule>

  <rule name="IsManagedMailboxExists" returnValue="TRUE">
    <!--
        This rule is used to determine if a Managed Mailbox exists.  It must use
        the Managed CS for processing 
      
        (homeMDB != NULL)
      
      -->

    <commandExpression expression="{22}" />
  </rule>

 </ruleDefinition>
