PageRenderTime 93ms CodeModel.GetById 24ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 1ms

/src/system/application/libraries/qdmail.php

https://bitbucket.org/seezoo/seezoo/
PHP | 4120 lines | 3564 code | 216 blank | 340 comment | 530 complexity | e2ec42afa2bdbd6048c4784be5743f2f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * Qdmail ver 1.2.6b
   4 * E-Mail for multibyte charset
   5 *
   6 * PHP versions 4 and 5 (PHP4.3 upper)
   7 *
   8 * Copyright 2008, Spok in japan , tokyo
   9 * hal456.net/qdmail    :  http://hal456.net/qdmail/
  10 * & CPA-LAB/Technical  :  http://www.cpa-lab.com/tech/
  11 * Licensed under The MIT License License
  12 *
  13 * @copyright		Copyright 2008, Spok.
  14 * @link			http://hal456.net/qdmail/
  15 * @version			1.2.6b
  16 * @lastmodified	2008-10-23
  17 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
  18 *
  19 * Qdmail is sending e-mail library for multibyte language ,
  20 * easy , quickly , usefull , and you can specify deeply the details.
  21 * Copyright (C) 2008   spok
  22*/
  23//-------------------------------------------
  24// For CakePHP , extended 'Object' Class ,
  25// if including in CakePHP Component .
  26// At normal PHP Script or another Framework ,
  27// 'QdmailBranch' means Dummy Base Class .
  28//-------------------------------------------
  29if (!defined('QD_DS')) {
  30	define('QD_DS', DIRECTORY_SEPARATOR);
  31}
  32
  33if ( defined('CAKE_CORE_INCLUDE_PATH') || defined('CAKE')) {
  34	class QdmailBranch extends Object{
  35	}
  36}else{
  37	class QdmailBranch{
  38	}
  39}
  40
  41if( !function_exists( 'qd_send_mail' ) ){
  42
  43	function qd_send_mail( $type , $to = null, $subject = null , $content = null , $other_header = array() , $attach = null, $debug = 0 ){
  44		$type_org = $type;
  45
  46		$mail = Qdmail::getInstance();
  47		$mail->debug = $debug;
  48		if(!is_array($type)){
  49			$type = array('TYPE'=>$type);
  50		}
  51		list( $type , $link ) = $mail->keyUpper($type);
  52		$option = array();
  53		$return = array();
  54		$type = array_change_key_case( $type , CASE_UPPER ) ;
  55		$option = (isset($type['OPTION']) && is_array($type['OPTION'])) ? $type['OPTION'] : array();			$return = (isset($type['RETURN']) && is_array($type['RETURN'])) ? $type['RETURN'] : array();
  56		if(isset($type['SMTP'])){
  57			$option = array_merge($option,array('SMTP'=>true,'smtpServer'=>$type['SMTP']));
  58		}
  59		$type = isset($type['TYPE']) ? $type['TYPE']:'text';
  60		$_type=array('TEXT'=>'Text','HTML'=>'Html','DECO'=>'Deco' ,'DECOTEMPLATE'=>'DecoTemplate');
  61		$easy_method = isset($_type[strtoupper($type)]) ? 'easy'.$_type[strtoupper($type)]:'_';
  62
  63		if(!method_exists($mail,$easy_method)){
  64			$mail -> errorGather('Illegal type \''.$type.'\'',__LINE__);
  65			return false;
  66		}
  67
  68		$ret = $mail->{$easy_method}( $to , $subject , $content , $other_header , $attach , $option );
  69
  70		foreach($return as $method => $value ){
  71			if(method_exists($mail,$method)){
  72				$type_org[$link['RETURN']][$method] = $mail -> {$method}($value);
  73			}
  74		}
  75		if(0!==count($return)){
  76			$type_org[$link['RETURN']]['qd_send_mail'] = $ret;
  77			$ret = $type_org;
  78		}
  79
  80		return $ret;
  81	}
  82}
  83
  84class QdmailBase extends QdmailBranch{
  85
  86	//----------------------------
  87	// Default Language
  88	// If you do not Japanese
  89	// Please change this propaty for your Language and Encoding
  90	//----------------------------
  91	var	$lang_def			= "ja";
  92	var	$encoding_def		= "utf-8";
  93	var	$detect_def			= array('ASCII','JIS','UTF-8','EUC-JP','SJIS');
  94	var $mb_parameter_stack = null;
  95	var $united_charset		= null;
  96	var $mime_encode_max	= 75;
  97	//------------------------
  98	// Time Zone , Message Id
  99	//------------------------
 100	var $time_zone			= null; // '+0900' in Japan
 101	var $message_id			= true;
 102	var $salt				= 'qdmail';
 103	var $message_id_right	= null;
 104	//----------------------------
 105	// Line Feed Character & kana
 106	//----------------------------
 107	var	$LFC				=  "\r\n";// Notice: CRLF ,If you failed, change to "\n"
 108	var $LFC_Qmail			=  null;
 109	var $is_qmail			=  null;
 110	var $language			= 'ja';
 111	var $kana				=  false; // kana header
 112	//----------
 113	// sysytem
 114	//----------
 115	var $kana_content_relation =  false;
 116	var	$name			= 'Qdmail';
 117	var	$version		= '1.2.6b';
 118	var	$xmailer		= 'PHP-Qdmail';
 119	var $license 		= 'The_MIT_License';
 120	//--------------------
 121	// charset , encoding
 122	//--------------------
 123	var $charset_header				= 'iso-2022-jp';
 124	var $charset_content			= 'iso-2022-jp';
 125	var $charset_attach_filename	= 'iso-2022-jp';
 126	var $content_transfer_enc_text	= '7bit';
 127	var $content_transfer_enc_html	= '7bit';
 128	var $detect_order				= false;
 129//	var $detect_order				= "iso-2022-jp,eucJP-win,UTF-8,SJIS-win,jis,ASCII";
 130	var $qdmail_system_charset 		= 'utf-8';
 131	var	$force_change_charset		= false;
 132	var $corres_charset				= array(
 133			'HEADER'=>'charset_header',
 134			'BODY'=>'charset_content',
 135			'ATTACH'=>'charset_attach_filename',
 136			'TEXT'=>'content_transfer_enc_text',
 137			'HTML'=>'content_transfer_enc_html',
 138			'DETECT'=>'detect_order',
 139			'SYSTEM'=>'qdmail_system_charset',
 140		) ;
 141	//--------------------------
 142	// for address
 143	//--------------------------
 144	var $varidate_address_regex	= '/[^@]+@[^@]+/';
 145	var $allow_blank_header		= false;
 146	var	$addr_many = array(
 147		'TO'	=> true,
 148		'CC'	=> true,
 149		'BCC'	=> true,
 150		'FROM'	=> false,
 151		'REPLYTO'=> false
 152	);
 153	var	$addr_head_name = array(
 154		'TO'	=> 'To',
 155		'CC'	=> 'Cc',
 156		'BCC'	=> 'Bcc',
 157		'FROM'	=> 'From',
 158		'REPLYTO'=>'Reply-To'
 159	);
 160	var $header_must =array( 'TO' , 'FROM' , 'SUBJECT' );
 161	var $body_empty_allow = false;
 162	var $tokey		= array(
 163		'_ADDR' => 'mail',
 164		'_NAME' => 'name',
 165	);
 166	//--------------
 167	// content_id
 168	//--------------
 169	var	$content_id_include_attach_path = false ;
 170	var	$content_id_only_filename = true ;
 171	//---------------
 172	// Once mode
 173	//---------------
 174	var $body_structure			= array();
 175	var $body_build_once		= false;
 176	var $body_already_build		= false;
 177	var $attach_build_once		= true;
 178	var $attach_already_build	= false;
 179	//------------------------------
 180	// simple replace
 181	//------------------------------
 182	var $simple_replace	= false;
 183	var $replace		= array();
 184	var $replace_with_to_priority= true;
 185	var $replace_def	= array();
 186	// simple replace command prefix
 187	var	$rep_prefix		= null;
 188	//---------
 189	// wordwrap
 190	//---------
 191	var	$wordwrap_allow	= false;
 192	var	$wrap_prohibit_allow	= false;
 193	var $wordwrap_length= 45 ;
 194	// inteligent wordwrap
 195	// false is that the word exist in the line ,
 196	// true is that the word must be the beginning of a line
 197	var	$wrap_except	= array(
 198		'http://'=>false,
 199		'code'=>true,
 200	);
 201	var $wrap_prohibit_top=',.;:–?!‼、。.))]}}〕〉》」』】〙〗〟’”»ヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎ‐〜?!';
 202	var $wrap_prohibit_end='(([{{〔〈《「『【〘〖‘“« ';
 203	var $wrap_prohibit = array();
 204	// multibyte wordwrap , by wordcount or by wordwidth
 205	var	$wrap_width	= true;
 206	// multibyte wordwidth compare by ascii
 207	var	$mb_strwidth_magni = 2;
 208	//------------------
 209	// To Separate mode
 210	//------------------
 211	var	$to_separate	= false ;
 212	//----------------------------
 213	// html mail
 214	//----------------------------
 215	var $is_html		= null ;
 216	var	$auto_both		= true ; // text & html
 217	var	$inline_mode	= false;
 218	var	$deco_kind		= null ; // number of $this->deco_def
 219	var	$auto_deco_judge= false;
 220	var $no_inline_attach_structure = 0;
 221	var $deco_def_default = 0;
 222	var	$deco_def		=array(
 223		array(
 224			'OPTION_NAME'	=> array( 'MHTML' , 'INLINE' , 'PC' ),
 225			'STRUCTURE'		=> 1,
 226			'_CHARSET'		=> 'iso-2022-jp' ,
 227			'ENC_TEXT'		=> '7bit',
 228			'ENC_HTML'		=> 'QUOTED-PRINTABLE',
 229			'HTML_EXTERNAL'	=> false,
 230			'DISPOSITION'	=> true,
 231		),
 232		array(
 233			'OPTION_NAME'	=> array( 'DC' , 'DOCOMO' ),
 234			'STRUCTURE'		=> 2,
 235			'_CHARSET'		=> 'iso-2022-jp',
 236			'ENC_TEXT'		=> '7bit',
 237			'ENC_HTML'		=> 'QUOTED-PRINTABLE',
 238			'HTML_EXTERNAL'	=> array('this','stripCrlf'),
 239			'DISPOSITION'	=> false,
 240		),
 241		array(
 242			'OPTION_NAME'	=> array( 'AU' ,'EZ', 'EZWEB'),
 243			'STRUCTURE'		=> 3,
 244			'_CHARSET'		=> 'iso-2022-jp',
 245			'ENC_TEXT'		=> '7bit',
 246			'ENC_HTML'		=> 'QUOTED-PRINTABLE',
 247			'HTML_EXTERNAL'	=> array('this','stripCrlf'),
 248			'DISPOSITION'	=> true,
 249		),
 250		array(
 251			'OPTION_NAME'	=> array( 'SB' , 'SOFTBANK' ),
 252			'STRUCTURE'		=> 4,
 253			'_CHARSET'		=> 'iso-2022-jp',
 254			'ENC_TEXT'		=> '7bit',
 255			'ENC_HTML'		=> 'QUOTED-PRINTABLE',
 256			'HTML_EXTERNAL'	=> array('this','stripCrlf') ,
 257			'DISPOSITION'	=> true ,
 258		),
 259		array(
 260			'OPTION_NAME'	=> array( 'EM','EMOBILE' ,'EMNET'),
 261			'STRUCTURE'		=> 2,
 262			'_CHARSET'		=> 'iso-2022-jp',
 263			'ENC_TEXT'		=> '7bit',
 264			'ENC_HTML'		=> 'QUOTED-PRINTABLE',
 265			'HTML_EXTERNAL'	=> array('this','stripCrlf') ,
 266			'DISPOSITION'	=> true ,
 267		),
 268		array(
 269			'OPTION_NAME'	=> array( 'WL','WILLCOM' ,'POCKET'),
 270			'STRUCTURE'		=> 2,
 271			'_CHARSET'		=> 'iso-2022-jp',
 272			'ENC_TEXT'		=> '7bit',
 273			'ENC_HTML'		=> 'QUOTED-PRINTABLE',
 274			'HTML_EXTERNAL'	=> array('this','stripCrlf') ,
 275			'DISPOSITION'	=> true ,
 276		),
 277		array(
 278			'OPTION_NAME'	=> array( 'TEMPLATE_DC' , 'TEMPLATE_DOCOMO' ,'TPL_DC'),
 279			'STRUCTURE'		=> 5,
 280			'_CHARSET'		=> 'Shift_JIS',
 281			'ENC_TEXT'		=> '8bit',
 282			'ENC_HTML'		=> '8bit',
 283			'HTML_EXTERNAL'	=> array('this','stripCrlf'),
 284			'DISPOSITION'	=> false,
 285			'BOUNDARY'		=> 'mime9DC9bdary',
 286			'TOP'			=> array('Decomail-Template'),
 287			'CID_PREFIX'	=> 'img_',
 288			'CID_NUM_COL'	=> 3,
 289		),
 290		array(
 291			'OPTION_NAME'	=> array( 'TEMPLATE_AU','TPL_AU' ,'TPL_AU_2_0'),
 292			'STRUCTURE'		=> 6,
 293			'_CHARSET'		=> 'iso-2022-jp',
 294			'ENC_TEXT'		=> '7bit',
 295			'ENC_HTML'		=> '7bit',
 296			'HTML_EXTERNAL'	=> array('this','stripCrlf'),
 297			'DISPOSITION'	=> false,
 298			'BOUNDARY'		=> '--=_KDDI_NEXT_PART_0000',
 299			'TOP'			=> array('KDDI_HTML_MAIL_2_0'),
 300			'CID_PREFIX'	=> 'img_cid_',
 301			'CID_NUM_COL'	=> 3,
 302		),
 303		array(
 304			'OPTION_NAME'	=> array( 'TEMPLATE_AU_1_0','TPL_AU_1_0' ,'TPL_AU_1_0'),
 305			'STRUCTURE'		=> 6,
 306			'_CHARSET'		=> 'iso-2022-jp',
 307			'ENC_TEXT'		=> '7bit',
 308			'ENC_HTML'		=> '7bit',
 309			'HTML_EXTERNAL'	=> array('this','stripCrlf'),
 310			'DISPOSITION'	=> false,
 311			'BOUNDARY'		=> '--=_KDDI_NEXT_PART_0000',
 312			'TOP'			=> array('KDDI_HTML_MAIL_1_0'),
 313			'CID_PREFIX'	=> 'img_cid_',
 314			'CID_NUM_COL'	=> 3,
 315		),
 316		array(
 317			'OPTION_NAME'	=> array( 'TEMPLATE_SB','TPL_SB' ),
 318			'STRUCTURE'		=> 5,
 319			'_CHARSET'		=> 'Shift_JIS',
 320			'ENC_TEXT'		=> '8bit',
 321			'ENC_HTML'		=> '8bit',
 322			'HTML_EXTERNAL'	=> array('this','stripCrlf'),
 323			'DISPOSITION'	=> false,
 324			'BOUNDARY'		=> 'aremejkj15a14',
 325			'TOP'			=> array('HTMLMail-Template-Version:1.0',
 326				'HTMLMail-Template-Title:HTMLMail-Template',
 327				''
 328			),
 329			'CID_PREFIX'	=> '',
 330			'CID_NUM_COL'	=> 2,
 331			'CID_AFTER'		=> '@areme.jp',
 332		),
 333	);
 334
 335	var		$structure		=array(
 336		// no inline attachment
 337		0 => array(
 338			'multipart/mixed' => array(
 339				'multipart/alternative'=>array(
 340					'html'		=>	1,
 341					'plain'		=>	1,
 342					'OMIT'		=>	true,
 343				),
 344				'image'		=> 'BOTH', // Available Inline
 345				'OMIT'		=>	true,
 346			),
 347			'OMIT'		=>	true,
 348		),
 349		// PC inline HTML
 350		1 => array(
 351			'multipart/mixed' => array(
 352				'multipart/alternative'=>array(
 353					'multipart/related'	=>	array(
 354						'html'		=>	1,
 355						'image'		=>	'INLINE',
 356						'OMIT'		=>	true,
 357					),
 358					'plain'		=>	1,
 359					'OMIT'		=>	true,
 360				),
 361				'image'		=> 'NOT_INLINE', // not inline
 362				'OMIT'	=> true,
 363			),
 364			'OMIT'	=> true,
 365		),
 366		2 => array(
 367			'multipart/mixed' => array(
 368				'multipart/related'=>array(
 369					'multipart/alternative'	=>	array(
 370						'plain'		=>	1,
 371						'html'		=>	1,
 372						'OMIT'		=>	false,
 373					),
 374					'image'		=>	'INLINE',
 375					'OMIT'		=>	false,
 376				),
 377				'OMIT'		=>	false,
 378				'image'		=> 'NOT_INLINE',
 379			),
 380			'OMIT'	=> false,
 381		),
 382		3 => array(
 383			'multipart/mixed' => array(
 384				'multipart/alternative'	=>	array(
 385					'plain'		=>	1,
 386					'html'		=>	1,
 387					'OMIT'		=>	false,
 388				),
 389				'image'		=>	'BOTH',
 390				'OMIT'		=>	false,
 391			),
 392			'OMIT'	=> false,
 393		),
 394		4 => array(
 395			'multipart/related'=>array(
 396				'multipart/alternative'	=>	array(
 397					'plain'		=>	1,
 398					'html'		=>	1,
 399					'OMIT'		=>	false,
 400				),
 401				'image'		=>	'INLINE',
 402				'OMIT'		=>	false,
 403			),
 404			'image'		=> 'NOT_INLINE',
 405			'OMIT'		=>	false,
 406			),
 407		5 => array(
 408			'multipart/related'=>array(
 409				'plain'		=>	1,
 410				'html'		=>	1,
 411				'image'		=>	'INLINE',
 412				'OMIT'		=>	false,
 413				),
 414			'OMIT'		=>	false,
 415			),
 416		6 => array(
 417			'multipart/mixed'=>array(
 418				'plain'		=>	1,
 419				'html'		=>	1,
 420				'image'		=>	'INLINE',
 421				'OMIT'		=>	false,
 422				),
 423			'OMIT'		=>	false,
 424			),
 425	);
 426	var	$deco_judge		= array(
 427		'docomo.ne.jp'		=> 'DC',
 428		'softbank.ne.jp'	=> 'SB',
 429		'i.softbank.ne.jp'	=> 'SB',
 430		'disney.ne.jp'		=> 'SB',
 431		'vodafone.ne.jp'	=> 'SB',
 432		'ezweb.ne.jp'		=> 'AU',
 433		'emnet.ne.jp'		=> 'EM',
 434		'pdx.ne.jp'			=> 'WL',
 435		'gmail.com'			=> 'DC',
 436	);
 437
 438	//------------------
 439	// using address and content
 440	//------------------
 441	var	$to				= array()	;
 442	var	$from			= array()	;
 443	var	$cc				= array()	;
 444	var	$bcc			= array()	;
 445	var	$done			= array()	;
 446	var	$undone			= array()	;
 447	var	$replyto		= array()	;
 448	var	$recipient		= array()	;
 449	var	$allways_bcc	= null ;
 450	var	$header			= array()	;
 451	var	$other_header	= array()	;
 452	var $header_content_type = array();
 453	var $content		= array(
 454		'TEXT'=>array(
 455			'CONTENT'		=> null,
 456			'LENGTH'		=> null,
 457			'_CHARSET'		=> null,
 458			'ENC'			=> null,
 459			'_ORG_CHARSET'	=> null,
 460		),
 461		'HTML'=>array(
 462			'CONTENT'		=> null,
 463			'ORG_CONTENT'	=> null,
 464			'LENGTH'		=> null,
 465			'_CHARSET'		=> null,
 466			'ENC'			=> null,
 467			'_ORG_CHARSET'	=> null,
 468		),
 469	);
 470	var	$header_for_mailfunction_to;
 471	var	$header_for_mailfunction_subject;
 472	var	$header_for_mailfunction_other;
 473	var	$content_for_mailfunction;
 474	var $header_for_smtp_array;
 475	var $content_all_for_smtp;
 476	var	$header_for_smtp;
 477	//--------------
 478	// attachament
 479	//--------------
 480	var	$attach			= array();
 481	var	$attach_path	= null;
 482	var	$auto_ext		= true ; // mimetypes
 483	var $content_id_fix = false;
 484	//------------------------
 485	// Mailer
 486	//-------------------------
 487	var $mailer		= 'mail';
 488	//------------------------
 489	// Sendmail
 490	//-------------------------
 491	var $sendmail = false ;
 492	var $sendmail_path = null;
 493	//------------------------
 494	// SMTP
 495	//-------------------------
 496	var $smtp				= false ;
 497	var $smtp_object		= null;
 498	var $smtp_loglevel_link	= false;
 499	var $smtp_server = array(
 500	'host'		=> null ,
 501	'port'		=> 25 ,
 502	'from'		=> null,
 503	'user'		=> null,
 504	'pass' 		=> null,
 505	'protocol'	=> null,
 506	'pop_host'	=> null,
 507	'pop_user'	=> null,
 508	'pop_pass'	=> null,
 509	);
 510	//------------------------
 511	// render Mode
 512	//------------------------
 513	var $render_mode		= false;
 514	var $size			= array();
 515	//------------------------
 516	// Priority
 517	//------------------------
 518	var $priority			= null;
 519	var $priority_def   =array(
 520		'X-Priority'		=> array( 'HIGH' => 1 , 'NORMAL' => 3 , 'LOW' =>5 ),
 521		'X-MsMail-Priotiry'	=> array( 'HIGH'=>'High' , 'NORMAL'=>'Normal' , 'LOW'=>'Low' ),
 522		'Priotiry'			=> array( 'HIGH'=>'urgent' , 'NORMAL' => 'normal' , 'LOW'=> 'non-urgent' ),
 523		'Importance'		=> array( 'HIGH' =>'High' , 'NORMAL'=>'Normal' ,'LOW' =>'Low' ),
 524	);
 525	//------------------------
 526	// signed
 527	//------------------------
 528	var $sign						=	false;
 529	var $smime						=	false;
 530	var $pgp						=	false;
 531	var $private_key_file			= 'private.pem';
 532	var $certificate_file			= 'cert.pem';
 533	var $certificate_pass			=  null;
 534	var $certificate_file_path		=  null;
 535	var $certificate_temp_path		=  null;
 536	var $certificate_file_path_win	= 'c:\cert';
 537	var $certificate_temp_path_win	= 'c:\temp';
 538	var $certificate_file_path_unix	= '/user/local/cert';
 539	var $certificate_temp_path_unix	= '/tmp';
 540	//------------------------
 541	// etc
 542	//------------------------
 543	var $temporary_path		= null;
 544	var $simple_attach		= false;
 545	var $keep_parameter		= array(false);
 546	var	$mta_option			= null ;
 547	var	$is_create			= false;
 548	var	$address_validation_method  = array('this','validateAddr');
 549	var	$boundary_base_degit= 2 ;
 550	var	$stack_construct	= null ;
 551	var $start_time			= null;
 552	var $framework			= null;
 553	//-------------------------------
 554	// logs
 555	// 0 is nolog,
 556	// 1 is simple(Message 'Success' & recipt e-mail@address ),
 557	// 2 is including header data,
 558	// 3 is including fulldata,
 559	//------------------------------
 560	var	$log_level		= 0 ;
 561	var	$log_level_max  = 3 ;
 562	var	$log_path  		= './';
 563	var	$log_filename	= 'qdmail.log';
 564	var	$log_append		= 'a' ;
 565	var	$log_dateformat	= 'Y-m-d H:i:s';
 566	var	$log_LFC	= "\n";
 567	// -------------------------------
 568	// error & error logs
 569	// 0 is nolog,
 570	// 1 is simple,
 571	// 2 is including header data,
 572	// 3 is inc fulldata
 573	//--------------------------------
 574	var $error			= array();
 575	var $error_stack	= array();
 576	var $error_display	= true;
 577	var	$errorlog_level	= 0 ;
 578	var	$errorlog_level_max = 3 ;
 579	var	$errorlog_path  = './';
 580	var	$errorlog_filename= 'qbmail_error.log';
 581	var	$errorlog_append= 'a' ;
 582	var	$ignore_error	= false ;
 583	//----------------
 584	// debug
 585	// 0 is no debug mode & really sending ,
 586	// 1 is showing header&body & really sending ,
 587	// 2 is no sending & showing header&body and some vars
 588	//----------------
 589	var	$debug			= 0 ;
 590	var	$debug_report	= false;
 591	var	$debug_report_path = './';
 592	var	$debug_echo_charset= true;
 593
 594//****************************************************
 595//  Methods
 596//****************************************************
 597	//--------------------------------
 598	// constructor   set error display
 599	// $charset_def = null,
 600	// $error_display = true
 601	// $mail -> (&) new Qdmail( Charset , Encoding , DetectOrder , error_display );
 602	//--------------------------------
 603
 604	function __construct( $param = null ){
 605		$this->stack_construct = $param ;
 606		if( !empty( $param[0] ) && !empty( $param[1] ) ){
 607			$this->charset( $param[0] , $param[1] );
 608		}elseif( !empty( $param[0] ) ){
 609			$this->charset( $param[0] );
 610		}
 611		if( !empty( $param[2] ) ){
 612			$this->detect_order = $param[1];
 613		}
 614		if( false !== $this->detect_order ){
 615			$this->qd_detect_order( $this->detect_order );
 616		}
 617		if( !empty( $param[3] ) ){
 618			$this->error_display = $param[2];
 619		}
 620
 621		if(is_null($this->LFC)){
 622			$this->LFC = chr(13) . chr(10);
 623		}
 624
 625		if(is_null($this->LFC_Qmail)){
 626			$this->LFC_Qmail = chr(10);
 627		}
 628
 629		if($this->isQmail()){
 630			$this->LFC = $this->LFC_Qmail;
 631		}
 632		$this->optionNameLink();
 633		$this->wordwrapProhibitConstruct();
 634		$this->sendmail_path = ini_get("sendmail_path");
 635	}
 636
 637	function & getInstance(){
 638		static $instance = array();
 639
 640		if( isset($instance[0]) && is_object($instance[0]) ){
 641			$keep = $instance[0]->keep_parameter;
 642
 643			if(  is_string($keep[0]) ){
 644				$stack = array();
 645				foreach($keep as $method){
 646					if( !is_string( $method ) || !method_exists( $instance[0] , $method ) ){
 647						continue;
 648					}
 649					$stack[$method] = $instance[0]->{$method}();
 650				}
 651				$instance[0] -> reset();
 652				foreach($stack as $method => $value){
 653					$instance[0]->{$method}($value);
 654				}
 655			}elseif( true !== $keep[0] ){
 656				$instance[0] -> reset();
 657			}
 658
 659			return $instance[0];
 660		}
 661		$instance[0] =  new Qdmail();
 662		return  $instance[0];
 663	}
 664	//--------------------------
 665	// Decoration Mail Template
 666	//--------------------------
 667	function makeDecoTemplate( $deco_kind , $content ){
 668
 669		if(false===($this->deco_kind=$this->decoSelect( $deco_kind ))){
 670			return $this->errorGather('Illegal Decoration Kind \''.$deco_kind.'\'',__LINE__);
 671		}
 672
 673		$DECO = new QdDeco;
 674		$DECO -> template($content);
 675		$DECO -> decode();
 676		$content = $DECO -> get('HTML');
 677		$attach  = $DECO  -> get('ATTACH');
 678		$this -> renderMode( true );
 679		$this -> to('dummy@example.com');
 680		$this -> from('dummy@example.com');
 681		$this -> subject('dummy_subject');
 682		$this->body = null;
 683		$this->after_id = null;
 684		$this->content_id_fix = true;
 685		$this->is_html = 'HTML';
 686		$count = 0;
 687
 688		$content = $this->qd_convert_encoding($content,'utf-8',$this->qd_detect_encoding($content));
 689		$content=preg_replace('/\r?\n/','',$content);
 690
 691		foreach($attach as $key => $att){
 692			if( empty( $attach[$key]['CONTENT-ID'] ) ){
 693				continue;
 694			}
 695
 696			$aft = isset($this->deco_def[$this->deco_kind]['CID_AFTER']) ? $this->deco_def[$this->deco_kind]['CID_AFTER']:'';
 697			$prefix = isset($this->deco_def[$this->deco_kind]['CID_PREFIX']) ? $this->deco_def[$this->deco_kind]['CID_PREFIX']:'';
 698			$col_num = isset($this->deco_def[$this->deco_kind]['CID_NUM_COL']) ? $this->deco_def[$this->deco_kind]['CID_NUM_COL']:3;
 699			$ct = '00'.$count++;
 700			$start  = (strlen($ct)-$col_num) < 0 ? 0:strlen($ct)-$col_num;
 701			$end = strlen($ct)-$start;
 702			$new_cid =  $prefix
 703				. substr($ct,$start,$end)
 704				. $aft;
 705			$content=preg_replace('/<\s*IMG\s+SRC\s*=\s*"cid:'.$attach[$key]['CONTENT-ID'].'"/is','<IMG SRC="cid:'.$new_cid.'"',$content);
 706			$attach[$key]['CONTENT-ID'] = $new_cid;
 707		}
 708		$this->html( $content , null , null , 'utf-8' );
 709		if( 0 < count($attach) ){
 710			$this->attach( $attach );
 711		}
 712		$this->createMail(
 713			$this->deco_def[$this->deco_kind]['BOUNDARY'],
 714			true
 715		);
 716
 717		$header = '';
 718		foreach($this->deco_def[$this->deco_kind]['TOP'] as $line){
 719			$header .= $line .$this->LFC;
 720		}
 721		$header .= 'MIME-Version: 1.0' . $this->LFC
 722			. 'Content-type: ' . key($this->structure[$this->deco_def[$this->deco_kind]['STRUCTURE']])
 723			. '; boundary="'.$this->deco_def[$this->deco_kind]['BOUNDARY'] . '"'
 724			. $this->LFC;
 725		return $header . $this->LFC . $this -> smtpDataBody() . $this->LFC ;
 726	}
 727
 728	//-------------------
 729	// Easy Base
 730	//-------------------
 731	function easy( $type , $to , $subject , $content , $other_header = array() , $attach = null ){
 732		if(is_null($other_header)){
 733			$other_header=array();
 734		}
 735
 736		$this->resetHeaderBody();
 737
 738		$option_return = array();
 739		if( is_array($type) ){
 740			$type = array_change_key_case( $type , CASE_UPPER );
 741			if( isset( $type['SMTP'] ) ){
 742				$this->smtp( true );
 743				$this->smtpServer( $type['SMTP'] );
 744			}
 745			if(isset( $type['OPTION'] )){
 746				$type['OPTION'] = array_change_key_case( $type['OPTION'] , CASE_UPPER );
 747				foreach($type['OPTION'] as $method => $param ){
 748					if(method_exists($this,$method)){
 749						$option_return[$method] = $this->{$method}($param);
 750					}
 751				}
 752			}
 753			$type = isset( $type['TYPE'] ) ? $type['TYPE'] : 'TEXT' ;
 754		}
 755
 756		if( (empty($to) && ( !empty($subject) || !empty($content) ))){
 757			return $this->errorGather('Parameter Specified Error',__LINE__);
 758		}elseif( empty($to) ){
 759			return $option_return;
 760		}
 761
 762		if( 'TEXT' == strtoupper( $type ) || 'HTML' == strtoupper( $type ) ){
 763			$type=strtolower( $type );
 764		}else{
 765			$this->error[]='Illegal spcify \'type\' in '.$type.' .'.__LINE__;
 766			return $this->errorGather();
 767		}
 768		$to = is_string($to) ? array($to) : $to ;
 769		$other_header = is_string($other_header) ? array('From' => $other_header) : $other_header ;
 770
 771		list($other_header_temp , $link ) = $this->keyUpper( $other_header );
 772
 773		if(!isset($other_header_temp['FROM'])){
 774			$fromAddr = null;
 775			if( isset($other_header[0]) ){
 776				$fromAddr = $other_header[0];
 777				unset($other_header[0]);
 778			}
 779			$fromName = null;
 780			if(isset($other_header[1])){
 781				$fromName =  $other_header[1];
 782				unset($other_header[1]);
 783			}
 784			if(!empty($fromAddr)){
 785				$other_header = array_merge( $other_header,array('FROM'=>array( $fromAddr , $fromName )));
 786			}
 787		}
 788
 789		$other_header = array_merge(array('TO'=>$to),$other_header);
 790		$section = array('TO'=>'to','CC'=>'cc','BCC'=>'bcc','REPLY-TO'=>'replyto','FROM'=>'from');
 791		list($other_header_temp , $link ) = $this->keyUpper( $other_header );
 792
 793		foreach($other_header_temp as $key => $other_head){
 794			if(isset($section[$key])){
 795				$method = $section[$key];
 796				$this -> {$method}( $other_head , null );
 797			}else{
 798				$this -> addHeader( $link[$key] ,  $other_head );
 799			}
 800		}
 801
 802		$this->subject( $subject );
 803		$this->{$type}( $content );
 804		if( isset( $attach ) ){
 805			$this->attach( $attach , $add = false , $this->inline_mode );
 806		}
 807
 808		return $this->send();
 809	}
 810
 811	function easyText( $to , $subject , $content , $other_header = array() , $attach = null , $option = array() ){
 812		return $this->easy( array('TYPE'=>'text','OPTION'=>$option) , $to , $subject , $content , $other_header ,  $attach );
 813	}
 814
 815	function easyHtml( $to , $subject , $content , $other_header = array() , $attach = null , $option = array() ){
 816		return $this->easy( array('TYPE'=>'html','OPTION'=>$option) , $to , $subject , $content , $other_header ,  $attach );
 817	}
 818
 819	function easyReplace( $to , $subject , $content , $other_header = array() , $attach = null , $option = array() ){
 820		$this->simpleReplace( true );
 821		$type = 'text';
 822		if(0!==count($option)){
 823			$option = array_change_key_case( $option , CASE_UPPER );
 824			$type = ( 'HTML' === strtoupper( $option['TYPE']) ) ? 'html' : $type ;
 825		}
 826		$this->easy( array('TYPE'=>$type,'OPTION'=>$option) , $to , $subject , $content , $other_header ,  $attach );
 827	}
 828
 829	function easyDeco( $to , $subject , $content , $other_header = array() , $attach = null , $option = array() ){
 830		if( isset( $attach ) ){
 831			$this->inline_mode=true;
 832		}
 833		$this->autoDecoJudge( true );
 834		$this->toSeparate( true );
 835
 836		return $this->easy( array('TYPE'=>'html','OPTION'=>$option) , $to , $subject , $content , $other_header ,  $attach );
 837	}
 838	function easyDecoTemplate( $to , $subject , $template , $other_header = array() , $attach = null , $option = array() ){
 839		if(is_null($attach)){
 840			$attach = array();
 841		}
 842		$DECO = new QdDeco;
 843		$DECO -> template($template);
 844		$DECO -> decode();
 845		$content = $DECO -> get('HTML');
 846		$text = $DECO -> get('PLAIN');
 847		if(!empty($text)){
 848			$this->text($text);
 849		}
 850		$att = $DECO ->get('ATTACH');
 851		$attach = array_merge($att,$attach);
 852		return $this->easyDeco( $to , $subject , $content , $other_header , $attach , $option );
 853	}
 854
 855	function easyDecoRep( $to , $subject , $content , $other_header = array() , $attach = null , $option = array() ){
 856		$this->simpleReplace( true );
 857		return $this->easyDeco($to , $subject , $content , $attach , $option , $option);
 858	}
 859
 860	function easyOption( $to , $subject = null , $content = null , $other_header = array() , $attach = null , $option = array() ){
 861
 862		if(!is_array($to)){
 863			$option = array( $to => $subject );
 864		}else{
 865			$option = $to;
 866		}
 867		return $this->easy( array('TYPE'=>'option','OPTION'=>$option) , $to , $subject , $content , $other_header ,  $attach );
 868	}
 869
 870/*
 871 * Notice: Before use $this->optionNameLink(); by Constractor
 872*/
 873	//
 874	//---------------------------------------
 875	// something change mode
 876	//---------------------------------------
 877	// Keys must lowercase , because of PHP4's
 878	var	$property_type = array(
 879		'auto_both'			=> 'bool' ,
 880		'to_separate'		=> 'bool' ,
 881		'simple_replace'	=> 'bool' ,
 882		'auto_deco_judge'	=> 'bool' ,
 883		'auto_ext'			=> 'bool' ,
 884		'body_empty_allow'	=> 'bool' ,
 885		'ignore_error'		=> 'bool' ,
 886		'wrap_width'		=> 'bool' ,
 887		'wordwrap_allow'	=> 'bool' ,
 888		'wrap_prohibit_allow'=> 'bool' ,
 889		'force_change_charset'	=> 'bool' ,
 890		'error_display'		=> 'bool' ,
 891		'sendmail'			=> 'bool' ,
 892		'smtp'				=> 'bool' ,
 893		'smtp_loglevel_link'=> 'bool' ,
 894		'inline_mode'		=> 'bool' ,
 895		'replace_with_to_priority'=> 'bool' ,
 896		'attach_build_once'	=> 'bool' ,
 897		'body_build_once'	=> 'bool' ,
 898		'kana'				=> 'bool' ,
 899		'render_mode'		=> 'bool' ,
 900		'smime'				=> 'bool' ,
 901		'pgp'				=> 'bool' ,
 902		'simple_attach'		=> 'bool' ,
 903		'message_id'		=> 'bool' ,
 904		'allow_blank_header'=> 'bool' ,
 905		'sign'				=> 'string' ,
 906		'keep_parameter'	=> 'array' ,
 907		'attach_path'		=> 'string' ,
 908		'mta_option'		=> 'string' ,
 909		'rep_prefix'		=> 'string' ,
 910		'log_path'			=> 'string' ,
 911		'errorlog_path'		=> 'string' ,
 912		'log_filename'		=> 'string' ,
 913		'errorlog_filename'	=> 'string' ,
 914		'allways_bcc'		=> 'string' ,
 915		'wrap_prohibit_top'	=> 'string' ,
 916		'wrap_prohibit_end'	=> 'string' ,
 917		'framework'			=> 'string' ,
 918		'priority'			=> 'string' ,
 919		'certificate_file'	=> 'string' ,
 920		'certificate_file_path'	=> 'string' ,
 921		'certificate_temp_path'	=> 'string' ,
 922		'time_zone'			=> 'string' ,
 923		'private_key_file'	=> 'string' ,
 924		'certificate_pass'	=> 'string' ,
 925		'message_id_right'	=> 'string' ,
 926		'sendmail_path'		=> 'string' ,
 927		'temporary_path'	=> 'string' ,
 928		'united_charset'	=> 'string' ,
 929		'varidate_address_regex'=> 'string' ,
 930		'mb_strwidth_magni'	=> 'numeric' ,
 931		'log_dateformat'	=> 'numeric' ,
 932		'log_level'			=> 'numeric' ,
 933		'errorlog_level'	=> 'numeric' ,
 934		'mime_encode_max'	=> 'numeric' ,
 935		'smtp_server'			=> 'array' ,
 936		'address_validation_method'=> 'array',
 937	);
 938	var	$method_property	= array();
 939
 940	function optionNameLink(){
 941		foreach($this->property_type as $prop => $type ){
 942			$method_low = strtolower( str_replace( '_' , '' , $prop ) );
 943			$this->method_property[$method_low] = $prop;
 944		}
 945	}
 946	function option( $option , $line = null , $min = null , $max = null ){
 947		$ret = array();
 948		if( !is_null( $line ) ){
 949			$line = '-' . $line ;
 950		}
 951		if(!is_array($option)){
 952			return $this->errorSpecify( __FUNCTION__, __LINE__ );
 953		}
 954		foreach( $option as $key => $value ){
 955			if( !isset( $this->method_property[strtolower($key)] ) ){
 956				return $this->errorSpecify( __FUNCTION__ . '-' .$key , __LINE__ . $line );
 957			}
 958			$property_name = $this->method_property[strtolower($key)];
 959			if( is_null( $value ) ){
 960				$ret[] = $this->{$property_name} ;
 961				continue ;
 962			}
 963			$err = false;
 964			switch( $this->property_type[$property_name] ){
 965				case 'bool':
 966					if( is_bool( $value ) ){
 967						$this->{$property_name} = $value ;
 968						$ret[0] = true ;
 969					}else{
 970						return $this->errorSpecify( __FUNCTION__ . '-' .$key , __LINE__ . $line );
 971					}
 972				break;
 973				case 'string':
 974					if( '' === $value ){
 975						$this->{$property_name} = null ;
 976						$ret[0] = true ;
 977						break ;
 978					}
 979					if( is_string( $value ) ){
 980						$this->{$property_name} = $value ;
 981						$ret[0] = true ;
 982					}else{
 983						return $this->errorSpecify( __FUNCTION__ . '-' .$key , __LINE__ . $line );
 984					}
 985				break;
 986				case 'numeric':
 987					if( !is_numeric( $value ) || ( isset( $min ) && ( $value < $min ) ) || ( isset( $max ) && ( $value > $max ) ) ){
 988						return $this->errorSpecify( __FUNCTION__ . '-' .$key , __LINE__ . $line );
 989					}else{
 990						$this->{$property_name} = $value ;
 991
 992						$ret[0] = true ;
 993					}
 994				break;
 995				case 'array':
 996					if( !is_array( $value ) ){
 997						$value = array( $value );
 998					}
 999					if( true===$min ){
1000						$this->{$property_name} = array_merge( $this->{$property_name} , $value );
1001					}else{
1002						$this->{$property_name} = $value ;
1003					}
1004					$ret[0] = true ;
1005					if( true === $max ){
1006						$this->{$property_name} = array_change_key_case( $this->{$property_name} , CASE_UPPER );
1007					}
1008				break;
1009
1010				default:
1011					return $this->errorSpecify( __FUNCTION__ . '-' .$key , __LINE__ . $line );
1012				break;
1013			}
1014		}
1015		if( 0 === count( $ret ) ){
1016			return $this->errorSpecify( __FUNCTION__ , __LINE__ );
1017		}elseif( 1 === count( $ret ) ){
1018			return array_shift( $ret );
1019		}else{
1020			return $ret ;
1021		}
1022	}
1023
1024	function autoBoth( $bool = null ){
1025		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1026	}
1027	function toSeparate( $bool = null ){
1028		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1029	}
1030	function simpleReplace( $bool = null ){
1031		$this->toSeparate( $bool );
1032		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1033	}
1034	function autoDecoJudge( $bool = null ){
1035		$this->attachBuildOnce( !$bool );
1036		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1037	}
1038	function autoExt( $bool = null ){
1039		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1040	}
1041	function bodyEmptyAllow( $bool = null ){
1042		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1043	}
1044	function ignoreError( $bool = null ){
1045		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1046	}
1047	function forceChangeCharset( $bool = null ){
1048		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1049	}
1050	function errorDisplay( $bool = null ){
1051		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1052	}
1053	function sendmail( $bool = null ){
1054		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1055	}
1056	function smtp( $bool = null ){
1057		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1058	}
1059	function smtpLoglevelLink( $bool = null ){
1060		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1061	}
1062	function inlineMode( $bool = null ){
1063		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1064	}
1065	function replaceWithToPriority( $bool = null ){
1066		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1067	}
1068	function attachBuildOnce( $bool = null ){
1069		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1070	}
1071	function bodyBuildOnce( $bool = null ){
1072		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1073	}
1074	function kana( $bool = null ){
1075		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1076	}
1077	function keepParameter( $bool = null ){
1078		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1079	}
1080	function renderMode( $bool = null ){
1081		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1082	}
1083	function simpleAttach( $bool = null ){
1084		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1085	}
1086	function messageId( $bool = null ){
1087		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1088	}
1089	function allowBlankHeader( $bool = null ){
1090		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1091	}
1092	function smime( $bool = null ){
1093		$fg = $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1094		if(!extension_loaded ( 'openssl' )){
1095			$this->smime = false;
1096			if(!$bool){
1097				return false;
1098			}
1099		}
1100		return $fg;
1101	}
1102	function pgp( $bool = null ){
1103		// future
1104		return true;
1105	}
1106	function sign( $string = null ){
1107		if(false===$string){
1108			$this->smime = false;
1109			$this->pgp   = false;
1110			$this->sign  = false;
1111			return true;
1112		}
1113		if(empty($string)){
1114			return $this->sign;
1115		}
1116		$string = strtoupper($string);
1117		if('S/MIME'==$string){
1118			$this->smime(true);
1119		}elseif('PGP'==$string){
1120			$this->pgp(true);
1121		}else{
1122			return false;
1123		}
1124		$fg = $this->option( array( __FUNCTION__ => $string ) ,__LINE__);
1125		return $fg;
1126	}
1127	function size( $kind = null ){
1128
1129		if(empty($this->header_for_smtp)){
1130			$stack = $this->render_mode;
1131			$this->render_mode = true;
1132			$fg = $this->send();
1133			$this->render_mode = $stack;
1134		}
1135
1136		$this->size['ALL'] = strlen( bin2hex( $this->header_for_smtp . $this->LFC . $this->content_for_mailfunction )) / 2;
1137		$this->size['HEADER'] = strlen( bin2hex( $this->header_for_smtp )) / 2;
1138		$this->size['BODY'] = strlen( bin2hex( $this->content_for_mailfunction )) / 2;
1139
1140		if(is_null($kind)){
1141			return $this->size;
1142		}
1143		$kind = strtoupper( $kind );
1144		if(isset($this->size[$kind])){
1145			return $this->size[$kind];
1146		}
1147		return false;
1148	}
1149	function sizeAll(){
1150		return $this->size('ALL');
1151	}
1152	function sizeHeader(){
1153		return $this->size('HEADER');
1154	}
1155	function sizeBody(){
1156		return $this->size('BODY');
1157	}
1158	function smtpData(){
1159		if(empty($this->header_for_smtp)){
1160			$stack = $this->render_mode;
1161			$this->render_mode = true;
1162			$fg = $this->send();
1163			$this->render_mode = $stack;
1164		}
1165		return  $this->header_for_smtp . $this->LFC . $this->content_for_mailfunction ;
1166	}
1167	function smtpDataBody(){
1168		if(empty($this->content_for_mailfunction)){
1169			$stack = $this->render_mode;
1170			$this->render_mode = true;
1171			$fg = $this->send();
1172			$this->render_mode = $stack;
1173		}
1174		return  $this->content_for_mailfunction ;
1175	}
1176	function isQmail(){
1177		if(!is_null($this->is_qmail)){
1178			return $this->is_qmail;
1179		}
1180		$this->is_qmail = false;
1181		$ret = ini_get ( 'sendmail_path' );
1182		if(false !== strpos($ret,'qmail')){
1183			$this->is_qmail = true;
1184		}
1185		$sendmail_path = ini_get('sendmail_path');
1186		if(false !== @system($sendmail_path.' -d0.1 < /dev/null > /dev/null',$ret)){
1187			if(is_array($ret)){
1188				$ret = reset($ret);
1189			}
1190			$code = (int) substr($ret,0,3);
1191			if( 100 === $code || 111 === $code){
1192				$this->is_qmail = true;
1193			}
1194		}
1195
1196		return $this->is_qmail ;
1197	}
1198	function lineFeed( $LFC = null ){
1199		if(is_null($LFC)){
1200			return $this->LFC;
1201		}
1202		if(preg_match('/[\r|\n|\r\n]/is',$LFC)){
1203			$this->LFC = $LFC;
1204			return true;
1205		}else{
1206			return false;
1207		}
1208	}
1209	function isWin(){
1210		return false!==strpos(PHP_OS,'WIN');
1211	}
1212	//---------------------------------------
1213	// something change mode
1214	//---------------------------------------
1215	function whichTextHtml( $which ){
1216		$which = strtoupper( $which );
1217		if( 'TEXT' == $which ){
1218			$this->is_html='TEXT';
1219		}elseif( 'HTML' == $which ){
1220			$this->is_html='HTML';
1221		}elseif( 'BOTH' == $which ){
1222			$this->is_html='BOTH';
1223		}
1224	}
1225
1226	function allwaysBcc( $option = null ){
1227		if( is_null( $option ) ){
1228			return $this->allways_bcc ;
1229		}
1230		if( $this->option( array( __FUNCTION__ => $option ) ,__LINE__) ){
1231			$fg = $this->extractAddr( $this->allways_bcc ) ;
1232		 }
1233		if( $this->errorGather() && $fg && !empty($this->allways_bcc) ){
1234			return true ;
1235		}else{
1236			$this->allways_bcc = array();
1237			return false ;
1238		}
1239	}
1240	function priority( $option = null ){
1241		$fg=$this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1242		$priority = strtoupper($option);
1243		if(empty($priority)){
1244			return $fg;
1245		}
1246		$kind = array('HIGH'=>1,'NORMAL'=>1,'LOW'=>1);
1247		if( !isset( $kind[$priority] ) ){
1248			return $this->errorGather('Illegal Priority Name \''.$option.'\'',__LINE__);
1249		}
1250		foreach($this->priority_def as $header_name => $values){
1251			$this->addHeader($header_name,$values[$priority]);
1252		}
1253		return $this->errorGather();
1254	}
1255	function certificatePass( $option = null ){
1256		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1257	}
1258	function certificateFilePath( $option = null ){
1259		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1260	}
1261	function certificateTempPath( $option = null ){
1262		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1263	}
1264	function certificateFile( $option = null ){
1265		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1266	}
1267	function privateKeyFile( $option = null ){
1268		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1269	}
1270	function framework( $option = null ){
1271		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1272	}
1273	function attachPath( $option = null ){
1274		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1275	}
1276	function timeZone( $option = null ){
1277		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1278	}
1279	function messageIdRight( $option = null ){
1280		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1281	}
1282	function mtaOption( $option = null ){
1283		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1284	}
1285	function unitedCharset( $option = null ){
1286		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1287	}
1288	function varidateAddressRegex( $option = null ){
1289		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1290	}
1291	function sendmailPath( $option = null ){
1292		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1293	}
1294	function temporaryPath( $option = null ){
1295		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1296	}
1297	function logPath( $option = null ){
1298		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1299	}
1300	function errorlogPath( $option = null ){
1301		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1302	}
1303	function logDateFormat( $option = null ){
1304		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1305	}
1306	function logFilename( $option = null ){
1307		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1308	}
1309	function errorlogFilename( $option = null ){
1310		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1311	}
1312	function logLevel( $option = null ){
1313		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__, 0 , $this->log_level_max );
1314	}
1315	function errorlogLevel( $option = null ){
1316		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__, 0 , $this->errorlog_level_max );
1317	}
1318	function mimeEncodeMax( $option = null ){
1319		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1320	}
1321	function smtpServer( $array = null ){
1322		return $this->option( array( __FUNCTION__ => $array ) ,__LINE__, true , true );
1323	}
1324	function addressValidationMethod( $array = null ){
1325		return $this->option( array( __FUNCTION__ => $array ) ,__LINE__, false , true );
1326	}
1327	//------------------
1328	//version
1329	//------------------
1330	function version(){
1331		return $this->version;
1332	}
1333	//------------------
1334	//mb_ wrapper
1335	//------------------
1336	function qd_detect_encoding( $word ){
1337		if(!is_null($this->united_charset)){
1338			return $this->united_charset;
1339		}else{
1340			return mb_detect_encoding( $word , mb_detect_order() , true );
1341		}
1342	}
1343	function qd_convert_encoding( $word , $target_chrset , $org_charset = null ){
1344
1345		if(empty($org_charset)){
1346			$org_charset = $this->qd_detect_encoding( $word );
1347		}
1348		if(empty($org_charset)){
1349			return $word;
1350		}
1351		if( strtoupper( $target_chrset ) === strtoupper( $org_charset ) ){
1352			return $word;
1353		}
1354		if('ASCII'===strtoupper( $target_chrset ) || 'ASCII'===strtoupper( $org_charset )){
1355			return $word;
1356		}
1357		return mb_convert_encoding( $word , $target_chrset , $org_charset );
1358	}
1359	function qd_detect_order( $param=null ){
1360		if(is_null($param)){
1361			return mb_detect_order();
1362		}else{
1363			return mb_detect_order( $param );
1364		}
1365	}
1366	//-----------------------------------------
1367	// Address and Name Keys change Opiton
1368	//-----------------------------------------
1369	function addressField( $addr = null , $name = null ){
1370		if( is_null($addr) && is_null($name) ){
1371			return array( $this->tokey['_ADDR'] , $this->tokey['_NAME'] );
1372		}
1373		if( !is_null($addr) && is_array($addr) && 1 < count($addr) ){
1374			$_addr = array_shift( $addr ) ;
1375			$name = array_shift( $addr ) ;
1376			$addr = $_addr;
1377		}
1378		if( (!is_null($addr) && !is_string( $addr )) || !is_null($name) && !is_string($name) ){
1379			return $this->errorGather('Specify Error in addressField',__LINE__);
1380		}
1381		$addr = is_null( $addr ) ? $this->tokey['_ADDR'] : $addr ;
1382		$name = is_null( $name ) ? $this->tokey['_NAME'] : $name ;
1383		$this->tokey = array(
1384			'_ADDR' => $addr,
1385			'_NAME' => $name,
1386		);
1387		return true;
1388	}
1389	//-----------------------------------------------------------
1390	// Wordwrap Opiton
1391	// array( 'except word' => beginning flag )
1392	// if beginning flag is true , beginning of a line is target
1393	// if beginning flag is true , the word in line is target
1394	//-----------------------------------------------------------
1395	function wordwrapProhibitConstruct(){
1396		$ret = $this->strToArrayKey( $this->wrap_prohibit_top , true );
1397		$ret2 = $this->strToArrayKey( $this->wrap_prohibit_end , false );
1398		$this->wrap_prohibit = array_merge( $ret , $ret2 );
1399	}
1400	function strToArrayKey( $word , $value ){
1401		$ret = array();
1402		$enc = $this->qd_detect_encoding( $word );
1403		$length = mb_strlen( $word , $enc );
1404		for( $i=0 ; $i < $length ; $i++ ){
1405			$ret[ mb_substr( $word , $i , 1 , $enc ) ] = $value;
1406		}
1407		return $ret;
1408	}
1409	function wordwrapAllow( $bool = null ){
1410		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1411	}
1412	function wrapProhibitAllow( $bool = null ){
1413		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1414	}
1415	function wrapProhibitEnd( $option = null ){
1416		$this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1417		$this->wordwrapProhibitConstruct();
1418		return  $this->errorGather();
1419	}
1420	function wrapProhibitTop( $option = null ){
1421		$this->option( array( __FUNCTION__ => $option ) ,__LINE__);
1422		$this->wordwrapProhibitConstruct();
1423		return  $this->errorGather();
1424	}
1425	function wrapWidth( $bool = null ){
1426		return $this->option( array( __FUNCTION__ => $bool ) ,__LINE__);
1427	}
1428	function wordwrapLength( $length = null ){
1429		if( is_null( $length ) ){
1430			return $this->wordwrap_length;
1431		}
1432		if( !is_numeric( $length ) || ( is_numeric( $length ) &&  $length < 1 ) ){
1433			return $this->errorGather('Wordwrap error , length is illegal' ,__LINE__) ;
1434		}
1435		$this->wordwrap_length = $length;
1436		return $this->errorGather() ;
1437	}
1438	function mbStrwidthMagni( $option = null ){
1439		return $this->option( array( __FUNCTION__ => $option ) ,__LINE__, 0 , 10 );
1440	}
1441	function wrapExcept( $array = null ){
1442		if( null === $array ){
1443			return $this->wrap_except;
1444		}
1445		if( is_string( $array ) || is_numeric( $array ) ){
1446			$this->wrap_except = array( $array =>false );//default false
1447		}
1448		if( is_array( $array ) ){
1449			if( 0 === count( $array ) ){
1450				$this->wrap_except = array();
1451				return $this->errorGather() ;
1452			}
1453			foreach( $array as $key => $value){
1454				if( !is_bool( $value ) ){
1455					$array[$key] = empty( $value ) ? false:true;
1456				}else{
1457					$array[$key] = $value ;
1458				}
1459			}
1460			$this->wrap_except = $array;
1461			return $this->errorGather() ;
1462		}
1463		return $this->errorSpecify(__FUNCTION__,__LINE__);
1464	}
1465	//------------------------------------------
1466	// Charset Option
1467	//------------------------------------------
1468	function charsetHeader( $charset = null ){
1469		if(is_null($charset)){
1470			return $this->charset_header ;
1471		}
1472		$stack = $this->charset();
1473		$stack['HEADER'] = $charset;
1474		return $this->charset( $stack );
1475	}
1476	function charsetAttach( $charset = null ){
1477		if(is_null($charset)){
1478			return $this->charset_attach_filename ;
1479		}
1480		$stack = $this->charset();
1481		$stack['HEADER'] = $charset;
1482		return $this->charset( $stack );
1483	}
1484	function charsetBody( $charset = null , $enc = null ){
1485		if( is_null($charset) && is_null($enc) ){
1486			return array($this->charset_content , $this->content_transfer_enc_text , content_transfer_enc_html) ;
1487		}
1488		if(is_array($charset)){
1489			$enc = isset($charset[1]) ? $charset[1]:null;
1490			$charset = $charset[0];
1491		}
1492		$stack = $this->charset();
1493		if( !is_null($charset) ){
1494			$stack['BODY'] = $charset;
1495		}
1496		if( !is_null($enc) ){
1497			$stack['HTML'] = $stack['TEXT'] = $enc;
1498		}
1499		return $this->charset( $stack );
1500	}
1501	function charset( $array = null , $op = null ){
1502		if( is_null( $array ) && is_null( $op ) ){
1503			foreach( $this->corres_charset as $key => $value ){
1504				$ret[$key] = $this->{$value} ;
1505			}
1506			return $ret;
1507		}
1508		if( !is_null($op) && is_string($op) ){
1509
1510			$this->content_transfer_enc_text = $op ;
1511			$this->content_transfer_enc_html = $op ;
1512
1513			return $this->charset( $array );
1514		}elseif(!is_null($op) && !is_string($op)){
1515			return $this->errorSpecify( __FUNCTION__ , __LINE__ );
1516		}
1517		if( is_array( $array ) ){
1518			if( 2===count($array) && isset($array[0]) && isset($array[1])){
1519				return $this->charset($array[0],$array[1]);
1520			}
1521			$array = array_change_key_case( $array , CASE_UPPER );
1522			foreach( $array as $key => $value ){
1523				if(isset($this->corres_charset[$key])){
1524					if( is_string($this->corres_charset[$key]) ){
1525						$this->{$this->corres_charset[$key]} = $value;
1526					}else{
1527						return $this->errorSpecify( __FUNCTION__ , __LINE__ );
1528					}
1529				}
1530			}
1531		}elseif( is_string($array) ){
1532			$this->charset_header = $this->charset_content = $this->charset_attach_filename = $array;
1533		}else{
1534			return $this->errorSpecify( __FUNCTION__ , __LINE__ );
1535		}
1536	return $this->errorGather() ;
1537	}
1538	function encoding( $enc = null ){
1539		if(is_null($enc)){
1540			return $this->corres_charset['TEXT'];
1541		}
1542		$this->corres_charset['TEXT'] = $this->corres_charset['HTML'] = $enc;
1543		return true;
1544	}
1545	//--------------------------
1546	// set Mutibye Parameter
1547	//--------------------------
1548	function setMbParameter( $lang = null , $internal_enc = null , $detect = null ){
1549
1550		if(is_array($lang)){
1551			mb_language( $lang[0] ) ;
1552			mb_internal_encoding( $lang[1] ) ;
1553			$this->qd_detect_order( $lang[2] );
1554		}elseif( 'STACK'===strtoupper($lang) ){
1555			$this->mb_parameter_stack = array(mb_language(),mb_internal_encoding(),$this->qd_detect_order());
1556			mb_language( $this->lang_def );
1557			mb_internal_encoding( $this->encoding_def );
1558			$this->qd_detect_order( $this->detect_def );
1559		}else{
1560			if( !is_null( $lang ) ){
1561				mb_language( $lang ) ;
1562			}
1563			if( !is_null( $internal_enc ) ){
1564				mb_internal_encoding( $internal_enc ) ;
1565			}
1566			if( !is_null( $detect ) ){
1567				$this->qd_detect_order( $detect );
1568			}
1569		}
1570	}
1571	//--------------------------------
1572	// Decorationable HTML Mail Opiton
1573	// ( Inline HTML , MHTML )
1574	// See $this->deco_def Property
1575	//--------------------------------
1576	// Change decoration default along to each career
1577	function decoDef( $value = null ){
1578		if( is_null( $value ) ){
1579			return $this->deco_def_default;
1580		}
1581			$this->deco_def_default = $value ;
1582		return $this->errorGather() ;
1583	}
1584	// fix Decoration Pattern by STRING means CareerName
1585	function decoFix( $cari = null ){
1586		if(is_null($cari)){
1587			return $this->deco_kind;
1588		}
1589		$this->deco_kind = $this->decoSelect( $cari );
1590		return true;
1591	}
1592	function decoSelect( $deco_kind = null ){
1593		if( is_null( $deco_kind ) ){
1594			return $this->deco_def_default;//$this->deco_judge
1595		}
1596		$deco_kind = strtoupper( $deco_kind );
1597		$ret = false ;
1598		foreach( $this->deco_def as $key => $def ){
1599			if( in_array( $deco_kind , $def['OPTION_NAME'] ) ){
1600				$ret = $key ;
1601				$this->inline_mode = true;
1602			}
1603		}
1604		return $ret;
1605	}
1606
1607	// Change Decoration Pattern by E-mail Address
1608	function decoJudge( $addr_array ){
1609		$addr=$addr_array[$this->tokey['_ADDR']];
1610		$start = strrpos( $addr , '@');
1611		if(empty($start)){
1612			retu…

Large files files are truncated, but you can click here to view the full file