Mail filters can be attached to inbound bridges and reject unwanted eMails. The following mail filter types are available:
Mail filters can be chained and so make complex filtering possible. Each incoming eMail is checked against the configured filters and might be deleted or rejected and bounced back to the sender, depending on the configuration.
To create a new mail filter, go to folder "Mail Filter", right mouse click, and select "Create New Entity ...":
A mail filter consists a the following general attributes:
| Attribute | Meaning |
|---|---|
| Name | Some unique name of your choice. Mail filters are processed in lexical order of this name. |
| Filter Type | "header", "body", "attachment" or "size". |
| Reject On Match | Rejects the eMail if the filter matches or rejects it if it doesn't match. Default is true. This attribute is a way to invert the mail filter. |
| Rejection Message | The message which is send back to the sender in case the message is rejected and "Return to Sender" is true. |
| Return to Sender | Sends a rejection messages back to the sender if the message is rejected. Default is true. If it is set to false, the eMail is only deleted. |
Press "Create ..." to create the mail filter. Each mail filter has different specific properties which can be created here:
A header mail filter can check the following eMail headers:
The header name, e.g. "subject", must be specified as property name and a regular expression as the value. In the screen shot above the mail filter checks the subject of the content of the word "VIAGRA". Multiple properties with different headers can be defined and are handled like an "and" condition. For example, if the inbound bridge only accepts eMails from a particular domain and with a keyword in its subject, a "from" and a "subject" property with the appropriate regex needs to be defined.
A body mail filter checks the eMail body against the regular expressions of the filter properties. Multiple properties can be defined and are handled like an "and" condition. The name of the property can be freely selectable. The value contains the regular expression. For example:
Note that the mail filter uses "DOTALL" for the regex so the regex doesn't need to care about linefeeds.
This filter checks the MIME-type of attachments. The name of the property must be "mime-type" and the value the MIME-type which is checked against those of the attachments. The value is NOT a regular expression but a regular MIME-type, e.g. "application/pdf" for PDF documents or "application/*" for every thing under the "application" media type. Only 1 property "mime-type" can be defined. To filter multiple attachment MIME types, multiple filters can be defined.
The following attachment filter lets only PDF documents through:
A size mail filter checks the size of the eMail. There can only 1 filter property with name "max-size" be defined. The value of the property is the maximum size of an eMail in KB. Setting "Reject on Match" to false has no effect on this mail filter. The following example defines a size mail filter which rejects all eMail with a size greater than 1 MB:
Mail filters can be easily chained to create more complex filters. Each filter of the chain is handled in a "or" fashion. For example, to create a filter for an internal support system whith the following conditions:
this chain needs to be defined (covers the whole configuration from the routerconfig.xml):
<swiftlet name="xt$javamail">
<inbound-bridges>
<inbound-bridge name="support-inbound" enabled="true"
mail-host="mx.wombat.com" mail-host-account-name="xxx" mail-host-account-password="xxx"
mail-host-port="143" protocol="imap" target-name="support-inbound"
transformer-class="com.swiftmq.extension.javamail.inbound.MultipartTransformer">
<default-properties/>
<mail-filter-definition mail-filter-reject-from-address="noreply@wombat.com"
mail-filter-reject-queue="support-reject">
<mail-filters>
<mail-filter name="01"
filter-type="header"
rejection-message="This is an internal support system for wombat.com only!"
return-to-sender="true">
<filter-properties>
<filter-property name="from" value=".*@wombat.com"/>
<filter-property name="subject" value=".*TICKET#.*"/>
</filter-properties>
</mail-filter>
<mail-filter name="02" filter-type="body">
<filter-properties>
<filter-property name="01" value=".*VIAGRA.*"/>
</filter-properties>
</mail-filter>
<mail-filter name="03" filter-type="body">
<filter-properties>
<filter-property name="01" value=".*PORN.*"/>
</filter-properties>
</mail-filter>
<mail-filter name="04" filter-type="attachment"
reject-on-match="false"
rejection-message="Only PDF attachments accepted!"
return-to-sender="true">
<filter-properties>
<filter-property name="mime-type" value="application/pdf"/>
</filter-properties>
</mail-filter>
<mail-filter name="05" filter-type="size"
rejection-message="We don't accept eMails greater than 5 MB!"
return-to-sender="true">
<filter-properties>
<filter-property name="max-size" value="5120"/>
</filter-properties>
</mail-filter>
</mail-filters>
</mail-filter-definition>
<property-translations/>
</inbound-bridge>
</inbound-bridges>
<outbound-bridges>
<outbound-bridge name="support-reject" enabled="true" smtp-host="mx.wombat.com" source-name="support-reject">
<default-headers/>
<header-translations>
<header-translation name="01" message-property="from"/>
<header-translation name="02" mail-header="to" message-property="to"/>
<header-translation name="03" mail-header="subject" message-property="subject"/>
</header-translations>
</outbound-bridge>
</outbound-bridges>
</swiftlet>
Whenever an eMail is rejected and the respective mail filter is configured to send the mail back to the sender, a message is stored into a reject queue which must serve as the input queue for an outbound bridge. 2 properties can be defined to configure the reject sender eMail address and the reject queue name:
The JMS message stored in the reject queue is a JMS TextMessage so the appropriate outbound bridge must have a TextMessageTransformer. The message properties set in the JMS TextMessage are:
The outbound bridge must have the appropriate property translations defined.