Using PostMaster filters on raw emails
Jens Bothe21. Dec 2016 | AdministrationConsultingUse cases
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: <firstname.lastname@example.org> 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" <email@example.com> To: 'Jens Bothe' <firstname.lastname@example.org> Message-ID: <email@example.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