2

I am parsing MIME formatted emails which have attachments. The attachments have their filenames encoded using RFC2231, so for example the 'content-disposition' of one of the attached files is:

attachment;  filename*=utf-8''Bill%20Sixteen.pdf

How do I go about decoding that filename?

4

2 に答える 2

1

Dukeatcoding で言及されている akelos フレームワークからの特定のメソッドを次に示します。

/**
 * RFC 2231 Implementation
 */
public function _decodeHeaderAttribute($header_attribute, $charset = '')
{
    if(preg_match("/^([A-Z0-9\-]+)(\'[A-Z\-]{2,5}\')?/i",$header_attribute,$match)){
        $charset = $match[1];
        $header_attribute = urldecode(str_replace(array('_','='),array('%20','%'), substr($header_attribute,strlen($match[0]))));
    }
    return Ak::recode($header_attribute, 'UTF-8', $charset);
}

彼らがどのようにそれを行うかを見て、それを使用して独自のデコード関数を作成してください;)

PS akelos フレームワークは LGLP ライセンスを使用していると思います。そのため、自分のプロジェクトでその方法をそのまま使用する場合は注意してください。

于 2012-10-31T11:57:52.717 に答える
1

akelos フレームワークには、調べられるデコード機能があるようです。

アケロス

于 2012-10-29T14:58:35.513 に答える