[rt-users] [PATCH] Japanese support in RT 2.0.13
Ben Gertzfield
che at debian.org
Thu Mar 28 01:04:47 EST 2002
Here's an updated version of the Japanese patch for the latest RT
release, 2.0.13. (A few changes were needed to get it to work with
2.0.12, and I didn't get to mail the 2.0.12 patch before 2.0.13 came
out.)
This patch will likely not work with any other languages besides
English and Japanese, and will in fact break if you use other
languages in email or web.
Ben
diff -ruN rt-2-0-13.orig/lib/RT/Action/SendEmail.pm rt-2-0-13/lib/RT/Action/SendEmail.pm
--- rt-2-0-13.orig/lib/RT/Action/SendEmail.pm Thu Feb 28 15:49:09 2002
+++ rt-2-0-13/lib/RT/Action/SendEmail.pm Thu Mar 28 15:03:35 2002
@@ -2,6 +2,8 @@
# Copyright 2000 Jesse Vincent <jesse at fsck.com> and Tobias Brox <tobix at cpan.org>
# Released under the terms of the GNU Public License
+use Jcode;
+
package RT::Action::SendEmail;
require RT::Action::Generic;
@@ -98,6 +100,21 @@
$MIMEObj->make_singlepart;
+
+ if (Jcode::getcode($MIMEObj->as_string) ne 'ascii') {
+ $MIMEObj->head->set('content-type', 'text/plain; charset=iso-2022-jp');
+ $MIMEObj->head->set('content-transfer-encoding', '7bit');
+ $MIMEObj->head->set('mime-version', '1.0');
+ my $body_r = $MIMEObj->bodyhandle->open("r");
+ my $body;
+ while (defined($_ = $body_r->getline)) {
+ $body .= Jcode->new($_)->iso_2022_jp;
+ }
+ $body_r->close;
+ my $body_w = $MIMEObj->bodyhandle->open("w");
+ $body_w->print($body);
+ $body_w->close;
+ }
#If we don't have any recipients to send to, don't send a message;
@@ -113,7 +130,7 @@
$self->SetHeader('To', join(',', @{$self->{'PseudoTo'}}))
if ( (@{$self->{'PseudoTo'}}) and (! $MIMEObj->head->get('To')));
-
+
if ($RT::MailCommand eq 'sendmailpipe') {
open (MAIL, "|$RT::SendmailPath $RT::SendmailArguments") || return(0);
print MAIL $MIMEObj->as_string;
@@ -292,6 +309,10 @@
unless ($self->TemplateObj->MIMEObj->head->get('From')) {
my $friendly_name=$self->TransactionObj->CreatorObj->RealName;
# TODO: this "via RT" should really be site-configurable.
+ # hack for Japanese - che at debian.org
+ if (Jcode::getcode($friendly_name) ne 'ascii') {
+ $friendly_name = Jcode->new($friendly_name)->mime_encode();
+ }
$self->SetHeader('From', "\"$friendly_name via RT\" <$replyto>");
}
@@ -396,7 +417,8 @@
sub SetSubject {
my $self = shift;
- unless ($self->TemplateObj->MIMEObj->head->get('Subject')) {
+ my $subj = $self->TemplateObj->MIMEObj->head->get('Subject');
+ if (not $subj) {
my $message=$self->TransactionObj->Message;
my $ticket=$self->TicketObj->Id;
@@ -423,11 +445,21 @@
$subject =~ s/(\r\n|\n|\s)/ /gi;
+ # hack for Japanese
+ if (Jcode::getcode($subject) ne 'ascii') {
+ $subject = Jcode->new($subject)->mime_encode();
+ }
+
chomp $subject;
$self->SetHeader('Subject',$subject);
-
- }
- return($subject);
+ return $subject;
+ } elsif (Jcode::getcode($subj) ne 'ascii') {
+ my $newsubj = Jcode->new($subject)->mime_encode();
+ $self->SetHeader('Subject', $newsubj);
+ return $newsubj;
+ } else {
+ return $subj;
+ }
}
# }}}
diff -ruN rt-2-0-13.orig/lib/RT/Interface/Email.pm rt-2-0-13/lib/RT/Interface/Email.pm
--- rt-2-0-13.orig/lib/RT/Interface/Email.pm Tue Feb 19 08:14:35 2002
+++ rt-2-0-13/lib/RT/Interface/Email.pm Thu Mar 28 15:00:20 2002
@@ -6,6 +6,7 @@
use strict;
use Mail::Address;
use MIME::Entity;
+use Jcode;
BEGIN {
use Exporter ();
@@ -246,8 +247,14 @@
# }}} (temporary directory)
#Ok. now that we're set up, let's get the stdin.
+
+ # Hack for Japanese.
+ my $body = '';
+ while (defined(my $line = <STDIN>)) {
+ $body .= Jcode->new($line)->euc;
+ }
my $entity;
- unless ($entity = $parser->read(\*STDIN)) {
+ unless ($entity = $parser->parse_data($body)) {
die "couldn't parse MIME stream";
}
#Now we've got a parsed mime object.
@@ -260,10 +267,15 @@
$head->unfold;
# TODO - information about the charset is lost here!
- $head->decode;
+ #$head->decode;
+ foreach my $header (qw(Subject To From Cc)) {
+ if ($head->count($header)) {
+ $head->replace($header,
+ Jcode->new($head->get($header))->mime_decode->euc);
+ }
+ }
return ($entity, $head);
-
}
# }}}
--
Brought to you by the letters Z and M and the number 13.
"You forgot Uranus." "Goooooooooodnight everybody!"
Debian GNU/Linux maintainer of Gimp and Nethack -- http://www.debian.org/
More information about the rt-users
mailing list