[Rt-commit] r9639 - rt/branches/3.6-RELEASE/lib/RT
audreyt at bestpractical.com
audreyt at bestpractical.com
Sun Nov 11 14:06:06 EST 2007
Author: audreyt
Date: Sun Nov 11 14:06:06 2007
New Revision: 9639
Modified:
rt/branches/3.6-RELEASE/lib/RT/Transaction_Overlay.pm
Log:
* RT::Transaction_Overlay: Unify the idea of "textual" MIME types
to text/plain, text/html and message/*. (Previously it was defined
differently for e.g. the first part and the other parts.)
* RT::Transaction_Overlay: Introduce the variable
$RT::Transaction::PreferredContentType to control the context
where ->Content() is evaluated in. If not set, it defaults
to text/plain.
Modified: rt/branches/3.6-RELEASE/lib/RT/Transaction_Overlay.pm
==============================================================================
--- rt/branches/3.6-RELEASE/lib/RT/Transaction_Overlay.pm (original)
+++ rt/branches/3.6-RELEASE/lib/RT/Transaction_Overlay.pm Sun Nov 11 14:06:06 2007
@@ -78,7 +78,7 @@
use strict;
no warnings qw(redefine);
-use vars qw( %_BriefDescriptions );
+use vars qw( %_BriefDescriptions $PreferredContentType );
use RT::Attachments;
use RT::Scrips;
@@ -271,12 +271,14 @@
=head2 Content PARAMHASH
-If this transaction has attached mime objects, returns the first text/plain part.
-Otherwise, returns undef.
+If this transaction has attached mime objects, returns the body of the first
+text/plain, text/html or message/* part. Otherwise, returns undef.
Takes a paramhash. If the $args{'Quote'} parameter is set, wraps this message
at $args{'Wrap'}. $args{'Wrap'} defaults to 70.
+If C<$RT::Transaction::PreferredContentType> is set to C<text/html>, plain texts
+are upgraded to HTML. Otherwise, HTML texts are downgraded to plain text.
=cut
@@ -294,11 +296,26 @@
if ($content_obj->ContentType =~ m{^text/html$}i) {
$content =~ s/<p>--\s+<br \/>.*?$//s if $args{'Quote'};
- $content = HTML::FormatText->new(leftmargin => 0, rightmargin => 78)->format( HTML::TreeBuilder->new_from_content( $content));
+ if ($PreferredContentType ne 'text/html') {
+ $content = HTML::FormatText->new(
+ leftmargin => 0,
+ rightmargin => 78,
+ )->format(
+ HTML::TreeBuilder->new_from_content( $content )
+ );
+ }
}
else {
$content =~ s/\n-- \n.*?$//s if $args{'Quote'};
+
+ if ($PreferredContentType eq 'text/html') {
+ # Extremely simple text->html converter
+ $content =~ s/&/&/g;
+ $content =~ s/</</g;
+ $content =~ s/>/>/g;
+ $content = "<pre>$content</pre>";
+ }
}
}
@@ -356,9 +373,9 @@
# Get the set of toplevel attachments to this transaction.
my $Attachment = $self->Attachments->First();
- # If it's a message or a plain part, just return the
- # body.
- if ( $Attachment->ContentType() =~ '^(?:text/plain$|text/html|message/)' ) {
+ # If it's a text/plain, text/html or message/* part, just return the body.
+ my $wanted_mime_types = qr{^(?:text/plain$|text/html$|message/)}i;
+ if ( $Attachment->ContentType() =~ $wanted_mime_types ) {
return ($Attachment);
}
@@ -375,13 +392,13 @@
}
- # If that fails, return the first text/plain or message/ part
+ # If that fails, return the first text/plain, text/html or message/* part
# which has some content.
else {
my $all_parts = $self->Attachments();
while ( my $part = $all_parts->Next ) {
- if (( $part->ContentType() =~ '^(text/plain$|message/)' ) && $part->Content() ) {
+ if (( $part->ContentType() =~ $wanted_mime_types ) && $part->Content() ) {
return ($part);
}
}
More information about the Rt-commit
mailing list