#!/usr/local/bin/perl
# detach.cgi
# View one attachment from a message

require './sendmail-lib.pl';
require './boxes-lib.pl';

&ReadParse();
@mail = &list_mails($in{'user'}, $in{'idx'}, $in{'idx'});
$mail = $mail[$in{'idx'}];
&parse_mail($mail);
@sub = split(/\0/, $in{'sub'});
foreach $s (@sub) {
	# We are looking at a mail within a mail ..
	local $amail = &extract_mail($mail->{'attach'}->[$s]->{'data'});
	&parse_mail($amail);
	$mail = $amail;
	}
$attach = $mail->{'attach'}->[$in{'attach'}];

print "Content-length: ",length($attach->{'data'}),"\n";
print "Content-type: $attach->{'type'}\n\n";
if ($attach->{'type'} =~ /^text\/html/i) {
	print &filter_javascript($attach->{'data'});
	}
else {
	print $attach->{'data'};
	}

