#==========================================================================#
# ■ B.Forum Ver.1.01                                                      #
# ■ プラグインSDK(sendmail)                                               #
# □ Encode = EUC                                                          #
# □ Hiroaki,Sakuma (sakuma@beetas.org)                                    #
#                                                                          #
# このアプリケーションはオープンソースウェアです.                          #
# 無料で使用することができます.                                            #
# なお, 詳細な使用条件/最新情報については下記サイトをご覧下さい.           #
# http://www.beetas.org/                                                   #
#                                                                          #
# ------------------------------------------------------------------------ #
# Copyright 2001-2002 Hiroaki,Sakuma All Rights Reserved.                  #
# Copyright 2001-2002 BEETAS.org All Rights Reserved.                      #
#                                                                          #
#==========================================================================#
package sendmail;

use Exporter;
use strict;

@ISA = qw(Exporter);
@EXPORT = qw(version status require_min require_max main);

my (%in %SET);

sub version {
	# バージョン(要変更)
	$version = "Plugin SDK(sendmail) 1.01(0055-0058)";
	return $version;
}

sub status {
	return 1;
}

sub require_min {
	# 最低動作バージョン(要変更)
	$require_min = "0055";
	return $require_min;
}

sub require_max {
	# 最高動作バージョン(要変更)
	$require_max = "0058";
	return $require_max;
}

sub main ($$$@) {

	# 変更の必要なし
	my $head = $_[0];
	my $foot = $_[1];
	%in = %{$_[2]};
	splice (@_,0,3);
	%SET = %Bforum::SET;



	# ここから変更

	my ($tmp1);

	if ($SET{'SENDMAIL'} && open (MAIL, "| $SET{'SENDMAIL'} >$SET{'USER_DIR'}/sendmail.error")) {

		## for code
		local ($tmp2);

		$tmp1 .= "Sender: $SET{'ADDRESS'}\n";
		$tmp1 .= "MIME-Version: 1.0\n";
		$tmp1 .= "Content-type: text/plain; Charset=ISO-2022-JP\n";
		$tmp1 .= "Content-Transfer-Encoding: 7bit\n";
		$tmp1 .= "X-Mailer: BEETAS.org B.Forum {version}(Revision:{revision})\n";

		%Bforum::email = %{$_[1]};
		$Bforum::email{'address'} = $SET{'ADDRESS'};
		$Bforum::email{'subject'} = $email{'title'};
		$Bforum::email{'message'} =~ s/&lt;/</go;
		$Bforum::email{'message'} =~ s/&gt;/>/go;
		$Bforum::email{'message'} =~ s/&amp;/&/go;
		$Bforum::email{'message'} =~ s/&quot;/"/go;
		$Bforum::email{'separator'} = ("-" x ($SET{'SENDMAIL_WRAP'} | 76));
		$Bforum::email{'version'} = $Bforum::version;
		$Bforum::email{'revision'} = $Bforum::revision;

		$tmp2 = $_[0];

		&Bforum::do($tmp1);
		&Bforum::change($tmp1,\%Bforum::email);

		&Bforum::do($tmp2);
		&Bforum::change($tmp2,\%Bforum::email);

		$tmp1 =~ s/Subject: (.*)/&Bforum::_subject($1)/ego;

		if ($SET{'SENDMAIL_WRAP'}) {
			if ($tmp2 =~ /^(.+?\n{2})(.*)$/so) {
				$tmp2 = $2;
				$tmp2 = $1 . join("\n",&Bforum::_wrap($tmp2,$SET{'SENDMAIL_WRAP'}));
			}
		}

		$tmp2 =~ s/\n\n/\n$tmp1\n/o;

		&Bforum::code(\$tmp2,'jis');

		$tmp2 =~ s/\n/\r\n/go;
		binmode (MAIL);
		print MAIL $tmp2;
		close (MAIL);
	}
	undef @_;

	return "";

}

sub about {
	close (NULL);
	&Bforum::about((caller)[2] . '@' . &version);
}

1;

