为什么邮件消息不正确解码? [英] Why doesn't this mail message decode correctly?

查看:158
本文介绍了为什么邮件消息不正确解码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码。来自 Zend阅读邮件示例。

  $ message = $ mail-> getMessage(1); 

//输出第一个文本/简单部分
$ foundPart = null;
foreach(new RecursiveIteratorIterator($ mail-> getMessage(1))as $ part){
try {
if(strtok($ part-> contentType,';')= ='text / plain'){
$ foundPart = $ part;
break;
}
} catch(Zend_Mail_Exception $ e){
//忽略
}
}
如果(!$ foundPart){
echo 没有明文部分找到;
} else {
echo $ foundPart-> getContent();
}

我可以得到的是消息,工作正常。但尝试将消息解码成可读的内容不起作用。我已经尝试过Zend_Mime,imap_mime和iconv,没有运气。



这是一个例子,我用 $ foundPart-> getContent() ;


Hall = F3 heim = FAr


应该说Hallóheimúr



我想要的只是一些图书馆,我可以按钮,接受培根实践。 X- 200454545 X- 20045 X- 20045 X-454545新新新新新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新旗新旗新旗新旗新新旗新新旗新新旗新新旗新新旗新旗新旗新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新旗新旗新新旗新旗新旗新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新旗新旗新旗新新旗新旗新旗新旗新新旗新新旗新新旗新新旗新新旗新新旗新新code> imap_mime_header_decode()给我一个具有相同数据的数组。

iconv_ mime_ decode() 200新新新新旗新新旗旗新新新新旗新新旗旗新新新新旗新新旗旗新新旗新新旗旗新新旗新新旗200新新新旗新新旗旗新200新新新旗新新旗200新新新新旗新新旗2001-新新新新旗新新旗2001-新新新新旗新新旗新200新新旗新新旗新新旗新新旗新新旗新旗旗目旗新新新旗新旗新新旗新新旗新新旗新旗新新旗新新旗新新旗新旗新旗新旗新新旗新新旗新新旗新旗新新旗新新旗新旗新旗新旗新新新新旗新新旗新旗新旗新旗新新旗新新旗新新旗新旗新旗新旗新新旗新新旗新新旗新旗新旗新旗新新旗新新旗新b

解决方案

这可能是因为base64编码。 Zend_Mail文件说(在'encoding'下):


...所有其他附件都通过base64编码
,如果没有其他附件编码为
,在addAttachment()调用或
中分配给MIME部分对象




X- 20045454545 X- 20045 X-454545 X- 20045 X-454545 X-454545 X- 20045 X-454545 X- 20045 X-454545 X- 20045 X-454545 X- 20045 X-454545 X-新新p新新新新旗新新新新旗新旗旗新新新旗新新旗旗新1992新新新新旗新新旗新新旗新新旗200新新新新旗新新旗200新新新新旗新新旗新200新新旗新新旗20045新新新旗新新旗新新旗新旗新新旗新新旗新旗新新旗新新旗新新旗新新旗新新旗新旗新新旗新新旗新新旗新新旗新旗新com / manual / en / zend.mail.encoding.htmlrel =nofollow noreferrer> http://framework.zend.com/manual/en/zend.mail.encoding.html



希望有所帮助。


I have this code. It's from the Zend Reading Mail example.

$message = $mail->getMessage(1);

// output first text/plain part
$foundPart = null;
foreach (new RecursiveIteratorIterator($mail->getMessage(1)) as $part) {
    try {
        if (strtok($part->contentType, ';') == 'text/plain') {
            $foundPart = $part;
            break;
        }
    } catch (Zend_Mail_Exception $e) {
        // ignore
    }
}
if (!$foundPart) {
    echo 'no plain text part found';
} else {
    echo $foundPart->getContent();
}

What I can get is the message, that works fine. But trying to decode the message into something readable does not work. I have tried Zend_Mime, imap_mime and iconv with no luck.

This is an example of what I get with $foundPart->getContent();

Hall=F3 heim=FAr

It should say "Halló heimúr"

What I would want is just some library where i could "push button, receive bacon" in practice. What I mean is, I just want to point the library to a POP3 email box and get the email in readable form (without any encoding issues) and the attachments.

imap_mime_header_decode() Gives me an array with the same data.
iconv_ mime_ decode() Does the same

Does anyone have any idea why this is happening or some library where I can just abstract this away (PHP/Python or Perl)

解决方案

This could be because of base64 encoding. The Zend_Mail docs say (under 'encoding'):

...All other attachments are encoded via base64 if no other encoding is given in the addAttachment() call or assigned to the MIME part object later.

Try something like:

echo base64_decode($foundPart->getContent());

Also, read: http://framework.zend.com/manual/en/zend.mail.encoding.html

Hope that helped somehow.

这篇关于为什么邮件消息不正确解码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