-use Plack::Builder;
-my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => $addr,
- "$cfgpfx.mainrepo" => $maindir,
-});
-is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
-my $git = PublicInbox::Git->new($maindir);
-my $im = PublicInbox::Import->new($git, 'test', $addr);
+my $cfgpath;
+my $creat_cb = sub {
+ my ($im, $ibx) = @_;
+ $im->add(eml_load('t/psgi_attach.eml')) or BAIL_OUT;
+ $im->add(eml_load('t/data/message_embed.eml')) or BAIL_OUT;
+ $cfgpath = "$ibx->{inboxdir}/pi_config";
+ open my $fh, '>', $cfgpath or BAIL_OUT $!;
+ print $fh <<EOF or BAIL_OUT $!;
+[publicinbox "test"]
+ address = $ibx->{-primary_address}
+ inboxdir = $ibx->{inboxdir}
+EOF
+ close $fh or BAIL_OUT $!;
+};
+my $ibx = create_inbox 'test', $creat_cb;
+$cfgpath //= "$ibx->{inboxdir}/pi_config";
+my $qp = "abcdef=g\n==blah\n";
+my $b64 = "b64\xde\xad\xbe\xef\n";
+my $txt = "plain\ntext\npass\nthrough\n";
+my $dot = "dotfile\n";
+my $www = PublicInbox::WWW->new(PublicInbox::Config->new($cfgpath));
+my $client = sub {
+ my ($cb) = @_;
+ my $res;
+ $res = $cb->(GET('/test/Z%40B/'));
+ my @href = ($res->content =~ /^href="([^"]+)"/gms);
+ @href = grep(/\A[\d\.]+-/, @href);
+ is_deeply([qw(1-queue-pee 2-bayce-sixty-four 3-noop.txt
+ 4-a.txt)],
+ \@href, 'attachment links generated');
+
+ $res = $cb->(GET('/test/Z%40B/1-queue-pee'));
+ my $qp_res = $res->content;
+ ok(length($qp_res) >= length($qp), 'QP length is close');
+ like($qp_res, qr/\n\z/s, 'trailing newline exists');
+ # is(index($qp_res, $qp), 0, 'QP trailing newline is there');
+ $qp_res =~ s/\r\n/\n/g;
+ is(index($qp_res, $qp), 0, 'QP trailing newline is there');