MTA
[ class tree: MTA ] [ index: MTA ] [ all elements ]

Source for file MTA.php

Documentation is available at MTA.php

  1. <?php
  2. /**
  3.  * Project: pear Mail Transfer Agent(MTA)<br />
  4.  * File:    MTA.php<br />
  5.  * Dependency: {@link https://github.com/OOPS-ORG-PHP/myException myException}
  6.  *
  7.  * MTA는 php mail function을 대체할 수 있으며, smtp server나
  8.  * smtp daemon이 없더라도 자체적으로 메일을 발송할 수 있는 기능을
  9.  * 제공한다.
  10.  *
  11.  * 또한 alternative/mixed 방식의 mail body를 생성하는 method를 제
  12.  * 공하며, 발송 시 중복된 메일 주소를 압축하여 중복된 메일 서버에
  13.  * 여러번 접근하지 않도록 최적화 되어 있다.
  14.  *
  15.  * 예제:
  16.  * {@example MTA/tests/test.php}
  17.  *
  18.  * @category   Networking
  19.  * @package    MTA
  20.  * @author     JoungKyun.Kim <http://oops.org>
  21.  * @copyright  (c) 2018, OOPS.org
  22.  * @license    BSD License
  23.  * @link       http://pear.oops.org/package/MTA
  24.  * @filesource
  25.  */
  26.  
  27. /**
  28.  * import myException class
  29.  *
  30.  * MTA API는 pear.oops.org/myException pear pacage에
  31.  * 의존성이 있다.
  32.  */
  33. require_once 'myException.php';
  34.  
  35. /**
  36.  * import MTA_Generate class
  37.  */
  38. require_once 'MTA/MTA_Generate.php';
  39.  
  40. /**
  41.  * MTA 없이 메일을 발송하기 위한 API
  42.  *
  43.  * 예제:
  44.  * {@example MTA/tests/test.php}
  45.  *
  46.  * @package MTA
  47.  */
  48. Class MTA extends MTA_Generate {
  49.     // {{{ properties
  50.     /**#@+
  51.      * @access public
  52.      */
  53.     /**
  54.      * 입력한 문자셋
  55.      * @var string 
  56.      */
  57.     public $charset = 'utf-8';
  58.     /**
  59.      * send method 실행시 debug message 출력
  60.      * @var boolean 
  61.      */
  62.     public $verbose = false;
  63.     /**
  64.      * Mail agent 값. 기본값은 oops\MTA 이다.
  65.      * @var string 
  66.      */
  67.     public $magent = 'oops\MTA';
  68.     /**#@-*/
  69.     /**
  70.      * 내부적으로 사용할 socket descriptor
  71.      * @access protected
  72.      * @var resource 
  73.      */
  74.     protected $sock = null;
  75.     // }}}
  76.  
  77.     // {{{ (void) MTA::__construct
  78.     /**
  79.      * MTA class 초기화
  80.      */
  81.     function __construct ({}
  82.     // }}}
  83.  
  84.     // {{{ (object) public  MTA::send ($o)
  85.     /**
  86.      * 메일 발송
  87.      *
  88.      * 예제:
  89.      * {@example MTA/tests/test.php 22 28}
  90.      *
  91.      * @access public
  92.      * @return stdClass 발송 결과를 object로 반환한다.
  93.      *
  94.      *    <pre>
  95.      *    stdClass Object
  96.      *    (
  97.      *        [status]  => (bool) 성공 실패 여부
  98.      *        [error]   => (string) status false시 에러 메시지
  99.      *        [rcptlog] => (array) rcpt to에 대한 log
  100.      *    )
  101.      *    </pre>
  102.      *
  103.      *    RCPT list별로 확인을 위해서 status가 true이더라도 rcptlog를
  104.      *    확인하는 것이 필요
  105.      *
  106.      * @param  stdClass $o mail object
  107.      *    <pre>
  108.      *    stdClass Object
  109.      *    (
  110.      *        [rpath]  => (string) return path (optional)
  111.      *        [from]   => (string) Sender address
  112.      *        [to]     => (array) Reciever address
  113.      *        [cc]     => (array) See also reciever address
  114.      *        [bcc]    => (array) Hidden see also reciever address
  115.      *        [subjet] => (string) mail subject
  116.      *        [body]   => (string) mail contents
  117.      *        [pbody]  => (string) planin/text mail contents (optional)
  118.      *        [attach] => (array) attached files (optional)
  119.      *    )
  120.      *    </pre>
  121.      */
  122.     public function send ($o{
  123.         $template $this->source ($o);
  124.         $r $this->socket_send ($o$template);
  125.  
  126.         return $r;
  127.     }
  128.     // }}}
  129.  
  130.     // {{{ (string) public MTA::source ($v)
  131.     /**
  132.      * 주어진 정보를 이용하여 raw mail body를 alternative/mixed
  133.      * 형식으로 반환
  134.      *
  135.      * 예제:
  136.      * {@example MTA/tests/test.php 22 22}
  137.      *
  138.      * @access public
  139.      * @return string If occur error, throw excption
  140.      * @param  stdClass $v mail object
  141.      *    <pre>
  142.      *    stdClass Object
  143.      *    (
  144.      *        [from]   => (string) Sender address
  145.      *        [to]     => (array) Reciever address
  146.      *        [cc]     => (array) See also reciever address (optional)
  147.      *        [bcc]    => (array) Hidden see also reciever address (optional)
  148.      *        [subjet] => (string) mail subject
  149.      *        [body]   => (string) mail contents
  150.      *        [pbody]  => (string) planin/text mail contents (optional)
  151.      *        [attach] => (array) attached files (optional)
  152.      *    )
  153.      *    </pre>
  154.      */
  155.     public function source ($v{
  156.         $template file_get_contents ('MTA/template.txt'true);
  157.  
  158.         $o new stdClass;
  159.         foreach $v as $key => $val {
  160.             if $key == 'attach' {
  161.                 $o->attach $val;
  162.                 continue;
  163.             }
  164.  
  165.             if preg_match ('/^utf[-]?8$/i'$this->charset) )
  166.                 $o->$key iconv ($this->charset'utf-8'$val);
  167.             else
  168.                 $o->$key $val;
  169.         }
  170.  
  171.         $this->addr ($o->from);
  172.         if is_array ($o->to|| is_object ($o->to) ) {
  173.             foreach $o->to as $val {
  174.                 $this->addr ($val);
  175.                 $to .= $val ', ';
  176.             }
  177.             $o->to preg_replace ('/\,[\s]*$/'''$to);
  178.             unset ($to);
  179.         else
  180.             $this->addr ($o->to);
  181.  
  182.         if $o->cc {
  183.             if is_array ($o->cc|| is_object ($o->cc) ) {
  184.                 foreach $o->cc as $val {
  185.                     $this->addr ($val);
  186.                     $cc .= $val ', ';
  187.                 }
  188.                 $o->cc preg_replace ('/\,[\s]*$/'''$cc);
  189.                 unset ($cc);
  190.             else
  191.                 $this->addr ($o->cc);
  192.  
  193.             $o->cc 'CC: ' $o->cc "\r\n";
  194.         }
  195.  
  196.         if $o->bcc {
  197.             if is_array ($o->bcc|| is_object ($o->bcc) ) {
  198.                 foreach $o->bcc as $val {
  199.                     $this->addr ($val', ';
  200.                     $bcc .= $val ', ';
  201.                 }
  202.                 $o->bcc preg_replace ('/\,[\s]*$/'''$bcc);
  203.                 unset ($bcc);
  204.             else
  205.                 $this->addr ($o->bcc);
  206.  
  207.             $o->bcc 'BCC: ' $o->bcc "\r\n";
  208.         }
  209.  
  210.         if $o->pbody )
  211.             $o->pbody strip_tags ($o->body);
  212.  
  213.         $o->date $this->date ();
  214.         $o->msgid $this->msgid ();
  215.         $o->subject $this->encode ($o->subject);
  216.         $o->boundary $this->boundary ();
  217.         $o->subboundary $this->boundary ();
  218.  
  219.         $o->body $this->encode ($o->bodytrue);
  220.         $o->pbody $this->encode ($o->pbodytrue);
  221.  
  222.         $attaches $this->attach ($o->attach$o->boundary);
  223.  
  224.         $src array (
  225.             '/@MESSAGE_ID@/''/@DATE@/''/@FROM@/''/@TO@/''/@CC@/',
  226.             '/@BCC@/''/@SUBJECT@/''/@BOUNDARY@/''/@SUB_BOUNDARY@/',
  227.             '/@PLAINBODY@/''/@BODY@/''/@ATTCHED@/''/@MAIL_AGENT@/',
  228.         );
  229.         $dst array (
  230.             $o->msgid$o->date$o->from$o->to,
  231.             $o->cc$o->bcc$o->subject$o->boundary,
  232.             $o->subboundary$o->pbody$o->body$attaches,
  233.             $this->magent
  234.         );
  235.  
  236.         return preg_replace ($src$dst$template);
  237.     }
  238.     // }}}
  239. }
  240.  
  241. /*
  242.  * Local variables:
  243.  * tab-width: 4
  244.  * c-basic-offset: 4
  245.  * End:
  246.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  247.  * vim600: noet sw=4 ts=4 fdm=marker
  248.  * vim<600: noet sw=4 ts=4
  249.  */
  250. ?>

Documentation generated on Tue, 14 May 2019 02:00:33 +0900 by phpDocumentor 1.4.4