<?
// Wriiten by Spike^ekipS <spike@spikeekips.net>

include_once "./setting.php";

include_once $global["root"] . "/include/handle.php";
include_once $global["root"] . "/include/print_array.php";
include_once $global["root"] . "/include/print_time.php";

//include_once $global["root"] . "/module/message/function/xmlrpc.php";
include_once $global["root"] . "/module/message/function/do.php";

//-------------------------------------------------- execute

include_once $global["root"] . "/lib/Site.php";
include_once $global["root"] . "/lib/Payload.php";
include_once $global["root"] . "/lib/EmailData.php";
include_once $global["root"] . "/lib/Basic_message.php";
include_once $global["root"] . "/lib/Template.php";

$Site = new Site;
$Site->init("mail");
include_once $global["lang"] . "/" . $_SESSION["config_lang"] . ".php";

extract($_POST);

if (! trim($To)) {
	$Site->end1();
	goprev();
}

// check whether mail to group or not.
if ($mail_to_group) {
	include_once $global["root"] . "/lib/Card_Group.php";

	$Group = new Card_Group;
	$a = $Group->get_address($To);

	if (! $a) {
		$Site->end1();
		goprev();
	} else {
		$To = implode(",", $a);
	}

} else {
	if (! ereg("@", $To)) $To = $To . "@" . $_SESSION["config_domain"];
}

$EmailData = new EmailData;

$var["To"] = explode(",", trim($To));
$var["Subject"] = $EmailData->decode($Subject);

if ($_POST["action"] == "reply") {
	$Template = new Template;

	$one["message"] = $EmailData->decode($body);

	if ($_POST["include_original_message"]) {
		$BM = new Basic_message;
		$info = $BM->info($_POST["include_original_message"]);
		$a["author"] = sprintf($string["message3"],
			$info["author"]["full"]);

		$a["original_message"] = getContent($_POST["include_original_message"], "body");
		$one["original_message"] =
			$Template->generate("/module/message/template/message_reply_original_message",
			$a);
	}

	$var["body"] = $Template->generate("/module/message/template/message_reply", $one);
} else {
	$var["body"] = $EmailData->decode($body);
}

if (! $delSignature) {
	$var["delSignature"] = "";
} else {
	$var["delSignature"] = true;
}

if (send_mail($var)) {
	// payload test
	$Payload = new Payload;
	$Payload->clean();

	$url = sprintf(
		"Location: %s%s", $_SESSION["user_www_url"], $_SESSION["user_previous_page"]);

	$Site->end1();

	Header($url);
	exit;
} else {
	$Site->end1();
	goprev();
}

/*
Changelog
---------
Mon Mar  3 11:14:56 KST 2003
- retouched.

Mon Mar  3 11:15:04 KST 2003
- big file size(larger than 1047552) can not be inserted into queue table.
  It was caused  from the limitation of 'post_max_size', 'upload_max_filesize'
  (PHP) and 'max_allowed_packet' (MySQL).

  So set it high!
  -----------------
  post_max_size = 20M
  upload_max_filesize = 20M
  (Edit php.ini)

  max_allowed_packet = 200000000
  (mysql> set max_allowed_packet = 200000000;)

Wed Mar  5 17:55:43 KST 2003
- sendmailThruXMLRPC() added.

Mon Jul 21 03:09:22 KST 2003
- new authentication system applied.

*/

?>
