This file is indexed.

/usr/bin/simplify is in sanitizer 1.76-3.

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/perl
#
my $revision = '$Id: simplify.pl,v 1.9 2003/06/18 11:02:24 bre Exp $';
my $version = 'Anomy 0.0.0 : simplify.pl';
#
##  Copyright (c) 2001 Bjarni R. Einarsson. All rights reserved.
##  This program is free software; you can redistribute it
##  and/or modify it under the same terms as Perl itself.  
#
# Usage: simplify.pl [args ...] <message >othermessage
#
# This is a crude script to simplify a MIME message.  The following arguments 
# are recognized:
#
#   mime=no                       Don't use MIME, no HTML mail allowed.
#   testing=yes                   Run in testing mode (suppress randonmess)
#   saveall=yes                   Save all attachments to files.
#   temp=/path/to/working/dir/    Defaults to /tmp.
#   url=http://box/path/          URL-prefix for printing paths to attachments
#   header=text...                Text preceding the attachment URL list.
#   textsig=/path/to/file         Text signature to append to text parts.
#   htmlsig=/path/to/file         HTML signature to append to HTML parts.
#
# If "saveall" is yes, then the script will save all attachments to disk so
# people can access their contents later.  If an URL is specified then that
# automatically implies "saveall=yes".  Without this, the default behavior is
# to only save text and html parts, and delete them and all working
# directories when the script is finished.
#
# This script never loads the entire message into memory, but does dump 
# it's entire contents to disk once.
#
BEGIN { push @INC, $ENV{"ANOMY"} . "/bin"; };
use strict;
use Anomy::MIMEStream;
use IO::Handle;


##[ Global variables, configuration ]#########################################

my @attachments = ( );
my @textparts = ( );
my @htmlparts = ( );

my $seentext = 0;
my $boundary = "";
my $filecounter = 0;
my $workdir = undef;

my $parsers = {
    "DEFAULT" => \&SaveIt,
    "multipart/*" => \&Anomy::MIMEStream::ParserMultipart,
};

# Defaults...
my $args = 
{
    "mime"    => "yes",
    "saveall" => "no",
    "testing" => "no",
    "temp"    => "/tmp",
    "url"     => undef,
    "header"  => "Attachments:",
    "lynx"    => "/usr/bin/lynx -dump %s",
    "textsig" => undef,
    "htmlsig" => undef,
};


##[ Main ]####################################################################

# Check args
#
foreach my $arg (@ARGV)
{
    if ($arg =~ /^\s*(mime|saveall|testing|temp|url|header|textsig|htmlsig)\s*=\s*(.*)$/si)
    {
        $args->{lc($1)} = $2;
    }
    else
    {
        die "Invalid argument: $arg\nStopped";
    }
}
$args->{"saveall"} = "yes" if ($args->{"url"});

# Parse message header
#
open (NULL, ">/dev/null");
my $message = Anomy::MIMEStream->New(*STDIN, *NULL, $parsers);
$message->ParseHeader();

# Create working directory
#
$workdir = CreateWorkdir();

# Dump attachments to files
#
$message->ParseBody();

# Print out new headers
#
$message->KillRawMimeHeaders();
chomp $message->{"rawheader"};
if ($args->{"mime"} =~ /no/i)
{
    # Without MIME...
    #
    print
        $message->{"UNIX-FROM"}, 
        "MIME-Version: 1.0\n",
        "Content-Type: text/plain; charset=iso-8859-1\n",
        "Content-Transfer-Encoding: 8bit\n",
        $message->{"rawheader"}, "\n";
}
else
{
    # With MIME...
    #
    $boundary = Anomy::MIMEStream::MakeBoundary();
    $boundary = "NotARandomBoundary" if ($args->{"testing"} =~ /yes/i);
    print
        $message->{"UNIX-FROM"}, 
        "Content-Type: multipart/alternative;\n\tboundary=\"",
        $boundary, "\"\n",
        "Content-Transfer-Encoding: 8bit\n",
        $message->{"rawheader"}, "\n";
}

PrintTextPartBoundary();
if (@textparts)
{
    # Dump all inline text parts in a row...
    #
    foreach my $tp (@textparts)
    {
        cat($args->{"temp"}."/".$tp);
    }
    print "\n";
}
elsif (@htmlparts)
{
    # No plain text part present, create one from the first HTML part
    # using lynx.
    #
    my $cmd = sprintf($args->{"lynx"}, $args->{"temp"}."/".$htmlparts[0]);
    
    if (open(PART, "$cmd |"))
    {
        while (<PART>)
        {
            print;
        }
        close(PART);
        print "\n";
    }
}
else
{
    # Default to an empty text message, containing links to attachments.
    # ... so we print nothing.
}
PrintTextPartAttachments();
PrintTextSignature();

