Question

I want to get emails from imap using Zend_Mail_Storage_Imap. When I get content I can't see polish chars. Mail:

coś tam coś tam

Content using Zend_Mail_Message:

co=B6 tam co=B6 tam

My code:

foreach($imap as $messageNum=>$message) 
{
    if($message->isMultipart())
    {
        $con = array(
            'content_type' => null,
            'encoding' => null,
            'text' => null,
        );

        foreach (new RecursiveIteratorIterator($message) as $part) 
        {
            $con['encoding'] = $part->getHeaderField('content-type', 'charset');

            $content_type = strtok($part->contentType, ';');
            if(!$con['content_type']) 
            {
                $con['content_type'] = $content_type;
                $con['text'] = $part->getContent();
            }
            else
            {
                if($content_type == 'text/html')
                {
                    $con['content_type'] = $content_type;
                    $con['text'] = $part->getContent();
                }
            }
        }
        $content = $con['text'];
        if(strtolower($con['encoding']) != 'utf-8')
            $content = iconv($con['encoding'], 'utf-8', $con['text']);
    }
    else
    {
        var_dump($message->getContent());
    }
}
Was it helpful?

Solution

quoted_printable_decode($string)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top