X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FTicket%2FElements%2FShowMessageStanza;fp=rt%2Fshare%2Fhtml%2FTicket%2FElements%2FShowMessageStanza;h=8a85443285056ac649571a924ec3cce7419b7d0e;hb=33beebf4cb42eba3e1dd868ad5e0af102de961da;hp=6f887519529e035bcf6d32c308d78ea4d49dfcbe;hpb=7ac86daf67b0a95153b736d5811f9050363f6553;p=freeside.git diff --git a/rt/share/html/Ticket/Elements/ShowMessageStanza b/rt/share/html/Ticket/Elements/ShowMessageStanza index 6f8875195..8a8544328 100755 --- a/rt/share/html/Ticket/Elements/ShowMessageStanza +++ b/rt/share/html/Ticket/Elements/ShowMessageStanza @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -45,67 +45,144 @@ %# those contributions and any derivatives thereof. %# %# END BPS TAGGED BLOCK }}} -<%perl> -if ( ref $Message ) { - $m->out('
') if $plain_text_pre && !$Depth && !$plain_text_mono;
-    $m->out( qq{
} ); +<%INIT> +my $plain_text_pre + = RT->Config->Get( 'PlainTextPre', $session{'CurrentUser'} ); +my $plain_text_mono + = RT->Config->Get( 'PlainTextMono', $session{'CurrentUser'} ); +my $Depth = 0; + +my $ticket = $Transaction ? $Transaction->TicketObj : undef; + +my $print_content = sub { + my $ref = shift; + return unless defined $$ref && length $$ref; + $m->callback( content => $ref, %ARGS ); + if ( $ContentType eq 'text/plain' ) { + $m->comp( '/Elements/MakeClicky', + content => $ref, + ticket => $ticket, + %ARGS + ); + + if ( defined $$ref && !$plain_text_pre && !$plain_text_mono ) { + $$ref =~ s{(\r?\n)}{
}g; + } + } else { + if ( defined $$ref ) { + $$ref =~ s/^[\r\n]+//g; + } + } + $m->out($$ref); +}; + +if ( ref $Message ) { + $m->out('
')
+        if (    $ContentType eq 'text/plain'
+             && $plain_text_pre
+             && !$Depth
+             && !$plain_text_mono );
+    $m->out(   '
' ); my @stack; my $para = ''; - my $i = 0; + my $i = 0; - AGAIN: foreach ( ; $i < @$Message; $i++ ) { +AGAIN: foreach ( ; $i < @$Message; $i++ ) { my $stanza = $Message->[$i]; if ( ref $stanza eq "HASH" ) { - $para .= ( defined $stanza->{raw} ? $stanza->{raw} : '') ."\n"; + # 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"; + } } next unless ref $stanza eq "ARRAY"; - $print_content->( \$para ); $para = ''; + $print_content->( \$para ); + $para = ''; $Depth++; - push @stack, [$Message, $i+1]; - ($Message, $i) = ($stanza, -1); - $m->out( qq{
} ); + push @stack, [ $Message, $i + 1 ]; + ( $Message, $i ) = ( $stanza, -1 ); + + if ( $Depth == 1 ) { + $m->comp('FoldStanzaJS'); + } + my @classes = ('message-stanza'); + push @classes, $Depth == 1 ? 'closed' : 'open'; + $m->out( '
' ); } if ( length $para ) { - $print_content->( \$para ); $para = ''; + $print_content->( \$para ); + $para = ''; } - if ( @stack ) { - ($Message, $i) = @{ pop @stack }; + if (@stack) { + ( $Message, $i ) = @{ pop @stack }; $Depth--; $m->out('
'); goto AGAIN; } $m->out('
'); - $m->out('
') if $plain_text_pre && !$Depth && !$plain_text_mono; + $m->out('
') + if ( $ContentType eq 'text/plain' + && $plain_text_pre + && !$Depth + && !$plain_text_mono ); } else { - $print_content->( \$Message ); + $print_content->( \$Message ); } - -<%INIT> -my $plain_text_pre = RT->Config->Get('PlainTextPre', $session{'CurrentUser'}); -my $plain_text_mono = RT->Config->Get('PlainTextMono', $session{'CurrentUser'}); - -my $ticket = $Transaction ? $Transaction->TicketObj : undef; - -my $print_content = sub { - my $ref = shift; - return unless defined $$ref && length $$ref; - - $m->callback( content => $ref, %ARGS ); - $m->comp('/Elements/MakeClicky', content => $ref, ticket => $ticket, %ARGS); - unless ( $plain_text_pre || $plain_text_mono ) { - $$ref =~ s{(\r?\n)}{
}g if defined $$ref; - } - $m->out( $$ref ); -}; <%ARGS> $Message => undef -$Depth => 0 $Transaction => undef +$ContentType => 'text/plain'