This is an old revision of the document!
Table of Contents
Filtering TNEF (winmail.dat) attachments with Sieve
Microsoft Outlook uses the proprietary TNEF format to send attachments. With non-Microsoft email clients you will see the infamous winmail.dat attachment, which generally remains as a black box that you cannot open.
Here I explain a recipe to filter such mails at Local Delivery Agent stage, i. e. the mail is filtered before it arrives into the user mailbox, the MIME part of type Application/MS-TNEF is parsed and every file contained herein, is attached again as a standard MIME part.
The original TNEF attachment is retained, so the size of the email is roughly doubled.
Installing the tnef-filter script
You can download a tnef-filter script provided by Graham Edgecombe, from his GitHub repository. On my Debian 10 Buster installation, that requied the following libraries:
apt-gest install libconvert-tnef-perl libfile-mmagic-perl libmime-tools-perl
I copied the binary script into /usr/local/bin/tnef-filter.
The Sieve filter
require ["fileinto", "vnd.dovecot.filter", "mime", "foreverypart"]; # Filter with /usr/local/lib/dovecot/sieve-filter/tnef-filter.sh # if there is an attachment of type Application/MS-TNEF (e.g. winmail.dat). foreverypart { if header :mime :anychild :contenttype "Content-Type" "application/ms-tnef" { filter "tnef-filter.sh"; } }
You need to include the mime and foreverypart plugins.
I created the shell script tnef-filter.sh into the /usr/local/lib/dovecot/sieve-filter/ directry, because that directory is the one declared to contains Sieve filters. You can set that location into /etc/dovecot/conf.d/90-sieve-extprograms.conf:
plugin { sieve_filter_bin_dir = /usr/local/lib/dovecot/sieve-filter }