X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FDashboard%2FMailer.pm;h=c88fb67a6a7b8a422b768b6dd7af3850105a6d8f;hb=7322f2afedcc2f427e997d1535a503613a83f088;hp=40b53b111015d66638ce7f27cea9560c018d6e62;hpb=a6fe07e49e3fc12169e801b1ed6874c3a5bd8500;p=freeside.git diff --git a/rt/lib/RT/Dashboard/Mailer.pm b/rt/lib/RT/Dashboard/Mailer.pm index 40b53b111..c88fb67a6 100644 --- a/rt/lib/RT/Dashboard/Mailer.pm +++ b/rt/lib/RT/Dashboard/Mailer.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -59,6 +59,8 @@ use RT::Dashboard; use RT::Interface::Web::Handler; use RT::Interface::Web; use File::Temp 'tempdir'; +use HTML::Scrubber; +use URI::QueryParam; sub MailDashboards { my $self = shift; @@ -145,7 +147,7 @@ sub IsSubscriptionReady { my $sub_hour = $subscription->SubValue('Hour'); my $sub_dow = $subscription->SubValue('Dow'); my $sub_dom = $subscription->SubValue('Dom'); - my $sub_fow = $subscription->SubValue('Fow'); + my $sub_fow = $subscription->SubValue('Fow') || 1; my ($hour, $dow, $dom) = @{ $args{LocalTime} }; @@ -164,8 +166,6 @@ sub IsSubscriptionReady { return 0 if $sub_dow ne $dow; # does it match the "every N weeks" clause? - $sub_fow = 1 if !$sub_fow; - return 1 if $counter % $sub_fow == 0; $subscription->SetSubValues(Counter => $counter + 1) @@ -248,6 +248,8 @@ SUMMARY } } + $content = ScrubContent($content); + $RT::Logger->debug("Got ".length($content)." characters of output."); $content = HTML::RewriteAttributes::Links->rewrite( @@ -348,6 +350,7 @@ sub EmailDashboard { $RT::Logger->debug('Mailing dashboard "'.$dashboard->Name.'" to user '.$currentuser->Name." <$email>"); my $ok = RT::Interface::Email::SendEmail( + %{ RT->Config->Get('Crypt')->{'Dashboards'} || {} }, Entity => $entity, ); @@ -378,12 +381,19 @@ sub BuildEmail { # already attached this object return "cid:$cid_of{$uri}" if $cid_of{$uri}; - $cid_of{$uri} = time() . $$ . int(rand(1e6)); my ($data, $filename, $mimetype, $encoding) = GetResource($uri); + return $uri unless defined $data; - # downgrade non-text strings, because all strings are utf8 by - # default, which is wrong for non-text strings. - if ( $mimetype !~ m{text/} ) { + $cid_of{$uri} = time() . $$ . int(rand(1e6)); + + # Encode textual data in UTF-8, and downgrade (treat + # codepoints as codepoints, and ensure the UTF-8 flag is + # off) everything else. + my @extra; + if ( $mimetype =~ m{text/} ) { + $data = Encode::encode( "UTF-8", $data ); + @extra = ( Charset => "UTF-8" ); + } else { utf8::downgrade( $data, 1 ) or $RT::Logger->warning("downgrade $data failed"); } @@ -393,8 +403,9 @@ sub BuildEmail { Type => $mimetype, Encoding => $encoding, Disposition => 'inline', - Name => $filename, + Name => RT::Interface::Email::EncodeToMIME( String => $filename ), 'Content-Id' => $cid_of{$uri}, + @extra, ); return "cid:$cid_of{$uri}"; @@ -402,29 +413,32 @@ sub BuildEmail { inline_css => sub { my $uri = shift; my ($content) = GetResource($uri); - return $content; + return defined $content ? $content : ""; }, inline_imports => 1, ); my $entity = MIME::Entity->build( - From => $args{From}, - To => $args{To}, - Subject => $args{Subject}, + From => Encode::encode("UTF-8", $args{From}), + To => Encode::encode("UTF-8", $args{To}), + Subject => RT::Interface::Email::EncodeToMIME( String => $args{Subject} ), Type => "multipart/mixed", ); $entity->attach( - Data => Encode::encode_utf8($content), Type => 'text/html', Charset => 'UTF-8', + Data => Encode::encode("UTF-8", $content), Disposition => 'inline', + Encoding => "base64", ); for my $part (@parts) { $entity->add_part($part); } + $entity->make_singlepart; + return $entity; } @@ -447,7 +461,7 @@ sub BuildEmail { autohandler_name => '', # disable forced login and more data_dir => $data_dir, ); - $mason->set_escape( h => \&RT::Interface::Web::EscapeUTF8 ); + $mason->set_escape( h => \&RT::Interface::Web::EscapeHTML ); $mason->set_escape( u => \&RT::Interface::Web::EscapeURI ); $mason->set_escape( j => \&RT::Interface::Web::EscapeJS ); } @@ -463,6 +477,33 @@ sub BuildEmail { } { + my $scrubber; + + sub _scrubber { + unless ($scrubber) { + $scrubber = HTML::Scrubber->new; + # Allow everything by default, except JS attributes ... + $scrubber->default( + 1 => { + '*' => 1, + map { ("on$_" => 0) } + qw(blur change click dblclick error focus keydown keypress keyup load + mousedown mousemove mouseout mouseover mouseup reset select submit unload) + } + ); + # ... and