#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
$Attachment->make_singlepart;
# Get the subject
- my $Subject = $Attachment->head->get( 'subject', 0 );
+ my $Subject = Encode::decode( 'UTF-8', $Attachment->head->get( 'subject' ) );
$Subject = '' unless defined $Subject;
chomp $Subject;
- utf8::decode( $Subject ) unless utf8::is_utf8( $Subject );
#Get the Message-ID
- my $MessageId = $Attachment->head->get( 'Message-ID', 0 );
+ my $MessageId = Encode::decode( "UTF-8", $Attachment->head->get( 'Message-ID' ) );
defined($MessageId) or $MessageId = '';
chomp ($MessageId);
$MessageId =~ s/^<(.*?)>$/$1/o;
#Get the filename
-
my $Filename = mime_recommended_filename($Attachment);
# remove path part.
# MIME::Head doesn't support perl strings well and can return
# octets which later will be double encoded in low-level code
- my $head = $Attachment->head->as_string;
- utf8::decode( $head ) unless utf8::is_utf8( $head );
+ my $head = Encode::decode( 'UTF-8', $Attachment->head->as_string );
# If a message has no bodyhandle, that means that it has subparts (or appears to)
# and we should act accordingly.
=head2 Children
Returns an L<RT::Attachments> object which is preloaded with
-all attachments objects with this attachment\'s Id as their
+all attachments objects with this attachment's Id as their
C<Parent>.
=cut
sub Content {
my $self = shift;
return $self->_DecodeLOB(
- $self->ContentType,
+ $self->GetHeader('Content-Type'), # Includes charset, unlike ->ContentType
$self->ContentEncoding,
$self->_Value('Content', decode_utf8 => 0),
);
}
return $self->Content unless RT::I18N::IsTextualContentType($self->ContentType);
- my $enc = $self->OriginalEncoding;
my $content;
if ( !$self->ContentEncoding || $self->ContentEncoding eq 'none' ) {
return( $self->loc("Unknown ContentEncoding [_1]", $self->ContentEncoding));
}
- # Turn *off* the SvUTF8 bits here so decode_utf8 and from_to below can work.
- local $@;
- Encode::_utf8_off($content);
+ my $entity = MIME::Entity->new();
+ $entity->head->add("Content-Type", $self->GetHeader("Content-Type"));
+ $entity->bodyhandle( MIME::Body::Scalar->new( $content ) );
+ my $from = RT::I18N::_FindOrGuessCharset($entity);
+ $from = 'utf-8' if not $from or not Encode::find_encoding($from);
- 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);
- }
+ my $to = RT::I18N::_CanonicalizeCharset(
+ $self->OriginalEncoding || 'utf-8'
+ );
- eval { Encode::from_to($content, 'utf8' => $enc) } if $enc;
+ local $@;
+ eval { Encode::from_to($content, $from => $to) };
if ($@) {
- $RT::Logger->error("Could not convert attachment from assumed utf8 to '$enc' :".$@);
+ $RT::Logger->error("Could not convert attachment from $from to $to: ".$@);
}
return $content;
}
=cut
+our @ADDRESS_HEADERS = qw(From To Cc Bcc RT-Send-Cc RT-Send-Bcc);
+
sub Addresses {
my $self = shift;
my %data = ();
my $current_user_address = lc $self->CurrentUser->EmailAddress;
- foreach my $hdr (qw(From To Cc Bcc RT-Send-Cc RT-Send-Bcc)) {
+ foreach my $hdr (@ADDRESS_HEADERS) {
my @Addresses;
my $line = $self->GetHeader($hdr);