X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FI18N.pm;h=9d0b2b5a135aa1d0dca583233d19a7ee61786829;hp=c2746f7cb59d742ba1bbc4e247ba516743fecfcd;hb=8103c1fc1b2c27a6855feadf26f91b980a54bc52;hpb=ef20b2b6b1feb47ad02b5ff7525f1a0fd11d0fa4 diff --git a/rt/lib/RT/I18N.pm b/rt/lib/RT/I18N.pm index c2746f7cb..9d0b2b5a1 100644 --- a/rt/lib/RT/I18N.pm +++ b/rt/lib/RT/I18N.pm @@ -153,7 +153,7 @@ sub encoding { 'utf-8' } =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 @@ sub SetMIMEEntityToUTF8 { # }}} +# {{{ IsTextualContentType + +=head2 IsTextualContentType $type + +An utility function that determines whether $type is I, 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 @@ sub SetMIMEEntityToEncoding { # 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; @@ -284,7 +303,7 @@ sub DecodeMIMEWordsToEncoding { my $str = shift; my $enc = shift; - @_ = $str =~ m/(.*?)=\?([^?]+)\?([QqBb])\?([^?]+)\?=([^=]*)/gc; + @_ = $str =~ m/(.*?)=\?([^?]+)\?([QqBb])\?([^?]+)\?=([^=]*)/gcs; return ($str) unless (@_); # add everything that hasn't matched to the end of the latest @@ -392,6 +411,7 @@ sub _GuessCharset { Encode::Guess->set_suspects(@RT::EmailInputEncodings); my $decoder = Encode::Guess->guess( $_[0] ); + if ( defined($decoder) ) { if ( ref $decoder ) { $charset = $decoder->name; $RT::Logger->debug("Guessed encoding: $charset"); @@ -411,6 +431,10 @@ sub _GuessCharset { else { $RT::Logger->warning("Encode::Guess failed: $decoder; fallback to $fallback"); } + } + else { + $RT::Logger->warning("Encode::Guess failed: decoder is undefined; fallback to $fallback"); + } } else { $RT::Logger->warning("Cannot Encode::Guess; fallback to $fallback");