【发布时间】:2012-10-14 13:12:29
【问题描述】:
我正在编写一个工具,该工具能够通过 python 中的 IMAP 备份和恢复 Gmail 中的电子邮件。 在某些情况下,从 Gmail 备份的电子邮件包含奇怪的字符:^@,然后 Gmail IMAP 无法重新提取这些字符。
Delivered-To: xxxxx@lxxxxxx
Received: by 1x.xx.xx.xx with SMTP id jjjjjjjj;
Tue, 14 Jun 2011 16:56:26 -0700 (PDT)
Received: by x.x.x.x with SMTP id xxxx.xxx;
Tue, 14 Jun 2011 16:56:16 -0700 (PDT)
Return-Path: <foo.bar@email.com>
Delivery-Date: Mon, 23 Aug 2010 17:58:56 +0200
Received: from xxxxx (xxxxx [x.x.x.x])
by xxxx (node=xxx) with ESMTP (xxx)
id xxx ; Mon, 23 Aug 2010 17:58:56 +0200
Received: from [x] (x)
by x (x) with x (x)
id x; Mon, 23 Aug 2010 17:58:50 +0200
Message-ID: <x@foo.com>
Date: Mon, 23 Aug 2010 17:58:48 +0200
From: Foo Bar <foo.bar@email.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2
MIME-Version: 1.0
To: bar.foo@email.com <x>
Subject: The subject
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
X-Provags-ID: xxxxxxxxxxx=
Envelope-To: foo.bar@email.com
Hello All,
blah blah blah
^@
最后他们是这个特殊字符。有时它会出现在中间的其他电子邮件中。 当我将电子邮件存储在磁盘上(eml 格式)时,我只是保存并恢复它。
编码似乎正确。
这个角色是什么? 当我将电子邮件存储在 eml 中时,我做错了什么吗?
如果能提供一些指导,将不胜感激。
谢谢。
【问题讨论】:
-
^@是一个空字符。不知道它是如何到达那里的。你能粘贴你的代码吗?参考:robelle.com/smugbook/ascii.html -
邮箱是 8bit,
Content-Transfer-Encoding: 8bit。并非所有系统/软件都能处理 8 位邮件。正如@ZnArK 所说,^@是 NULL 的常见表示。 -
我认为它是在最初创建电子邮件时插入的。然后 Gmail Imap 不想接受它。我有一个问题。上面有 IMAP 通信和 SSL。您认为 SSL 层可以添加它吗?代码非常简单,我通过 python imaplib 收到电子邮件并将其保存在文件中。该文件以“wb”打开。如果您有任何想法,请告诉我。谢谢
标签: python email character-encoding imap