PageRenderTime 72ms CodeModel.GetById 32ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0

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

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