久しぶりにMail_mimeDecodeを使ってみたのですが、decodeメソッドの返り値がstdClassだったので、Eclipseなどで返り値のクラスを定義して入力補完ができるようにしてみました。
コードはこちら。 gist: 217586 - GitHub
mimeDecodeStructure.phpを以下のような、内容で作成して
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)にする。
*** 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 に補完されます。
$mimeDecode = new Mail_mimeDecode($email);
$structure = $mimeDecode->decode($params);
しかし、Mail_mimeDecodeってしばらくメンテナンスされてないんですね。。