[Pyukiwiki-cvs 0004660] CVS update: PyukiWiki-Devel-UTF8/lib/Nana

Zurück zum Archiv-Index

PyukiWiki CVS Commit pyuki****@lists*****
2012年 2月 11日 (土) 17:50:42 JST


Index: PyukiWiki-Devel-UTF8/lib/Nana/Mail.pm
diff -u PyukiWiki-Devel-UTF8/lib/Nana/Mail.pm:1.254 PyukiWiki-Devel-UTF8/lib/Nana/Mail.pm:1.255
--- PyukiWiki-Devel-UTF8/lib/Nana/Mail.pm:1.254	Tue Jan 31 19:12:03 2012
+++ PyukiWiki-Devel-UTF8/lib/Nana/Mail.pm	Sat Feb 11 17:50:42 2012
@@ -1,8 +1,8 @@
 ######################################################################
 # Mail.pm - This is PyukiWiki, yet another Wiki clone.
-# $Id: Mail.pm,v 1.254 2012/01/31 10:12:03 papu Exp $
+# $Id: Mail.pm,v 1.255 2012/02/11 08:50:42 papu Exp $
 #
-# "Nana::Mail" version 0.3 $$
+# "Nana::Mail" version 0.4 $$
 # Author: Nanami
 # http://nanakochi.daiba.cx/
 # Copyright (C) 2004-2012 Nekyo
@@ -24,7 +24,7 @@
 use 5.8.1;
 use strict;
 use vars qw($VERSION);
-$VERSION = '0.3';
+$VERSION = '0.4';
 
 # sendmailパス検索候補
 $Nana::Mail::sendmail=<<EOM;
@@ -37,27 +37,77 @@
 
 use Jcode;
 
+sub utf8mail {
+	my $flg=0;
+	if($::send_utf8_mail ne 0) {
+		if(&load_module("Jcode") && &load_module("MIME::Base64")) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
 sub mime_conv {
 	my($str,$code)=@_;
-	$str=Jcode->new($str,$code)->jis;
-	$str=Jcode->new($str)->mime_encode;
+	if (&utf8mail) {
+		return "" if($str eq "");
+		$str=Jcode->new($str,$code)->utf8;
+		$str=MIME::Base64::encode_base64($str, "");
+		$str='=?utf-8?B?' . $str . '?=';
+	} else {
+		$str=Jcode->new($str,$code)->jis;
+		$str=Jcode->new($str)->mime_encode;
+	}
 	return $str;
 }
 
+sub mime_conv_body {
+	my($data,$code)=@_;
+	if (&utf8mail) {
+		$data=Jcode->new($data,$code)->utf8;
+		$data=MIME::Base64::encode_base64($data);
+	} else {
+		$data=Jcode->new($data,$code)->jis;
+	}
+	return $data;
+}
+
 sub send {
 	my(%hash)=@_;
-	my $to=&mime_conv($hash{to},$::defaultcode);
+	my $to=$hash{to};
 	my $to_name=&mime_conv($hash{to_name},$::defaultcode);
-	my $from=&mime_conv($hash{from},$::defaultcode);
+	my $from=$hash{from};
 	my $from_name=&mime_conv($hash{from_name},$::defaultcode);
-	my $subject=&mime_conv($hash{subject},$::defaultcode);
-	my $data=Jcode->new($hash{data},$::defaultcode)->jis;
-	return 1 if($to eq '' || $from eq '' || $::modifier_sendmail eq '');
+	my $subject=$hash{subject};
 	$subject="[Wiki] $::basehref" if($subject eq '');
+	$subject=&mime_conv($subject,$::defaultcode);
+	my $data=&mime_conv_body($hash{data},$::defaultcode);
+	return 1 if($to eq '' || $from eq '' || $::modifier_sendmail eq '');
 
 	$to=qq($to_name\n <$to>) if($to_name ne '');
 	$from=qq($from_name\n <$from>) if($from_name ne '');
-	my $mail=<<EOM;
+	my $mail;
+	my $part=time;
+
+	if (&utf8mail) {
+		$mail=<<EOM;
+To: $to
+From: $from
+Subject: $subject
+MIME-Version: 1.0
+Content-Type: multipart/mixed;
+	boundary="----=_Part_$part"
+Content-Transfer-Encoding: 7bit
+
+------=_Part_$part
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: base64
+
+$data
+------=_Part_$part--
+EOM
+	} else {
+		$mail=<<EOM;
 To: $to
 From: $from
 Subject: $subject
@@ -67,7 +117,12 @@
 
 $data
 EOM
+	}
+	&sendmail($mail);
+}
 
+sub sendmail {
+	my($mail)=@_;
 	foreach(split(/\n/,"$::modifier_sendmail\n$Nana::Mail::sendmail")) {
 		my($exec,$opt1, $opt2, $opt3, $opt4, $opt5)=split(/ /,$_);
 		if(-r $exec) {
@@ -104,5 +159,9 @@
 		  subject=>"[Wiki]$mode $::basehref", data=>$message);
 }
 
+sub load_module {
+	my $funcp = $::functions{"load_module"};
+	return &$funcp(@_);
+}
 1;
 __END__



Pyukiwiki-cvs メーリングリストの案内
Zurück zum Archiv-Index