<processor name="root">
  <mailet match="All" class="ToRepository" onMailetException="ignore">
    <passThrough> true </passThrough>
    <repositoryPath> file://var/mail/inbound/ </repositoryPath>
  </mailet>

  <mailet match="All" class="PostmasterAlias"/>

  <mailet match="RelayLimit=30" class="Null"/>

  <!-- RemoveMimeHeaders used internally -->
  <mailet match="All" class="BeanShell">
    <script>/opt/james/bsh/mimeheads.bsh</script>
    <method>RemoveMimeHeaderList</method>
    <name1>Received-SPF</name1>
    <name2>X-UserIsAuth</name2>
    <name3>X-WasSigned</name3>
    <name4>X-MessageIsSpam</name4>
    <name5>X-VirusChecked</name5>
    <name6>X-SpamChecked</name6>
    <name7>X-MessageIsSpamProbability</name7>
    <name8>X-Trusted</name8>
  </mailet>

  <!-- Messages from Trust source -->
  <mailet match="RemoteAddrInNetwork=127.0.0.0/8,10.0.0.0/8" class="SetMailAttribute">
    <org.apache.james.trusted>true</org.apache.james.trusted>
  </mailet>
  <mailet match="SMTPAuthSuccessful" class="SetMailAttribute">
    <org.apache.james.trusted>true</org.apache.james.trusted>
  </mailet>
  <mailet match="HasMailAttributeWithValue=org.apache.james.trusted, true" class="SetMimeHeader">
    <name>X-Trusted</name>
    <value>true</value>
  </mailet>

  <!-- Messages from authenticated sender -->
  <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
    <name>X-UserIsAuth</name>
    <value>true</value>
  </mailet>
  
  <!-- Send mails to the crossroad processor -->
  <mailet match="All" class="ToProcessor">
    <processor> crossroad </processor>
  </mailet>

</processor>

<!-- Processor crossroad is local or remote delivery -->
<processor name="crossroad">
  <!-- Is the recipient is for a local account, deliver it locally -->
  <mailet match="RecipientIsLocal" class="ToProcessor">
    <processor> local-account </processor>
  </mailet>
  
  <!-- If the host is handled by this server as secondary -->
  <!-- relay to remote host -->
  <mailet match="HostIs=xxxxxxXX.es,xxxxxxXX.com,xxxxxxXX.net,xxxxxxXX.org,xxxxxxXX.local" class="ToProcessor">
    <processor> secondary-domain </processor>
  </mailet>
  
  <!-- If the host is handled by this server and it did not get -->
  <!-- locally delivered, this is an invalid recipient -->
  <mailet match="HostIsLocal" class="ToProcessor">
    <processor> address-error </processor>
    <notice>550 - Requested action not taken: no such user here</notice>
  </mailet>
  
  <mailet match="HasMailAttributeWithValue=org.apache.james.trusted, true" class="ToProcessor">
    <processor> remote-domain </processor>
  </mailet>

  <mailet match="All" class="ToProcessor">
    <processor> relay-denied </processor>
    <notice>550 - Requested action not taken: relaying denied</notice>
  </mailet>
</processor>
  
<!-- Processor for a local account, deliver it locally -->
<processor name="local-account">
  <mailet match="All" class="LocalDelivery"/>
</processor>

<!-- Processor secondary-domain is a processor for remote delivery of secondary domains -->
<processor name="secondary-domain">
  <!-- Attempt remote delivery using the specified repository for the spool, -->
  <!-- using delay time to retry delivery and the maximum number of retries -->
  <mailet match="All" class="RemoteDelivery">
    <outgoing> file://var/mail/relay-xxxxxxXX/ </outgoing>
    <!-- 7 day retry period -->
    <delayTime>  5 minutes </delayTime>
    <delayTime> 10 minutes </delayTime>
    <delayTime> 15 minutes </delayTime>
    <delayTime> 30 minutes </delayTime>
    <delayTime> 1 hour </delayTime>
    <maxRetries> 171 </maxRetries>
    <!-- The number of threads that should be trying to deliver outgoing messages -->
    <deliveryThreads> 1 </deliveryThreads>
    <!-- If false the message will not be sent to given server if any recipients fail -->
    <sendpartial>false</sendpartial>
    <!-- By default we send bounces to the "bounce" processor -->
    <bounceProcessor>bounces</bounceProcessor>
    <gateway>10.x.x.x</gateway>
    <gatewayPort>25</gatewayPort>
  </mailet>
</processor>

<!-- This processor handles messages that are for local domains, where the user is unknown -->
<processor name="address-error">
  <!-- To avoid bouncing/archiving spam, uncomment this matcher/mailet configuration -->
  <mailet match="HasMailAttribute=isSpam" class="Null" onMatchException="noMatch"/>
  
  <!-- To destroy all messages, uncomment this matcher/mailet configuration -->
  <mailet match="All" class="Null"/>
</processor>

<processor name="relay-denied">
  <!-- To destroy all messages -->
  <mailet match="All" class="Null"/>
</processor>

<!-- Processor remote-domain is a processor for remote delivery -->
<processor name="remote-domain">
  <!-- Attempt remote delivery using the specified repository for the spool, -->
  <!-- using delay time to retry delivery and the maximum number of retries -->
  <mailet match="All" class="RemoteDelivery">
    <outgoing> file://var/mail/outgoing/ </outgoing>

    <delayTime>  5 minutes </delayTime>
    <delayTime> 10 minutes </delayTime>
    <delayTime> 45 minutes </delayTime>
    <delayTime>  2 hours </delayTime>
    <delayTime>  3 hours </delayTime>
    <delayTime>  6 hours </delayTime>
    <maxRetries> 25 </maxRetries>
    
    <!-- The number of threads that should be trying to deliver outgoing messages -->
    <deliveryThreads> 1 </deliveryThreads>
    
    <!-- If false the message will not be sent to given server if any recipients fail -->
    <sendpartial>false</sendpartial>
    
    <!-- By default we send bounces to the "bounce" processor -->
    <!-- By removing this configuration James will fallback to hardcoded bounce -->
    <!-- notifications -->
    <bounceProcessor>bounces</bounceProcessor>
  </mailet>
</processor>

<!-- DSNBounce properly create a DSN compliant bounce -->
<processor name="bounces">
  <mailet match="All" class="DSNBounce">
    <passThrough>false</passThrough>
  </mailet>
</processor>

<processor name="error">
  <!-- Logs any messages to the repository specified -->
  <mailet match="All" class="ToRepository">
    <repositoryPath> file://var/mail/error/ </repositoryPath>
  </mailet>
</processor>

