X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwAttach.pm;h=c17394afe8709b61caae9315f549d53c84ad758d;hb=5c8909925072804901e9c3b45bbf25446d379e7b;hp=09c66d0239cb40a5a3942f957154b4ec54fc1097;hpb=46cbc5a7a4ba917bd7154be3b6e6898420ff85d3;p=public-inbox.git diff --git a/lib/PublicInbox/WwwAttach.pm b/lib/PublicInbox/WwwAttach.pm index 09c66d02..c17394af 100644 --- a/lib/PublicInbox/WwwAttach.pm +++ b/lib/PublicInbox/WwwAttach.pm @@ -1,12 +1,11 @@ -# Copyright (C) 2016-2020 all contributors +# Copyright (C) 2016-2021 all contributors # License: AGPL-3.0+ # For retrieving attachments from messages in the WWW interface package PublicInbox::WwwAttach; # internal package use strict; +use v5.10.1; use parent qw(PublicInbox::GzipFilter); -use bytes (); # only for bytes::length -use PublicInbox::EmlContentFoo qw(parse_content_type); use PublicInbox::Eml; sub referer_match ($) { @@ -16,7 +15,7 @@ sub referer_match ($) { return 1 if $referer eq ''; # no referer is always OK for wget/curl # prevent deep-linking from other domains on some browsers (Firefox) - # n.b.: $ctx->{-inbox}->base_url($env) with INBOX_URL won't work + # n.b.: $ctx->{ibx}->base_url($env) with INBOX_URL won't work # with dillo, we can only match "$url_scheme://$HTTP_HOST/" without # path components my $base_url = $env->{'psgi.url_scheme'} . '://' . @@ -31,9 +30,7 @@ sub get_attach_i { # ->each_part callback return if $idx ne $ctx->{idx}; # [0-9]+(?:\.[0-9]+)+ my $res = $ctx->{res}; $res->[0] = 200; - my $ct = $part->content_type; - $ct = parse_content_type($ct) if $ct; - + my $ct = $part->ct; if ($ct && (($ct->{type} || '') eq 'text')) { # display all text as text/plain: my $cset = $ct->{attributes}->{charset}; @@ -53,7 +50,7 @@ sub get_attach_i { # ->each_part callback $part = "Deep-linking prevented\n"; } } - push @{$res->[1]}, 'Content-Length', bytes::length($part); + push @{$res->[1]}, 'Content-Length', length($part); $res->[2]->[0] = $part; } @@ -88,15 +85,15 @@ sub get_attach ($$$) { $ctx->{idx} = $idx; bless $ctx, __PACKAGE__; my $eml; - if ($ctx->{smsg} = $ctx->{-inbox}->smsg_by_mid($ctx->{mid})) { + if ($ctx->{smsg} = $ctx->{ibx}->smsg_by_mid($ctx->{mid})) { return sub { # public-inbox-httpd-only $ctx->{wcb} = $_[0]; scan_attach($ctx); } if $ctx->{env}->{'pi-httpd.async'}; # generic PSGI: - $eml = $ctx->{-inbox}->smsg_eml($ctx->{smsg}); - } elsif (!$ctx->{-inbox}->over) { - if (my $bref = $ctx->{-inbox}->msg_by_mid($ctx->{mid})) { + $eml = $ctx->{ibx}->smsg_eml($ctx->{smsg}); + } elsif (!$ctx->{ibx}->over) { + if (my $bref = $ctx->{ibx}->msg_by_mid($ctx->{mid})) { $eml = PublicInbox::Eml->new($bref); } }