# Dump all inline HTML parts in a row...
#
if (($args->{"mime"} !~ /no/i) && (@htmlparts))
{
    foreach my $tp (@htmlparts)
    {
        print
            "--", $boundary, "\n",
            "Content-Transfer-Encoding: 8bit\n",
            "Content-Disposition: inline\n",
            "Content-Type: text/html; charset=iso-8859-1\n\n";

        htmlcat($args->{"temp"}."/".$tp);
    }
    print "\n";
    
    if (($args->{"url"}) && (@attachments))
    {
        print "<h3>", $args->{"header"}, "</h3><ul>\n";
        foreach my $at (@attachments)
        {
            my $fn = $at;
            $fn =~ s/^.*\///g;
            print "<li><a href=\"", $args->{"url"}, $at, "\">", $fn, "</a>\n";
        }
        print "</ul>\n";
    }
    cat ($args->{"htmlsig"});
    print "</body></html>\n\n";
}

# Close multipart, if necessary.
#
if ($args->{"mime"} !~ /no/i)
{
    print "--", $boundary, "--\n",
}

if ($args->{"saveall"} !~ /yes/i)
{
    RemoveWorkdir();
}

##[ Subroutines ]##############################################################

sub CreateWorkdir
{
    my $prefix = sprintf("%x%x", ($$ % 10000), time());
    
    $prefix = "testing" if ($args->{"testing"} =~ /yes/i);
    
    if ($prefix =~ s/^(..)(..)(.*)$/$1\/$2\/$3/)
    {
        my ($a, $b, $c) = ($1, $2, $3);

        mkdir $args->{"temp"}."/$a", 0755;
        mkdir $args->{"temp"}."/$a/$b", 0755;
        mkdir $args->{"temp"}."/$a/$b/$c", 0755;
    }
    return $prefix;
}

sub RemoveWorkdir
{
    my $wd = $args->{"temp"};

    foreach my $att (@attachments, @textparts, @htmlparts)
    {
        unlink $wd ."/". $att;
    }
    
    $wd .= "/". $workdir;
    if ($wd =~ /^(((.*)\/.*?)\/.*?)\/?$/)
    {
        rmdir $1;
        rmdir $2;
        rmdir $3;
    }
}

sub SaveIt
{
    my $part = shift;
    my $fn = $part->{"mime"}->{"name"} || 
             $part->{"mime"}->{"filename"} || "unnamed";
    $fn =~ s/[^A-Za-z0-9\._-]/_/g;

    my $filename = sprintf("%s/%2.2d.%s", $workdir, $filecounter++, $fn);

    if ($part->{"mime"}->{"_disposition"} =~ /^attachment$/i)
    {
        push @attachments, $filename;
    }        
    elsif ($part->{"mime"}->{"_type"} =~ /^text\/plain$/i)
    {
        $filename .= ".txt" if ($filename !~ /\.txt$/i);
        push @textparts, $filename;
    }
    elsif ($part->{"mime"}->{"_type"} =~ /^text\/html$/i)
    {
        $filename .= ".html" if ($filename !~ /\.html$/i);
        push @htmlparts, $filename;
    }
    else
    {
        push @attachments, $filename;
    }
        
    open (FILE, ">".$args->{"temp"}."/$filename");
    while (my $l = $part->Read())
    {
        print FILE $l;
    }
    close(FILE);    
}

# Print text part preamble.
#
sub PrintTextSignature
{
    if (-r $args->{"textsig"})
    {
        print "-- \n";
        cat($args->{"textsig"});
        print "\n";
    }
}

# Print text part preamble.
#
sub PrintTextPartBoundary
{
    if ($args->{"mime"} !~ /no/i)
    {
        print
            "--", $boundary, "\n",
            "Content-Transfer-Encoding: 8bit\n",
            "Content-Disposition: inline\n",
            "Content-Type: text/plain; charset=iso-8859-1\n\n";
    }
}

# Print attachment list as text to stdout.
#
sub PrintTextPartAttachments
{
    if (($args->{"url"}) && (@attachments || @htmlparts))
    {
        print $args->{"header"}, "\n";
        foreach my $at (@attachments)
        {
            print " + ", $args->{"url"}, $at, "\n";
        }
        print "\n";
    }
}

# Dump the contents of a file...
#
sub cat
{
    my $fn = shift;
    
    open (FILE, "<$fn") || return undef;
    while (<FILE>)
    {
        print;
    }
    close(FILE);
}

# Dump the contents of an HTML file, disabling the </body> and </html> 
# tags, to allow us to append Stuff.
#
sub htmlcat
{
    my $fn = shift;
    
    open (FILE, "<".$args->{"temp"}."/$fn") || return undef;
    while (<FILE>)
    {
        s/<\/(body|html)/<END-$1/gi;
        print;
    }
    close(FILE);
}