如何使用 python 的电子邮件类解码位图图像
你好,我有一个 python 脚本,可以将电子邮件从字符串中分离出来。我正在使用电子邮件类中的 get_payload(decode=True) 函数,它对于 pdf 和 jpg 非常有用,但它不能解码 bmp 文件。当我将文件写入磁盘时,该文件仍然采用 base64 编码。
有人自己遇到过这个问题吗?
Hello I have python script that takes apart an email from a string. I am using the get_payload(decode=True) function from the email class and it works great for pdf's and jpg's but it does not decode bmp files. The file is still encoded base64 when I write it to disk.
Has anyone come across this issue themselves?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我终于找到了问题,它与 python 邮件类根本无关。我正在使用 .read() 函数从命名管道中读取数据,但它没有从管道中读取整个电子邮件。我必须向读取函数传递一个大小参数,然后它才能读取整封电子邮件。因此,最终我的 bmp 文件未解码的原因是因为我的 base64 数据无效,导致 get_payload() 函数无法解码附件。
OK so I finally found the problem and it was not related to the python mail class at all. I was reading from a named pipe using the .read() function and it was not reading the entire email from the pipe. I had to pass the read function a size argument and then it was able to read the entire email. So ultimately the reason why my bmp file was not decoded is because I had invalid base64 data causing the get_payload() function to not be able to decode the attatchment.