/usr/share/sanitizer/contrib/tnef2multipart.pl is in sanitizer 1.76-5.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | #!/usr/bin/perl -w
#
###############################################################################
# !!!NOTE!!!
#
# This is not being maintained within the Anomy tree, please check the
# author's web site for the most recent version. This one was downloaded
# from http://advosys.ca/papers/filter-misc/tnef2multipart.pl on 30.04.2003.
#
###############################################################################
#
# tnef2multipart.pl v0.02
#
# Convert an MS Outlook TNEF attachment bundle ("winmail.dat")
# into a standard MIME multipart/mixed section.
#
# For use with Anomy Sanitizer 1.56+ (http://mailtools.anomy.net/)
#
# Copyright 2003 Advosys Consulting Inc., Ottawa
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# USAGE:
#
# Use this as the scanner for file name "winmail.dat"
# For example, in your anomy.conf:
# file_list_1 = (?i)(winmail.dat)
# file_list_2_policy = accept:drop:drop:drop
# file_list_2_scanner = 0:::/usr/local/bin/tnef2multipart.pl %FILENAME
#
# Requires the following Perl modules:
# MIME::Entity
# MailTools
# IO::Stringy
# LWP::MediaTypes
# Convert::TNEF
#
# Changelog:
# v0.01 Initial write
# v0.02 Security: unset PATH and disallow spaces in TNEF filenames
# File locations
# (CHANGE AS REQUIRED TO MATCH YOUR SERVER)
my $ANOMY = '/usr/local/smtpfilter/anomy';
my $ANOMY_CONF = '/usr/local/smtpfilter/anomy.conf';
my $SPOOLDIR = '/var/spool/filter'; # Temp directory to use
my $typesfile = '/etc/mime.types'; # Location of your system's mime.types file
# ---------------------------------------
# Few user servicable parts below
use strict;
use Convert::TNEF;
use MIME::Entity;
use LWP::MediaTypes qw(guess_media_type);
# Make PATH safer:
$ENV{'PATH'} = $SPOOLDIR;
# Grab name of TNEF file to process:
my $tneffile = shift;
die("Usage: tnef2multipart <filename>\n") unless $tneffile;
die("Can't open $tneffile for reading: $!\n") unless -f $tneffile;
$ANOMY .= '/bin/sanitizer.pl';
# Create a temp dir:
my $tempdir = "$SPOOLDIR/tnef-$$"; # Where to extract each TNEF part
mkdir $tempdir or die("Can't create directory $tempdir: $!\n");
my $tnef = Convert::TNEF->read_in($tneffile) or die $Convert::TNEF::errstr;
my @files = ();
for ($tnef->attachments) {
my $fname = "$tempdir/" . sanitize( $_->longname );
push @files, $fname;
open(OUTFILE,">$fname") or die "Can't write attachment: $!\n";
print OUTFILE $_->data;
close OUTFILE;
}
# Cleanup:
$tnef->purge;
# Create a new multipart/mixed MIME file:
my $top = MIME::Entity->build(Type =>"multipart/mixed");
# Improve LWP's MIME type guessing by adding system's mime.types:
LWP::MediaTypes->read_media_types($typesfile);
for my $file ( @files ) {
my $type = guess_media_type($file);
$top->attach(
Path => $file,
Type => $type,
Disposition => "attachment",
Encoding => "Base64"
);
}
# Filter the MIME file with Anomy Sanitizer again, to apply security policy to
# files that were formerly hidden inside the TNEF:
# Quick 'n' dirty way: open a pipe to the sanitizer script:
open(SAN,"|$ANOMY $ANOMY_CONF > $SPOOLDIR/mime-$$") or die "Can't pipe to $ANOMY: $!\n";
$top->print(\*SAN) or die "Error piping to $ANOMY: $!\n";
close SAN;
# Cleanup:
unlink @files;
rmdir $tempdir;
unlink $tneffile;
# Tell Anomy Sanitizer about the conversion:
print "Anomy-FileScan-Description: Converted to MIME from the original TNEF file\n";
print "Anomy-FileScan-NewName: mime-$$\n";
print "Anomy-FileScan-NewFile: $SPOOLDIR/mime-$$\n";
print "Anomy-FileScan-NewType: multipart/mixed\n";
print "Anomy-FileScan-NewEnc: binary\n\n";
exit 0;
sub sanitize {
# Replace potentially nasty characters from input
my $param = shift;
my $ok_chars = 'a-zA-Z0-9._-';
$param =~ s/[^$ok_chars]/_/go;
return $param;
}
|