When you receive mails from some misconfigured Microsoft Outlook email clients, a file attachment called winmail.dat may be added as an attachment to the message. This file contains formatting information and any attachments sent with the original message. As the file is not recognized by Thunderbird (and many other email clients), you can't see any of the attachments sent with the original message in Thunderbird's message view.
These winmail.dat files are encoded following the Transport Neutral Encapsulation Format (TNEF) and are sent using the application/ms-tnef mime type.
This article explains how to setup your system to :
- extract files from a winmail.dat attachment
- declare the application/ms-tnef mime type
- create a complete interaction with Nautilus and Thunderbird
With this setup, you won't need any specific plugin (like Lookout) and you will be able to simply select a winmail.dat attachment in Thunderbird or Nautilus and it will open a window with all the files embedded within this attachment.
It has been tested under Ubuntu Precise 12.04, Gnome Shell 3.4 and Thunderbird 17, but it should be applicable to any other Linux distribution using Gnome Shell.
1. Install TNEF handler
To be able to extract files from a winmail.dat attachment, you need to install a TNEF format handler.
TNEF handler software is present in Ubuntu repository, so it can be installed very easily.
You'll also need a tool to convert filenames from GBK (windows) encoding to UTF-8.
# sudo apt-get install tnef convmv
2. Declare the Extraction Script
As a winmail.dat is in fact an archivage containing one or more files, the main idea is to :
- open the archive
- extract the files to a temporary directory
- convert filenames to UTF-8
- show this directory content in a Nautilus window
After these steps, you'll be able to decide what to do with these attachments (to open them with the default application, to save them in some other directory, ...).
This can be done with a very basic and simple script.
# Script to extract TNEF attachments
# in a temporary directory and
# to open a Nautilus window
# Depends on tnef package
# Parameter :
# $1 - full path to tnef attachment file
# Revision history :
# 17/07/2013 - Creation by N. Bernaerts
# set working directory
# remove any existing directory
rm --recursive "$WORK_DIR"
# create temporary directory
mkdir -p "$WORK_DIR"
# extract attachment
tnef --directory="$WORK_DIR" --file="$1"
# convert filenames to UTF-8
convmv -f gbk -t utf8 --notest $WORK_DIR/*
# remove temporary attachment
# open nautilus windows in the extracted directory
You can download and install this script straight from this site
# sudo wget -O /usr/local/sbin/tnef-extract http://bernaerts.dyndns.org/download/ubuntu/tnef/tnef-extract
# sudo chmod +x /usr/local/sbin/tnef-extract
You can now call the script from a console with your winmail.dat attachment file as parameter.
You'll get its full content of this attachment available in /tmp/attachment-winmail.
Next time you'll call this script, it will replace this content with the content of the new attachment.
3. Setup Nautilus Interaction
As we've seen, we can now open a winmail.dat attachment via a console. Next step is to setup a full Nautilus interaction.
What we want to do now is to double-click on a winmail.dat attachment file from Nautilus to extract it and open a window with its content.
This can be done in 2 steps :
- create a .desktop file to declare the action
- create a file association to this action
All .desktop files are located under ~/.local/share/applications.
Action to extract TNEF winmail.dat attachments will be handled by the tnef.desktop file.
Name=TNEF attachment extraction
This file can be downloaded and installed from this site
# wget -O $HOME/.local/share/applications/tnef.desktop http://bernaerts.dyndns.org/download/ubuntu/tnef/tnef.desktop
# chmod +x $HOME/.local/share/applications/tnef.desktop
winmail.dat attachments are received with the following mime type : application/ms-tnef
So we have to declare the association between this mime type and the previous action.
This is done by adding a line for this mime type in ~/.local/share/applications/mimeapps.list
Now that interaction is done, you can simply double-click on a winmail.dat attachment file from Nautilus, it will open a window with its content.
4. Setup Thunderbird Interaction
Last step is to setup a complete Thunderbird interaction. Thunderbird should be closed during this step.
What we want to achieve is to simply click on a winmail.dat attachment in a Thunderbird mail to automatically open a Nautils window with the attachment content.
This can be done easily by adding 2 entries in the file mimeTypes.rdf describing mime types handling in Thunderbird :
- one to declare the mime type
- one to declare the external handling script
As this file is in the user profile, which has a random name, you need to open it with this simple command :
# gedit `ls $HOME/.thunderbird/*.default/mimeTypes.rdf`
You need to add the lines in red around the line in black.
<RDF:Description RDF:about='urn:mimetype:application/ms-tnef' NC:value='application/ms-tnef' NC:editable='true' NC:fileExtensions='dat' NC:description='TNEF attachment'>
<RDF:Description RDF:about='urn:mimetype:handler:application/ms-tnef' NC:alwaysAsk='false' NC:saveToDisk='false' NC:useSystemDefault='false' NC:handleInternal='false'>
<RDF:Description RDF:about='urn:mimetype:externalApplication:application/ms-tnef' NC:prettyName='tnef-extract' NC:path='/usr/local/sbin/tnef-extract' />
<RDF:Description RDF:about='urn:handler:local:/usr/local/sbin/tnef-extract' NC:prettyName='tnef-extract' NC:path='/usr/local/sbin/tnef-extract' />
If you have freshly installed Thunderbird and you don't want to do some file editing, you can alternatively download the file straight from this site :
# wget -O `ls $HOME/.thunderbird/*.default/mimeTypes.rdf` http://bernaerts.dyndns.org/download/ubuntu/tnef/mimetypes.rdf
You can now open Thunderbird and click on one of these misteryous winmail.dat attachment.
A Nautilus window should open with the attachment content !
Hope it helped to save you some time and efforts.