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.pm91
1 files changed, 46 insertions, 45 deletions
diff --git a/rt/lib/RT/Attachment_Overlay.pm b/rt/lib/RT/Attachment_Overlay.pm
index fe189e378..8dcf56ea6 100644
--- a/rt/lib/RT/Attachment_Overlay.pm
+++ b/rt/lib/RT/Attachment_Overlay.pm
@@ -1,8 +1,8 @@
-# BEGIN BPS TAGGED BLOCK {{{
+# {{{ BEGIN BPS TAGGED BLOCK
#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC
# <jesse@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -42,8 +42,7 @@
# works based on those contributions, and sublicense and distribute
# those contributions and any derivatives thereof.
#
-# END BPS TAGGED BLOCK }}}
-
+# }}} END BPS TAGGED BLOCK
=head1 SYNOPSIS
use RT::Attachment;
@@ -67,9 +66,6 @@ ok (require RT::Attachment);
=cut
-
-package RT::Attachment;
-
use strict;
no warnings qw(redefine);
@@ -157,13 +153,6 @@ sub Create {
defined($Subject) or $Subject = '';
chomp($Subject);
- #Get the Message-ID
- my $MessageId = $Attachment->head->get( 'Message-ID', 0 );
- defined($MessageId) or $MessageId = '';
- chomp ($MessageId);
- $MessageId =~ s/^<(.*)>$/$1/go;
-
-
#Get the filename
my $Filename = $Attachment->head->recommended_filename || eval {
${ $Attachment->head->{mail_hdr_hash}{'Content-Disposition'}[0] }
@@ -173,19 +162,12 @@ sub Create {
# 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(
TransactionId => $args{'TransactionId'},
Parent => 0,
ContentType => $Attachment->mime_type,
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 );
@@ -194,6 +176,7 @@ sub Create {
Parent => $id,
Attachment => $part,
ContentType => $Attachment->mime_type,
+ Headers => $Attachment->head->as_string(),
);
}
@@ -203,21 +186,21 @@ sub Create {
#If it's not multipart
else {
+
+ my $Body = $Attachment->bodyhandle->as_string;
+
+
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,
+ 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);
- }
-
+ Filename => $Filename, );
return ($id);
}
}
@@ -237,11 +220,7 @@ sub Import {
my %args = ( ContentEncoding => 'none',
@_ );
-
-
- ($args{'ContentEncoding'}, $args{'Content'}) = $self->_EncodeLOB($args{'Content'}, $args{'MimeType'});
-
- return($self->SUPER::Create(%args));
+ return($self->SUPER::Create(@_));
}
# {{{ sub Content
@@ -255,7 +234,26 @@ before returning it.
sub Content {
my $self = shift;
- $self->_DecodeLOB($self->ContentType, $self->ContentEncoding, $self->_Value('Content', decode_utf8 => 0));
+ my $decode_utf8 = (($self->ContentType =~ qr{^text/plain}i) ? 1 : 0);
+
+ if ( $self->ContentEncoding eq 'none' || ! $self->ContentEncoding ) {
+ return $self->_Value(
+ 'Content',
+ decode_utf8 => $decode_utf8,
+ );
+ } elsif ( $self->ContentEncoding eq 'base64' ) {
+ return ( $decode_utf8
+ ? Encode::decode_utf8(MIME::Base64::decode_base64($self->_Value('Content')))
+ : MIME::Base64::decode_base64($self->_Value('Content'))
+ );
+ } elsif ( $self->ContentEncoding eq 'quoted-printable' ) {
+ return ( $decode_utf8
+ ? Encode::decode_utf8(MIME::QuotedPrint::decode($self->_Value('Content')))
+ : MIME::QuotedPrint::decode($self->_Value('Content'))
+ );
+ } else {
+ return( $self->loc("Unknown ContentEncoding [_1]", $self->ContentEncoding));
+ }
}
@@ -267,7 +265,7 @@ sub Content {
=head2 OriginalContent
Returns the attachment's content as octets before RT's mangling.
-Currently, this just means restoring text content back to its
+Currently, this just means restoring text/plain content back to its
original encoding.
=cut
@@ -275,8 +273,7 @@ original encoding.
sub OriginalContent {
my $self = shift;
- return $self->Content unless (
- $self->ContentType =~ qr{^(text/plain|message/rfc822)$}i) ;
+ return $self->Content unless $self->ContentType eq 'text/plain';
my $enc = $self->OriginalEncoding;
my $content;
@@ -401,16 +398,19 @@ sub Quote {
=head2 NiceHeaders
-Returns a multi-line string of the To, From, Cc, Date and Subject headers.
+Returns the To, From, Cc, Date and Subject headers.
+
+It is a known issue that this breaks if any of these headers are not
+properly unfolded.
=cut
sub NiceHeaders {
my $self = shift;
my $hdrs = "";
- my @hdrs = $self->_SplitHeaders;
+ my @hdrs = split(/\n/,$self->Headers);
while (my $str = shift @hdrs) {
- next unless $str =~ /^(To|From|RT-Send-Cc|Cc|Bcc|Date|Subject):/i;
+ next unless $str =~ /^(To|From|RT-Send-Cc|Cc|Bcc:Date|Subject): /i;
$hdrs .= $str . "\n";
$hdrs .= shift( @hdrs ) . "\n" while ($hdrs[0] =~ /^[ \t]+/);
}
@@ -433,9 +433,10 @@ an abstraction barrier that makes it impossible to pass this data directly
sub Headers {
my $self = shift;
my $hdrs="";
- my @headers = grep { !/^RT-Send-Bcc/i } $self->_SplitHeaders;
- return join("\n",@headers);
-
+ for ($self->_SplitHeaders) {
+ $hdrs.="$_\n" unless /^(RT-Send-Bcc):/i
+ }
+ return $hdrs;
}
@@ -534,7 +535,7 @@ sub _Value {
=head2 _SplitHeaders
Returns an array of this attachment object's headers, with one header
-per array entry. multiple lines are folded.
+per array entry. multiple lines are folded
=begin testing