As an opensource shop, one of the strangest problems we had to face with email is the way Microsoft Outlook/Outlook Express handles email attachments. They decided to encode the attachments into a single attachment and name it winmail.dat. Third party applications don't seem to want to open it. So how do you get around it?
Here's what you need to get MIMEDefang to extract winmail.dat attachments:
1) A Linux mail server.
2) A working installation of MIMEDefang.
3) The ytnef libraries installed and the binary located at /usr/local/bin/ytnef.
4) Add this code to your "sub filter" in /etc/mail/mimedefang-filter
# if this is a application/ms-tnef message then extract and delete it
if (lc($type) eq "application/ms-tnef") {
@tnef_files = extract_tnef( $entity );
my $tnef_file_qty = @tnef_files;
if( $tnef_file_qty > 0 ) {
md_syslog( 'info', "ytnef extracted some files so we are now dropping the winmail.dat mime part" );
} else {
md_syslog( 'info', "ytnef didn't find any attachments, but we are dropping the winmail.dat mime part anyway" );
}
return action_drop();
}
5) Add the extract_tnef procedure somewhere in /etc/mail/mimedefang-filter. I put it at the end, just above the "1;" where they explain not to delete the line or Perl will complain.
#***********************************************************************
# %PROCEDURE: extract_tnef
# %ARGUMENTS:
# entity -- a Mime::Entity object (see MIME-tools documentation for details)
# %RETURNS:
# A array of filenames extracted from the tnef part
# %DESCRIPTION: # This function extracts the attachments from a tnef file (winmail.dat)
# then provides a array of the files so that they can be attached later.
#***********************************************************************
sub extract_tnef( $ ) {
my ( $entity ) = @_;
my ( $body ) = $entity->bodyhandle;
my @tnef_files = ();
if( ! defined( $body ) ){
return @tnef_files;
}
# Get filename
my ( $path ) = $body->path;
if( ! defined( $path ) ){
return @tnef_files;
}
@new_files = `/usr/local/bin/ytnef -f Work $path`;
foreach my $file ( @new_files ){
chomp( $file );
push( @tnef_files, $file );
md_syslog( 'info', "Found file $file in winmail.dat attachment" );
}
return @tnef_files;
}
And that should do it! When the end user checks their email, they will have the real attachments and never see those nasty winmail.dat files again!
Craig Deering
Network Engineer
Astro Shapes, Inc. - Aluminum Extrusion Industry
Website - http://www.astroshapes.com