[rt-users] [PATCH] Japanese support in RT 2.0.11
Ben Gertzfield
che at debian.org
Mon Mar 4 04:12:12 EST 2002
I have patched Request Tracker 2.0.11 to work with Japanese, and both
email and web work correctly now. Outgoing emails and incoming emails
are both supported in Japanese.
This patch does not deal with any languages other than Japanese and
English, and in fact will probably break if
German/French/Russian/whatever messages are sent.
This patch requires Jcode.pm from http://openlab.ring.gr.jp/Jcode/ to
be installed. It stores all data in the DB in EUC-JP, and converts
incoming emails from ISO-2022-JP to EUC-JP. The subject line is
correctly MIME decoded/encoded with Base64 then converted, as well.
You will want to tell your web server to serve all pages for RT as
EUC-JP. In my apache httpd.conf, I used:
AddDefaultCharset euc-jp
The patch is available at:
http://nausicaa.interq.or.jp/rt/rt-japanese.patch
Patch follows, against Request Tracker version 2.0.11.
diff -ruN rt-2-0-11.orig/lib/RT/Action/SendEmail.pm rt-2-0-11/lib/RT/Action/SendEmail.pm
--- rt-2-0-11.orig/lib/RT/Action/SendEmail.pm Wed Nov 7 08:04:17 2001
+++ rt-2-0-11/lib/RT/Action/SendEmail.pm Mon Mar 4 17:25:25 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,19 @@
$MIMEObj->make_singlepart;
+
+ if (Jcode::getcode($MIMEObj->as_string) ne 'ascii') {
+ $MIMEObj->head->set('content-type', 'text/plain; charset=iso-2022-jp');
+ 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;
@@ -292,6 +307,11 @@
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 +416,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 +444,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-11.orig/lib/RT/Interface/Email.pm rt-2-0-11/lib/RT/Interface/Email.pm
--- rt-2-0-11.orig/lib/RT/Interface/Email.pm Wed Nov 7 08:04:52 2001
+++ rt-2-0-11/lib/RT/Interface/Email.pm Mon Mar 4 17:33:58 2002
@@ -6,6 +6,7 @@
use strict;
use Mail::Address;
use MIME::Entity;
+use Jcode;
BEGIN {
use Exporter ();
@@ -244,8 +245,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.
@@ -254,10 +261,15 @@
my $head = $entity->head;
# 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 M and Y and the number 19.
"You should be glad you don't have diaper rash. Mah Jongg."
Debian GNU/Linux maintainer of Gimp and Nethack -- http://www.debian.org/
More information about the rt-users
mailing list