电子邮件pipe道程序导致Unicode字符的问题?

我将传入的邮件传送到PHP脚本中,立即将RAW电子邮件存储在MySQL数据库中。 它工作得很好,除了约0.7%的电子邮件到达与截断的邮件正文。

我发现有人的电子邮件失败,并让他们发送电子邮件到我的Gmail帐户和服务器。 Gmail没有问题,我看到了整个消息。 但是我的服务器像这样裁剪了原始信息:

Delivered-To: [email protected] Received: by 10.152.1.193 with SMTP id 1csp3490lao; Mon, 20 Oct 2014 05:33:31 -0700 (PDT) Return-Path: <[email protected]> Received: from vps123.blahblah.com (vps123.blahblah.com. [74.124.111.111]) by mx.google.com with ESMTPS id fb7si7786786pab.30.2014.10.20.05.33.30 for <[email protected]> (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 20 Oct 2014 05:33:30 -0700 (PDT) Message-ID: <14FBD481E1074C79AF3D@acerDator> From: =?utf-8?Q?sende=C3=A4r?= <[email protected]> To: "test" <[email protected]> References: <[email protected]> Subject: Message body will contain only Det h Date: Mon, 20 Oct 2014 14:33:24 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0018_01CFEC72.CE424470" X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 14.0.8117.416 X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8117.416 X-Source: X-Source-Args: X-Source-Dir: Det här är ett flerdelat meddelande i MIME-format. ------=_NextPart_000_0018_01CFEC72.CE424470 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This email will not be received correctly. EXIM may not handle = some poorly formed emails. For example ... Det h=E4r =E4r ett flerdelat meddelande i MIME-format. ... is directly above this quoted-printable wrapper, thanks to the = Swedish email client Microsoft Windows Live (circa 2009), adding UTF-8 = chars where there should only be ascii. At least, that's what I think = the problem is. ------=_NextPart_000_0018_01CFEC72.CE424470-- 

我的服务器在第一个外来字符之前立即裁剪消息。 存储的原始数据包含标题,一个空白行“Det h”,没有别的。

当我将上述电子邮件input到shell中的PHP脚本( /blah/email_in.php < bademail.txt )中时,它将完美地存储消息。 所以我不认为我的脚本有问题,它正确存储原始STDIN。

我用cPanel“设置默认地址”为“Pipe to a program”。 我不知道这个设置是否完全绕过了EXIM,但是我在某处读到EXIM处理pipe道传输的信息,所以我的第一个猜测是EXIM正在修改一个格式不正确的消息,并且在第一个Unicode字符Ä处阻塞了这个stream。

为了证实这一点,我需要一种方法来pipe理电子邮件INTO EXIM,基本上欺骗EXIM认为它刚刚收到一封电子邮件时,实际上它只是收到一个TXT文件。 我已经find了几个关于如何telnet到端口25等的教程,但是没有任何东西可以保存头文件,多重边界,对于像我这样依赖于cPanel的unix n00b来说也没有意义。

我认为EXIM是可能的罪魁祸首吗?
任何人都可以提出一个方法来testing这个,或者一个替代方法?

我的服务器在CentOS 6.5上运行EXIM + Dovecot。

PS我唯一的想法是让服务器正常存储邮件,如果这些邮件正确保存,使用IMAP检索/删除邮件,而不是直接进入pipe道…似乎效率不高,添加IMAP中间人,尽pipe这种方法可能更强大。

你可能想尝试swaks :

  swaks --to [email protected] --server your-server.example.net -d your_mail_with_headers.txt 

当然,其中your_mail_with_headers.txt是包含您的原始消息(标题,正文,MIME等)的文件。

然而,我不认为应该是这个问题(事情通常是通过pipe道而不是修改的,甚至是二进制string)。 它更可能是你的脚本在shell和pipe道上的行为不同(例如,由于LANGLC_ALL环境variables等)