久しぶりにMail_mimeDecodeを使ってみたのですが、decodeメソッドの返り値がstdClassだったので、Eclipseなどで返り値のクラスを定義して入力補完ができるようにしてみました。
コードはこちら。
gist: 217586 – GitHub
mimeDecodeStructure.phpを以下のような、内容で作成して
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
class Mail_mimeDecodeStructure { /** * Headers * @var array */ public $headers = array(); /** * Content-Type (primary) * * @var string */ public $ctype_primary; /** * Content-Type (secondary) * @var string */ public $ctype_secondary; /** * * @var array */ public $ctype_parameters = array(); /** * Content-disposition * @var string */ public $disposition; /** * * @var array */ public $d_parameters = array(); /** * * @var string */ public $body; /** * * @var array */ public $parts = array(); } // End of class |
mimeDecode.phpの以下の部分を書き換え。
(メソッドの戻り値をMail_mimeDecodeStructure)にする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
*** vendors/PEAR/Mail/mimeDecode.php 2009-10-25 01:02:47.000000000 +0900 --- vendors/PEAR/Mail/mimeDecode.new.php 2009-10-24 23:55:25.000000000 +0900 *************** class Mail_mimeDecode extends PEAR *** 181,187 **** * decode_headers - Whether to decode headers * input - If called statically, this will be treated * as the input ! * @return object Decoded results * @access public */ function decode($params = null) --- 181,187 ---- * decode_headers - Whether to decode headers * input - If called statically, this will be treated * as the input ! * @return Mail_mimeDecodeStructure * @access public */ function decode($params = null) *************** class Mail_mimeDecode extends PEAR *** 225,236 **** * * @param string Header section * @param string Body section ! * @return object Results of decoding process * @access private */ function _decode($headers, $body, $default_ctype = 'text/plain') { ! $return = new stdClass; $return->headers = array(); $headers = $this->_parseHeaders($headers); --- 225,237 ---- * * @param string Header section * @param string Body section ! * @return Mail_mimeDecodeStructure * @access private */ function _decode($headers, $body, $default_ctype = 'text/plain') { ! require_once('Mail/mimeDecodeStructure.php'); ! $return = new Mail_mimeDecodeStructure(); $return->headers = array(); $headers = $this->_parseHeaders($headers); |
これでMail_mimeDecodeを以下のような形で使えば、$structure->h まで入力すれば $structure->headers に補完されます。
1 2 |
$mimeDecode = new Mail_mimeDecode($email); $structure = $mimeDecode->decode($params); |
しかし、Mail_mimeDecodeってしばらくメンテナンスされてないんですね。。