X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FAttachment_Overlay.pm;h=f1b93347fd5df7e154a2a2574501d35c544f127d;hp=fe189e378acd4a7ab26985d7a259a5897c49dacd;hb=ef20b2b6b1feb47ad02b5ff7525f1a0fd11d0fa4;hpb=a513c0bef534d05f03c1242831b6f3be19b97dae diff --git a/rt/lib/RT/Attachment_Overlay.pm b/rt/lib/RT/Attachment_Overlay.pm index fe189e378..f1b93347f 100644 --- a/rt/lib/RT/Attachment_Overlay.pm +++ b/rt/lib/RT/Attachment_Overlay.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -22,7 +22,9 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/copyleft/gpl.html. # # # CONTRIBUTION SUBMISSION POLICY: @@ -43,7 +45,6 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} - =head1 SYNOPSIS use RT::Attachment; @@ -125,14 +126,13 @@ sub TransactionObj { Create a new attachment. Takes a paramhash: 'Attachment' Should be a single MIME body with optional subparts - 'Parent' is an optional Parent RT::Attachment object - 'TransactionId' is the mandatory id of the Transaction this attachment is associated with.; + 'Parent' is an optional id of the parent attachment + 'TransactionId' is the mandatory id of the transaction this attachment is associated with.; =cut sub Create { my $self = shift; - my ($id); my %args = ( id => 0, TransactionId => 0, Parent => 0, @@ -142,8 +142,8 @@ sub Create { #For ease of reference my $Attachment = $args{'Attachment'}; - #if we didn't specify a ticket, we need to bail - if ( $args{'TransactionId'} == 0 ) { + #if we didn't specify a ticket, we need to bail + if ( $args{'TransactionId'} == 0 ) { $RT::Logger->crit( "RT::Attachment->Create couldn't, as you didn't specify a transaction\n" ); return (0); @@ -165,37 +165,35 @@ sub Create { #Get the filename - my $Filename = $Attachment->head->recommended_filename || eval { - ${ $Attachment->head->{mail_hdr_hash}{'Content-Disposition'}[0] } - =~ /^.*\bfilename="(.*)"$/ ? $1 : '' - }; + my $Filename = $Attachment->head->recommended_filename; # If a message has no bodyhandle, that means that it has subparts (or appears to) # and we should act accordingly. unless ( defined $Attachment->bodyhandle ) { - $id = $self->SUPER::Create( + my $id = $self->SUPER::Create( TransactionId => $args{'TransactionId'}, Parent => 0, ContentType => $Attachment->mime_type, - Headers => $Attachment->head->as_string, - MessageId => $MessageId, - Subject => $Subject); + Headers => $Attachment->head->as_string, + MessageId => $MessageId, + Subject => $Subject + ); unless ($id) { $RT::Logger->crit("Attachment insert failed - ".$RT::Handle->dbh->errstr); - } foreach my $part ( $Attachment->parts ) { my $SubAttachment = new RT::Attachment( $self->CurrentUser ); - $SubAttachment->Create( + my ($id) = $SubAttachment->Create( TransactionId => $args{'TransactionId'}, Parent => $id, Attachment => $part, - ContentType => $Attachment->mime_type, - ); + unless ($id) { + $RT::Logger->crit("Attachment insert failed - ".$RT::Handle->dbh->errstr); + } } return ($id); } @@ -203,17 +201,20 @@ sub Create { #If it's not multipart else { - my ($ContentEncoding, $Body) = $self->_EncodeLOB($Attachment->bodyhandle->as_string, $Attachment->mime_type); - my $id = $self->SUPER::Create( TransactionId => $args{'TransactionId'}, - ContentType => $Attachment->mime_type, - ContentEncoding => $ContentEncoding, - Parent => $args{'Parent'}, - Headers => $Attachment->head->as_string, - Subject => $Subject, - Content => $Body, - Filename => $Filename, - MessageId => $MessageId - ); + my ($ContentEncoding, $Body) = $self->_EncodeLOB( $Attachment->bodyhandle->as_string, + $Attachment->mime_type + ); + my $id = $self->SUPER::Create( + TransactionId => $args{'TransactionId'}, + ContentType => $Attachment->mime_type, + ContentEncoding => $ContentEncoding, + Parent => $args{'Parent'}, + Headers => $Attachment->head->as_string, + Subject => $Subject, + Content => $Body, + Filename => $Filename, + MessageId => $MessageId, + ); unless ($id) { $RT::Logger->crit("Attachment insert failed - ".$RT::Handle->dbh->errstr); } @@ -290,13 +291,13 @@ sub OriginalContent { return( $self->loc("Unknown ContentEncoding [_1]", $self->ContentEncoding)); } - # Encode::_utf8_on($content); + Encode::_utf8_on($content); if (!$enc || $enc eq '' || $enc eq 'utf8' || $enc eq 'utf-8') { # If we somehow fail to do the decode, at least push out the raw bits eval {return( Encode::decode_utf8($content))} || return ($content); } - eval { Encode::from_to($content, 'utf8' => $enc);}; + eval { Encode::from_to($content, 'utf8' => $enc) } if $enc; if ($@) { $RT::Logger->error("Could not convert attachment from assumed utf8 to '$enc' :".$@); }