[Rt-commit] r9644 - rt/branches/3.6-RELEASE/lib/RT
audreyt at bestpractical.com
audreyt at bestpractical.com
Mon Nov 12 02:56:43 EST 2007
Author: audreyt
Date: Mon Nov 12 02:56:43 2007
New Revision: 9644
Modified:
rt/branches/3.6-RELEASE/lib/RT/I18N.pm
Log:
* RT::I18N - Introduce a new utility function, IsTextualContentType($type),
that determines whether $type can be sensibly converted to Unicode text.
Currently it uses this regex (case-insensitively):
^(?:text/(?:plain|html)|message/rfc822)\b
The idea is to unify all the inconsistent uses all over RT's code
(some tested for text/*, some for text/plain|message/rfc822, some
for text/plain|text/html|message/*) to use this function instead.
* Minor POD glitch - Say "function" when it said "method" but really wasn't.
Modified: rt/branches/3.6-RELEASE/lib/RT/I18N.pm
==============================================================================
--- rt/branches/3.6-RELEASE/lib/RT/I18N.pm (original)
+++ rt/branches/3.6-RELEASE/lib/RT/I18N.pm Mon Nov 12 02:56:43 2007
@@ -153,7 +153,7 @@
=head2 SetMIMEEntityToUTF8 $entity
-An utility method which will try to convert entity body into utf8.
+An utility function which will try to convert entity body into utf8.
It's now a wrap-up of SetMIMEEntityToEncoding($entity, 'utf-8').
=cut
@@ -164,16 +164,37 @@
# }}}
+# {{{ IsTextualContentType
+
+=head2 IsTextualContentType $type
+
+An utility function that determines whether $type is I<textual>, meaning
+that it can sensibly be converted to Unicode text.
+
+Currently, it returns true iff $type matches this regular expression
+(case-insensitively):
+
+ ^(?:text/(?:plain|html)|message/rfc822)\b
+
+# }}}
+
+=cut
+
+sub IsTextualContentType {
+ my $type = shift;
+ ($type =~ m{^(?:text/(?:plain|html)|message/rfc822)\b}i) ? 1 : 0;
+}
+
# {{{ SetMIMEEntityToEncoding
=head2 SetMIMEEntityToEncoding $entity, $encoding
-An utility method which will try to convert entity body into specified
+An utility function which will try to convert entity body into specified
charset encoding (encoded as octets, *not* unicode-strings). It will
iterate all the entities in $entity, and try to convert each one into
specified charset if whose Content-Type is 'text/plain'.
-This method doesn't return anything meaningful.
+This function doesn't return anything meaningful.
=cut
@@ -205,11 +226,9 @@
# If this is a textual entity, we'd need to preserve its original encoding
$head->add( "X-RT-Original-Encoding" => $charset )
- if $head->mime_attr('content-type.charset') or $head->mime_type =~ /^text/;
-
+ if $head->mime_attr('content-type.charset') or IsTextualContentType($head->mime_type);
- return unless ( $head->mime_type =~ qr{^(text/plain|message/rfc822)$}i );
-
+ return unless IsTextualContentType($head->mime_type);
my $body = $entity->bodyhandle;
More information about the Rt-commit
mailing list