summaryrefslogtreecommitdiff
path: root/httemplate/view/cust_msg_part.html
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/view/cust_msg_part.html')
-rw-r--r--httemplate/view/cust_msg_part.html23
1 files changed, 23 insertions, 0 deletions
diff --git a/httemplate/view/cust_msg_part.html b/httemplate/view/cust_msg_part.html
new file mode 100644
index 000000000..0be5705cb
--- /dev/null
+++ b/httemplate/view/cust_msg_part.html
@@ -0,0 +1,23 @@
+<%init>
+die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('View email logs');
+# invoke this as "view/cust_msg_part.html?$custmsgnum+$partnum"
+my ($custmsgnum, $partnum) = $cgi->keywords;
+$custmsgnum =~ /^\d+$/ or die "bad custmsgnum";
+$partnum =~ /^\d+$/ or die "bad partnum";
+my $cust_msg = FS::cust_msg->by_key($custmsgnum)
+ or die "message not found";
+my $part = ($cust_msg->parts)[$partnum]
+ or die "message part $partnum does not exist";
+
+my $filename = $part->head->recommended_filename;
+if (!$filename) {
+ # for lack of a better idea
+ $part->bodyhandle->{MB_Path} =~ /.*\/(.*)/;
+ $filename = $1;
+}
+
+$m->clear_buffer;
+$r->content_type($part->mime_type || 'application/octet-stream');
+$r->headers_out->add('Content-Disposition' => 'attachment;filename=' . $filename);
+$m->print($part->bodyhandle->as_string);
+</%init>