+ # Fix message stanza nesting for Outlook's quoting styles
+ if ( $stanza->{raw}
+ and not $stanza->{_outlooked}
+ and $stanza->{raw} =~ /^ # start of an internal line
+ \s* # optional whitespace
+ (?:
+ -{3,} # at least three hyphens
+ \s* # whitespace varies between Outlook versions
+ # don't trigger on PGP signed message or signature blocks
+ (?!(?:BEGIN|END)\s+PGP)
+ \w # at least one word character
+ [\w\s]{3,}? # the rest of the word(s), totalling at least 5 characters,
+ # loose to get different languages
+ \w # at least one ending word character
+ \s* # whitespace varies between Outlook versions
+ -{3,} # at least three hyphens again
+ |
+ _{6,} # OR: six or more underscores
+ )
+ \s*$ # optional whitespace until the end of the line
+ /xm )
+ {
+ # There's content before the quoted message, but in the
+ # same stanza. Break it out!
+ if ( my $start = $-[0] ) {
+ my %preceding = %$stanza;
+
+ # We don't process $stanza->{text} because we don't use it
+ # and it isn't given to us by HTML::Quoted. If we ever
+ # need to, we can process it the same way as 'raw'.
+ $preceding{raw} = substr($stanza->{raw}, 0, $start, '');
+
+ # Replace the current stanza with the two we just created
+ splice @$Message, $i, 1, \%preceding, $stanza;
+
+ # Try it again from the top now that we've rejiggered our
+ # stanzas. We'll process the Outlook stanza again, and hit
+ # the else below this time.
+ redo;
+ } else {
+ # Nest the current stanza and everything that follows
+ $stanza->{_outlooked}++;
+ $stanza = $Message->[ $i ] = [ splice @$Message, $i ];
+ }
+ }
+ else {
+ $para .= ( defined $stanza->{raw} ? $stanza->{raw} : '' )."\n";
+ }