my $i = 0;
                @parts = map { [ $_, 1, ++$i ] } @parts;
                while (my $p = shift @parts) {
-                       my ($part, $depth, @idx) = @$p;
+                       my ($part, $depth, $idx) = @$p;
                        my @sub = $part->subparts;
                        if (@sub) {
                                $depth++;
                                $i = 0;
-                               @sub = map { [ $_, $depth, @idx, ++$i ] } @sub;
+                               @sub = map {
+                                       [ $_, $depth, "$idx.".(++$i) ]
+                               } @sub;
                                @parts = (@sub, @parts);
                        } else {
                                $cb->($p, $cb_arg);
 
 }
 
 sub index_xapian { # msg_iter callback
-       my $part = $_[0]->[0]; # ignore $depth and @idx
+       my $part = $_[0]->[0]; # ignore $depth and $idx
        my ($self, $doc) = @{$_[1]};
        my $ct = $part->content_type || 'text/plain';
        my $fn = $part->filename;
 
 
 sub attach_link ($$$$;$) {
        my ($ctx, $ct, $p, $fn, $err) = @_;
-       my ($part, $depth, @idx) = @$p;
-       my $nl = $idx[-1] > 1 ? "\n" : '';
-       my $idx = join('.', @idx);
+       my ($part, $depth, $idx) = @$p;
+       my $nl = substr($idx, -2) eq '.1' ? '' : "\n"; # like join("\n", ...)
        my $size = bytes::length($part->body);
 
        # hide attributes normally, unless we want to aid users in
        my ($p, $ctx) = @_;
        my $upfx = $ctx->{mhref};
        my $ibx = $ctx->{-inbox};
-       # $p - from each_part: [ Email::MIME-like, depth, @idx ]
-       my ($part, $depth, @idx) = @$p;
+       # $p - from each_part: [ Email::MIME-like, depth, $idx ]
+       my ($part, $depth, $idx) = @$p;
        my $ct = $part->content_type || 'text/plain';
        my $fn = $part->filename;
        my ($s, $err) = msg_part_text($part, $ct);
        # headers for solver unless some coderepo are configured:
        my $diff;
        if ($s =~ /^--- [^\n]+\n\+{3} [^\n]+\n@@ /ms) {
-               # diffstat anchors do not link across attachments or messages:
-               $idx[0] = $upfx . $idx[0] if $upfx ne '';
-               $ctx->{-apfx} = join('/', @idx);
+               # diffstat anchors do not link across attachments or messages,
+               # -apfx is just a stable prefix for making diffstat anchors
+               # linkable to the first diff hunk w/o crossing attachments
+               $idx =~ tr!.!/!; # compatibility with previous versions
+               $ctx->{-apfx} = $upfx . $idx;
 
                # do attr => filename mappings for diffstats in git diffs:
                $ctx->{-anchors} = {} if $s =~ /^diff --git /sm;
-
                $diff = 1;
                delete $ctx->{-long_path};
                my $spfx;
 
 use PublicInbox::MsgIter;
 
 sub get_attach_i { # ->each_part callback
-       my ($part, $depth, @idx) = @{$_[0]};
+       my ($part, $depth, $idx) = @{$_[0]};
        my $res = $_[1];
-       return if join('.', @idx) ne $res->[3]; # $idx
+       return if $idx ne $res->[3]; # [0-9]+(?:\.[0-9]+)+
        $res->[0] = 200;
        my $ct = $part->content_type;
        $ct = parse_content_type($ct) if $ct;
 
 my $nr = 0;
 msg_iter($msg, sub {
        my ($part, $level, @ex) = @{$_[0]};
-       if ($ex[0] == 1) {
+       is($level, 1, 'at expected level');
+       if (join('fail if $#ex > 0', @ex) eq '1') {
                is($part->body_str, "your tree directly? \r\n", 'body OK');
-       } elsif ($ex[0] == 2) {
+       } elsif (join('fail if $#ex > 0', @ex) eq '2') {
                is($part->body, "-----BEGIN PGP SIGNATURE-----\n\n" .
                                "=7wIb\n" .
                                "-----END PGP SIGNATURE-----\n",
 
                $s =~ s/\s+//s;
                push @parts, [ $s, $level, @ex ];
        });
-       is_deeply(\@parts, [ [qw(a 2 1 1)], [qw(b 2 1 2)], [qw(sig 1 2)] ],
+       is_deeply(\@parts, [ [qw(a 2 1.1)], [qw(b 2 1.2)], [qw(sig 1 2)] ],
                'nested part shows up properly');
 }