[jdev] About the Net::Jabber Charset !
LUKE
luke at tc.program.com.tw
Fri Sep 9 03:46:09 CDT 2005
Sorry! My english is very poor!
How to handle chinese mesage using Net::Jabber??
I use the Exodus, Gush, Pandion, Psi, Trillian Pro client to receive the message.But it have error in
showing chinese message.
use Encode --- Encode::from_to($subject, "big5", "utf-8" ) --- can not make it correct.
PS:
Net::Jabber V2.0
perl 5.8.7 ( ActivePerl Build 813)
WIN2K
===============================================================
use strict;
use Net::Jabber;
# Declare our constants
# ---------------------
use constant RECIPIENT => 'luke at localhost'; # Jabber ID to be notified
use constant SERVER => 'localhost'; # Jabber server to connect to
use constant PORT => 5222; # Port to connect to
use constant USER => 'luke'; # user this script connects as
use constant PASSWORD => 'luke!@#'; # password associated with USER
use constant RESOURCE => 'perlscript';
# Read and parse email and extract header info
# --------------------------------------------
# Create a new Jabber client and connect
# --------------------------------------
my $connection = Net::Jabber::Client->new();
$connection->Connect( "hostname" => SERVER,
"port" => PORT )
or die "Cannot connect ($!)\n";
# Identify and authenticate with the server
# -----------------------------------------
my @result = $connection->AuthSend( "username" => USER,
"password" => PASSWORD,
"resource" => RESOURCE );
if ($result[0] ne "ok") {
die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}
open(HANDLE,"mailerd.log");
while (<HANDLE>){
if ($_=~/^\[(.*)\]\s+\[(.*)\]\s+(.*)<(.*)>\s+\->\s+<(.*)>\s+\((.*)/){
# Create a message and build it up
# --------------------------------
my $time=$1;
my $from=$4;
my $to=$5;
my $subject=$6;
use Encode;
Encode::from_to($subject, "big5", "utf-8" ) ;
my $msg = Net::Jabber::Message->new();
$msg->SetMessage( "to" => RECIPIENT,
"subject" => "Email from $from",
"body" => join("\n", "Subject: $subject",
"Date: $time") );
# Send the message
# ----------------
$connection->Send($msg);
}
}
# Disconnect from the Jabber server
# ---------------------------------
$connection->Disconnect();
exit;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.jabber.org/jdev/attachments/20050909/2a4b4590/attachment-0002.htm>
More information about the JDev
mailing list