#!/usr/bin/perl -wT
use strict;
use CGI qw( :standard );
use MIME::Lite;

delete $ENV{PATH};
print header;

if( param('file') )
{
    my $msg = MIME::Lite->new(
	  From    =>'www-data@liljegren.org',
	  To      =>'jonas@liljegren.org',
	  Subject =>'A file to you',
	  Type    =>'multipart/mixed'
	 );

    ### Add parts (each "attach" has same arguments as "new"):
    $msg->attach(Type     =>'TEXT',
		 Data     =>"Here's the file you wanted"
		);

    my $conent_type = uploadInfo(param('file'))->{'Content-Type'};
    $msg->attach(Type     => $conent_type,
		 FH       => upload('file'),
		 Filename => param('file'),
		 Disposition => 'attachment'
		);

    ### Send in the "best" way (the default is to use "sendmail"):
    $msg->send;

    print start_html('File sent'),
      h1('File sent'), end_html;
}
else
{
    print start_html('Upload form'),
      h1('Upload form'),
	start_multipart_form(),
	  filefield('file'),
	    submit, end_form, end_html;
}
__END__
