2 die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('View email logs');
3 # invoke this as "view/cust_msg_part.html?$custmsgnum+$partnum"
4 my ($custmsgnum, $partnum) = $cgi->keywords;
5 $custmsgnum =~ /^\d+$/ or die "bad custmsgnum";
6 $partnum =~ /^\d+$/ or die "bad partnum";
7 my $cust_msg = FS::cust_msg->by_key($custmsgnum)
8 or die "message not found";
9 my $part = ($cust_msg->parts)[$partnum]
10 or die "message part $partnum does not exist";
12 my $filename = $part->head->recommended_filename;
14 # for lack of a better idea
15 $part->bodyhandle->{MB_Path} =~ /.*\/(.*)/;
20 $r->content_type($part->mime_type || 'application/octet-stream');
21 $r->headers_out->add('Content-Disposition' => 'attachment;filename=' . $filename);
22 $m->print($part->bodyhandle->as_string);