summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Attachment_Overlay.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT/Attachment_Overlay.pm')
-rw-r--r--rt/lib/RT/Attachment_Overlay.pm76
1 files changed, 40 insertions, 36 deletions
diff --git a/rt/lib/RT/Attachment_Overlay.pm b/rt/lib/RT/Attachment_Overlay.pm
index d1f0ed4..c4fe47b 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
# <jesse@bestpractical.com>
#
# (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);
}
@@ -275,8 +276,8 @@ original encoding.
sub OriginalContent {
my $self = shift;
- return $self->Content unless (
- $self->ContentType =~ qr{^(text/plain|message/rfc822)$}i) ;
+ return $self->Content unless RT::I18N::IsTextualContentType($self->ContentType);
+
my $enc = $self->OriginalEncoding;
my $content;
@@ -285,12 +286,15 @@ sub OriginalContent {
} elsif ( $self->ContentEncoding eq 'base64' ) {
$content = MIME::Base64::decode_base64($self->_Value('Content', decode_utf8 => 0));
} elsif ( $self->ContentEncoding eq 'quoted-printable' ) {
- return MIME::QuotedPrint::decode($self->_Value('Content', decode_utf8 => 0));
+ $content = MIME::QuotedPrint::decode($self->_Value('Content', decode_utf8 => 0));
} else {
return( $self->loc("Unknown ContentEncoding [_1]", $self->ContentEncoding));
}
- # Encode::_utf8_on($content);
+ # Turn *off* the SvUTF8 bits here so decode_utf8 and from_to below can work.
+ local $@;
+ Encode::_utf8_off($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);
@@ -355,7 +359,7 @@ sub Quote {
# TODO: Handle Multipart/Mixed (eventually fix the link in the
# ShowHistory web template?)
- if ($self->ContentType =~ m{^(text/plain|message)}i) {
+ if (RT::I18N::IsTextualContentType($self->ContentType)) {
$body=$self->Content;
# Do we need any preformatting (wrapping, that is) of the message?