- my (@orig, @quot);
- my @lines = split(/\n/, $s);
- while (defined(my $l = shift @lines)) {
- if ($l =~ /^>/) {
- $self->index_body(\@orig, $doc) if @orig;
- push @quot, $l;
- } else {
- $self->index_body(\@quot, 0) if @quot;
- push @orig, $l;
- }
- }
- $self->index_body(\@quot, 0) if @quot;
- $self->index_body(\@orig, $doc) if @orig;
+ # split off quoted and unquoted blocks:
+ my @sections = split(/((?:^>[^\n]*\n)+)/sm, $s);
+ $part = $s = undef;
+ index_body($self, $_, /\A>/ ? 0 : $doc) for @sections;