<?xml version="1.0"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
 -->

<mailetcontainer enableJmx="true">

    <context>
        <postmaster>postmaster@open-paas.org</postmaster>
    </context>

    <spooler>
        <threads>20</threads>
    </spooler>

    <processors>

        <processor state="root" enableJmx="true">
            <mailet match="All" class="PostmasterAlias"/>
            <mailet match="RelayLimit=30" class="Null"/>
            <mailet match="dlp.Dlp" class="ToProcessor">
                 <processor>dlpQuarantine</processor>
            </mailet>
            <mailet match="All" class="ToProcessor">
                <processor>transport</processor>
            </mailet>
        </processor>

        <processor state="dlpQuarantine" enableJmx="true">
            <mailet match="All" class="ToSenderDomainRepository">
                 <urlPrefix>cassandra://var/mail/dlp/quarantine/</urlPrefix>
            </mailet>
        </processor>

        <processor state="dlpReject" enableJmx="true">
            <mailet match="All" class="ToSenderDomainRepository">
                 <urlPrefix>cassandra://var/mail/dlp/rejected/</urlPrefix>
            </mailet>
        </processor>

        <processor state="error" enableJmx="true">
            <mailet match="All" class="Bounce"/>
            <mailet match="All" class="ToRepository">
                <repositoryPath>file://var/mail/error/</repositoryPath>
            </mailet>
        </processor>

        <processor state="transport" enableJmx="true">
            <matcher name="mdn-matcher" match="org.apache.james.mailetcontainer.impl.matchers.And">
                <matcher match="HasMimeType=multipart/report"/>
                <matcher match="HasMimeTypeParameter=report-type=disposition-notification"/>
            </matcher>
            <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
                <name>X-UserIsAuth</name>
                <value>true</value>
            </mailet>
            <mailet match="HasMailAttribute=org.apache.james.SMIMECheckSignature" class="SetMimeHeader">
                <name>X-WasSigned</name>
                <value>true</value>
            </mailet>
            <mailet match="IsOverQuota" class="ToProcessor">
                <processor>over-quota</processor>
            </mailet>
            <!-- Beginning of contact pipeline -->
            <mailet match="SenderIsLocal" class="ContactExtractor">
                <attribute>extractedContacts</attribute>
            </mailet>
            <mailet match="All" class="AmqpForwardAttribute">
                <uri>amqp://rabbitmq:5672</uri>
                <exchange>collector:email</exchange>
                <attribute>extractedContacts</attribute>
            </mailet>
            <!-- End of contact pipeline -->
            <mailet match="All" class="RemoveMimeHeader">
                <name>bcc</name>
            </mailet>
            <mailet match="All" class="RemoveMimeHeader">
                <name>X-MEETING-UID,X-MEETING-METHOD,X-MEETING-RECURRENCE-ID,X-MEETING-SEQUENCE,X-MEETING-DTSTAMP</name>
            </mailet>
            <mailet match="All" class="RecipientRewriteTable" />
            <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/>
            <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
            <mailet match="mdn-matcher" class="org.apache.james.jmap.mailet.ExtractMDNOriginalJMAPMessageId"/>
            <mailet match="RecipientIsLocal" class="ToProcessor">
                <processor>local-recipient</processor>
            </mailet>
            <!--
            <mailet match="HostIsLocal" class="ToProcessor">
                <processor>local-address-error</processor>
                <notice>550 - Requested action not taken: no such user here</notice>
            </mailet>
            -->
            <mailet match="SMTPAuthSuccessful" class="RemoteDelivery">
                <outgoingQueue>outgoing</outgoingQueue>
                <delayTime>5000, 100000, 500000</delayTime>
                <maxRetries>25</maxRetries>
                <maxDnsProblemRetries>0</maxDnsProblemRetries>
                <deliveryThreads>10</deliveryThreads>
                <sendpartial>true</sendpartial>
                <bounceProcessor>bounces</bounceProcessor>
            </mailet>
            <mailet match="All" class="ToProcessor">
                <processor>relay-denied</processor>
            </mailet>
        </processor>

        <processor state="local-recipient" enableJmx="true">
            <!-- ICAL pipeline -->
            <mailet match="All" class="StripAttachment">
                <mimeType>text/calendar</mimeType>
                <attribute>rawIcalendar</attribute>
            </mailet>
            <mailet match="All" class="MimeDecodingMailet">
                <attribute>rawIcalendar</attribute>
            </mailet>
            <mailet match="All" class="ICalendarParser">
                <sourceAttribute>rawIcalendar</sourceAttribute>
                <destinationAttribute>icalendar</destinationAttribute>
            </mailet>
            <mailet match="All" class="ICALToHeader">
                <attribute>icalendar</attribute>
            </mailet>
            <mailet match="RecipientIsLocal" class="LogMessage"/>
            <mailet match="All" class="ICALToJsonAttribute">
                <source>icalendar</source>
                <destination>icalendarAsJson</destination>
                <rawSource>rawIcalendar</rawSource>
            </mailet>
            <mailet match="All" class="AmqpForwardAttribute">
                <uri>amqp://rabbitmq:5672</uri>
                <exchange>james:events</exchange>
                <attribute>icalendarAsJson</attribute>
            </mailet>
            <!-- End of ICAL pipeline -->
            <mailet match="All" class="AddDeliveredToHeader"/>
            <mailet match="All" class="LocalDelivery"/>
        </processor>

        <processor state="local-address-error" enableJmx="true">
            <mailet match="All" class="Bounce">
                <attachment>none</attachment>
            </mailet>
            <mailet match="All" class="ToRepository">
                <repositoryPath>file://var/mail/address-error/</repositoryPath>
            </mailet>
        </processor>

        <processor state="relay-denied" enableJmx="true">
            <mailet match="All" class="Bounce">
                <attachment>none</attachment>
            </mailet>
            <mailet match="All" class="ToRepository">
                <repositoryPath>file://var/mail/relay-denied/</repositoryPath>
                <notice>Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation</notice>
            </mailet>
        </processor>

        <processor state="bounces" enableJmx="true">
            <mailet match="All" class="DSNBounce">
                <passThrough>false</passThrough>
            </mailet>
        </processor>

        <processor state="over-quota" enableJmx="true">
            <mailet match="All" class="MetricsMailet">
                <metricName>mailet-over-quota-error</metricName>
            </mailet>
            <mailet match="All" class="Bounce">
                <message>The following recipients do not have enough space for storing the email you sent them.</message>
                <attachment>none</attachment>
            </mailet>
            <mailet match="All" class="ToRepository">
                <repositoryPath>file://var/mail/over-quota-error/</repositoryPath>
            </mailet>
        </processor>

    </processors>

</mailetcontainer>


