Using PostMaster filters on raw emails
Jens Bothe21. Dec 2016 | AdministrationConsultingUse cases
Disclaimer:
The practical examples presented in our technical blog (blog.otrs.com) and now in the expert category in our FAQ blog section serve as a source of ideas and documentation to show what is theoretically possible with OTRS in concrete scenarios or sometimes even for more exotic configurations. All configurations presented here were developed under laboratory conditions as a proof of concept.
We can only guarantee testing and implementation of these concepts to be error-free and productive if implemented in a workshop with one of our OTRS consultants. Without this, the responsibility lies with the customer himself. Please note that configurations from older OTRS versions may not work in the newer ones.
OTRS has a deep background on handling emails. One of the most powerful tools integrated is the ability to analyze incoming emails and even fetch data to different fields of a ticket. The best known filters are the “Match Filters” which can be configured through the admin panel.
These filters use Kernel::System::EmailParser to split the content of incoming emails into different parts, like the headers and body. Due to this splitting, it is not possible to analyze parts of an email which are not stored in the headers or the body.
Solving the issue
Deeply hidden in the Sysconfig, is the possibility to create postmaster filters which use the raw or plaintext content. This filter can be found in the PostMaster::PreFilterModule###4-CMD
section of the Ticket -> Core::PostMaster
group and matches if the command will create an output on STDOUT.
Let’s say I would like to set a Dynamic Field if the mail was signed by PGP/MIME. As the PGP signature is an additional MIME part within the mail, this is not possible with the regular filters.
Lets have a look on the raw email:
Subject: Some Test Mail
Message-ID: <dd5236ce@otrs.com>
Date: Wed, 21 Dec 2016 21:08:59 +0100
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
protocol="application/pgp-signature";
boundary="cIkbOuFPs5f5mcbVqptdx5bwHgr8Ca53h"
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--cIkbOuFPs5f5mcbVqptdx5bwHgr8Ca53h
Content-Type: multipart/mixed; boundary="QjgNWgJvSE4d1wRcsuMPf9MFTaAMnLIFb";
protected-headers="v1"
From: "Jens O. Bothe" <nobodye@otrs.com>
To: 'Jens Bothe' <nobody@otrs.com>
Message-ID: <dd5236ce0f@otrs.com>
Subject: Some Test Mail
--QjgNWgJvSE4d1wRcsuMPf9MFTaAMnLIFb
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Hey,
this is a test
((enjoy))
Jens
--QjgNWgJvSE4d1wRcsuMPf9MFTaAMnLIFb--
--cIkbOuFPs5f5mcbVqptdx5bwHgr8Ca53h
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
iEYEARECAAYFAlha4V8ACgkQZ4I/4k742SwdBgCgnNb6NbqLNkNw75eTjeVHhVtY
QLcAoMOW/++VqAOPSwlLRd8delBY5qym
=LpXU
-----END PGP SIGNATURE-----
--cIkbOuFPs5f5mcbVqptdx5bwHgr8Ca53h--
I want to filter on the part:
Content-Type: application/pgp-signature; name="signature.asc"
So I have to add as CMD: grep “Content-Type: application/pgp-signature”
The full part in the Sysconfig
For my latest customer I created some additional filters. The XML file can be found here: PostMasterFilter.xml
Theo at 09.07.2020, 11:37
Hi, I'm new to OTRS (community edition), and while reading your post I was wondering : When does this filtering occurs ? Is it happening between the moment you received a mail and before the ticket is created ? And is it possible to apply filters with something external to OTRS, like an ERP or a LDAP server ? (Any hints to do so will be very welcomed)
Jens Bothe at 18.04.2019, 10:02
You would need to develop your own filters
Prashant Jain at 18.04.2019, 07:02
can we remove some text/html content of the mail body based on filter criteria - Post Master Filter? Example if the incoming html email containssome logo and copyright then remove that logo and copyright string.