Commit 36a64346 authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Don't "upgrade" plaintext messages to have HTML versions

git-svn-id: svn+ssh://svn.bestpractical.com/svn/bps-public/rt/branches/3.8-TESTING@11978 e417ac7c-1bcc-0310-8ffa-8f5827389a85
parent a1ec6d04
......@@ -312,10 +312,7 @@ sub Parse {
my $orig_entity = $self->MIMEObj;
my $mime_type = $self->MIMEObj->mime_type;
if (!$mime_type or $mime_type eq 'text/plain') {
$self->_UpgradeToHTML(@_);
}
elsif ($mime_type eq 'text/html') {
if (defined $mime_type and $mime_type eq 'text/html') {
$self->_DowngradeFromHTML(@_);
}
......@@ -476,70 +473,6 @@ sub _DowngradeFromHTML {
return ($rv, $msg);
}
sub _UpgradeToHTML {
my $self = shift;
my $orig_entity = $self->MIMEObj;
local $RT::Transaction::PreferredContentType = 'text/html';
require Text::Template;
my $old_compile = \&Text::Template::compile;
local *Text::Template::compile = sub {
$old_compile->(@_) or return undef;
my $self = shift;
my @new_content;
my $in_body;
foreach my $chunk (@{$self->{SOURCE}}) {
if ($chunk->[0] eq 'TEXT') {
my $new_text = $chunk->[1];
my $prepend = '';
if (!$in_body) {
# We don't HTMLify anything within the header.
if ($new_text =~ /\n\r?\n/) {
$in_body = 1;
# Preserve the header text but upgrade the body text
($prepend, $new_text) = split(/(?<=\n\r\n)|(?<=\n\n)/, $new_text, 2);
}
else {
push @new_content, $chunk;
next;
}
}
$new_text =~ s/&/&#38;/g;
$new_text =~ s/</&lt;/g;
$new_text =~ s/>/&gt;/g;
$new_text =~ s/\n/\n<br \/>/g;
push @new_content, [$chunk->[0], $prepend.$new_text, $chunk->[2]];
}
else {
push @new_content, $chunk;
}
}
$self->{SOURCE} = \@new_content;
};
my ($rv, $msg) = $self->_Parse(@_);
if (!$rv) {
$self->{MIMEObj} = $orig_entity;
return;
}
$orig_entity->head->mime_attr( "Content-Type" => 'text/plain' );
$orig_entity->head->mime_attr( "Content-Type.charset" => 'utf-8' );
$orig_entity->make_multipart('alternative', Force => 1);
my $new_entity = $self->{MIMEObj};
$new_entity->head->mime_attr( "Content-Type" => 'text/html' );
$new_entity->head->mime_attr( "Content-Type.charset" => 'utf-8' );
$orig_entity->add_part($new_entity);
$self->{MIMEObj} = $orig_entity;
return ($rv, $msg);
}
=head2 CurrentUserHasQueueRight
Helper function to call the template's queue's CurrentUserHasQueueRight with the passed in args.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment