diff options
Diffstat (limited to 'rt/lib/RT/Attachment_Overlay.pm')
-rw-r--r-- | rt/lib/RT/Attachment_Overlay.pm | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/rt/lib/RT/Attachment_Overlay.pm b/rt/lib/RT/Attachment_Overlay.pm index f1b93347f..d1f0ed40c 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-2007 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC # <jesse@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) @@ -22,9 +22,7 @@ # # 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., 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. +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # # CONTRIBUTION SUBMISSION POLICY: @@ -45,6 +43,7 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} + =head1 SYNOPSIS use RT::Attachment; @@ -126,13 +125,14 @@ sub TransactionObj { Create a new attachment. Takes a paramhash: 'Attachment' Should be a single MIME body with optional subparts - 'Parent' is an optional id of the parent attachment - 'TransactionId' is the mandatory id of the transaction this attachment is associated with.; + 'Parent' is an optional Parent RT::Attachment object + '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,35 +165,37 @@ sub Create { #Get the filename - my $Filename = $Attachment->head->recommended_filename; + my $Filename = $Attachment->head->recommended_filename || eval { + ${ $Attachment->head->{mail_hdr_hash}{'Content-Disposition'}[0] } + =~ /^.*\bfilename="(.*)"$/ ? $1 : '' + }; # If a message has no bodyhandle, that means that it has subparts (or appears to) # and we should act accordingly. unless ( defined $Attachment->bodyhandle ) { - my $id = $self->SUPER::Create( + $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 ); - my ($id) = $SubAttachment->Create( + $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); } @@ -201,20 +203,17 @@ 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); } @@ -291,7 +290,7 @@ 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); |