How to get the charset from a Zend_Mail_Part object?
I am trying to determine the character set of a Zend_Mail_Part
object (I am reading email). How can I get the charset
information?
I can get the content-type header by doing this:开发者_如何转开发
echo $part->contentType;
# text/plain; charset="iso-8859-1"
I am willing to parse out the charset
information if that is the only way. Just trying to look for the cleanest solution.
You can use Zend_Mail_Part::getHeaderField:
$part->getHeaderField('content-type', 'charset');
http://framework.zend.com/apidoc/1.11/_Mail_Part.html#Zend_Mail_Part::getHeaderField()
The only way that I could figure out how to find the charset
is by using a regular expression:
preg_match('/charset="(.+)"$/', $foundPart->contentType, $matches);
$charset = $matches[1];
if ($charset == 'iso-8859-1') {
$content = utf8_encode($content);
}
精彩评论