Search

Ubuntu - Handle winmail.dat with Thunderbird and Nautilus

Contents[Hide]

dropcap-thunderbird

ubuntu-winmail-datWhen 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 :

  1. open the archive
  2. extract the files to a temporary directory
  3. convert filenames to UTF-8
  4. 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.

/usr/local/sbin/tnef-extract

#!/bin/sh
# --------------------------------------------
# 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
WORK_DIR="/tmp/attachment-winmail"

# 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
rm "$1"

# open nautilus windows in the extracted directory
nautilus "$WORK_DIR"

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 :

  1. create a .desktop file to declare the action
  2. 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.

~/.local/share/applications/tnef.desktop

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/usr/local/sbin/tnef-extract
Name=TNEF attachment extraction
Icon=/usr/share/icons/gnome/48x48/actions/document-open.png

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

~/.local/share/applications/mimeapps.list

...
[Added Associations]
application/ms-tnef=tnef.desktop;
...

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 :

  1. one to declare the mime type
  2. 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.

~/.thunderbird/*.default/mimeTypes.rdf

<?xml version="1.0"?>
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
...
  <RDF:Seq RDF:about="urn:schemes:root">
  </RDF:Seq>
  <RDF:Description RDF:about="urn:schemes">
    <NC:Protocol-Schemes RDF:resource="urn:schemes:root"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetypes">
    <NC:MIME-types RDF:resource="urn:mimetypes:root"/>
  </RDF:Description>
...
  <RDF:Description RDF:about='urn:mimetype:application/ms-tnef' NC:value='application/ms-tnef' NC:editable='true' NC:fileExtensions='dat' NC:description='TNEF attachment'>
    <NC:handlerProp RDF:resource='urn:mimetype:handler:application/ms-tnef'/>
  </RDF:Description>
  <RDF:Description RDF:about='urn:mimetype:handler:application/ms-tnef' NC:alwaysAsk='false' NC:saveToDisk='false' NC:useSystemDefault='false' NC:handleInternal='false'>

    <NC:externalApplication RDF:resource='urn:mimetype:externalApplication:application/ms-tnef'/>
  </RDF:Description>
  <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' />
  <RDF:Seq RDF:about="urn:mimetypes:root">
    <RDF:li RDF:resource='urn:mimetype:application/ms-tnef'/>
    ...
  </RDF:Seq>
...
</RDF:RDF>

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.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus