X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fsbin%2Frt-email-digest.in;h=52fa45084018a4d142dfc6ef4e2ca06a25ba9024;hp=a535e3649c6d410ec9182a7dd2cb3ef040582a04;hb=681a340f6be4184b1472a8e1fa9cd5d074f6f325;hpb=45d35d5739d05e602bc317739485693e0e9ff0b5 diff --git a/rt/sbin/rt-email-digest.in b/rt/sbin/rt-email-digest.in index a535e3649..52fa45084 100644 --- a/rt/sbin/rt-email-digest.in +++ b/rt/sbin/rt-email-digest.in @@ -3,7 +3,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -49,23 +49,15 @@ use warnings; use strict; -BEGIN { +BEGIN { # BEGIN RT CMD BOILERPLATE require File::Spec; + require Cwd; my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@"); my $bin_path; for my $lib (@libs) { unless ( File::Spec->file_name_is_absolute($lib) ) { - unless ($bin_path) { - if ( File::Spec->file_name_is_absolute(__FILE__) ) { - $bin_path = ( File::Spec->splitpath(__FILE__) )[1]; - } - else { - require FindBin; - no warnings "once"; - $bin_path = $FindBin::Bin; - } - } + $bin_path ||= ( File::Spec->splitpath(Cwd::abs_path(__FILE__)) )[1]; $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib ); } unshift @INC, $lib; @@ -76,10 +68,9 @@ BEGIN { use Date::Format qw( strftime ); use Getopt::Long; use RT; -use RT::Interface::CLI qw( CleanEnv loc ); +use RT::Interface::CLI qw( loc ); use RT::Interface::Email; -CleanEnv(); RT::LoadConfig(); RT::Init(); @@ -179,8 +170,10 @@ sub send_digest { } # Set our sender and recipient. - $digest_template->MIMEObj->head->replace( 'From', RT::Config->Get('CorrespondAddress') ); - $digest_template->MIMEObj->head->replace( 'To', $to ); + $digest_template->MIMEObj->head->replace( + 'From', Encode::encode( "UTF-8", RT::Config->Get('CorrespondAddress') ) ); + $digest_template->MIMEObj->head->replace( + 'To', Encode::encode( "UTF-8", $to ) ); if ($print) { $digest_template->MIMEObj->print; @@ -266,7 +259,7 @@ sub find_transactions { my $queue = $txn->TicketObj->QueueObj->Name; # Xxx todo - may clobber if two queues have the same name foreach my $user ( $txn->DeferredRecipients($frequency) ) { - $all_digest->{$user}->{$queue}->{$ticket}->{ $txn->id } = $txn->ContentObj; + $all_digest->{$user}->{$queue}->{$ticket}->{ $txn->id } = $txn; $sent_transactions->{$user}->{ $txn->id } = $txn; } } @@ -310,12 +303,14 @@ sub build_digest_for_user { # Spit out the messages for the transactions on this ticket. $contents_body .= "\n== $ticket_title\n"; foreach my $txn ( sort keys %$tkt_txns ) { - my $msg = $tkt_txns->{$txn}; - - # $msg contains an RT::Attachment with our outgoing - # message. Print a few headers for clarity's sake. - $contents_body .= "From: " . $msg->GetHeader('From') . "\n"; - my $date = $msg->GetHeader('Date '); + my $top = $tkt_txns->{$txn}->Attachments->First; + + # $top contains the top-most RT::Attachment with our + # outgoing message. It may not be the MIME part with + # the content. Print a few headers from it for + # clarity's sake. + $contents_body .= "From: " . $top->GetHeader('From') . "\n"; + my $date = $top->GetHeader('Date '); unless ($date) { my $txn_obj = RT::Transaction->new( RT->SystemUser ); $txn_obj->Load($txn); @@ -328,7 +323,7 @@ sub build_digest_for_user { @{ [ localtime( $date_obj->Unix ) ] } ); } $contents_body .= "Date: $date\n\n"; - $contents_body .= $msg->Content . "\n"; + $contents_body .= $tkt_txns->{$txn}->ContentObj->Content . "\n"; $contents_body .= "-------\n"; } # foreach transaction } # foreach ticket