-use Email::MIME::ContentType qw(parse_content_type);
-use PublicInbox::MIME;
-use PublicInbox::MsgIter;
-
-sub get_attach_i { # msg_iter callback
- my ($part, $depth, @idx) = @{$_[0]};
- my $res = $_[1];
- return if join('.', @idx) ne $res->[3]; # $idx
+use PublicInbox::EmlContentFoo qw(parse_content_type);
+use PublicInbox::Eml;
+
+sub referer_match ($) {
+ my ($ctx) = @_;
+ my $env = $ctx->{env};
+ my $referer = $env->{HTTP_REFERER} // '';
+ 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->{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'} . '://' .
+ ($env->{HTTP_HOST} //
+ "$env->{SERVER_NAME}:$env->{SERVER_PORT}") . '/';
+ index($referer, $base_url) == 0;
+}
+
+sub get_attach_i { # ->each_part callback
+ my ($part, $depth, $idx) = @{$_[0]};
+ my $ctx = $_[1];
+ return if $idx ne $ctx->{idx}; # [0-9]+(?:\.[0-9]+)+
+ my $res = $ctx->{res};