如何防止 TMail 丢弃希伯来语电子邮件的最后一个字母?

发布于 2024-10-07 18:27:33 字数 953 浏览 0 评论 0原文

我正在尝试处理一些包含以 Windows-1255 编码的希伯来语字符的传入电子邮件。

一些示例内容:

From: =?windows-1255...
Subject: =?windows-1255...
...

--Boundary_(ID_/GX/qGlPt4gpL8Dqc2zQQg)
Content-type: text/plain;   charset="windows-1255"
Content-transfer-encoding: quoted-printable
...

主题应该是“שאלה - לאור צדוק”,但实际上是“שאלה - לאור צדו"。即最后一个字符被删除。From名称也是如此。

我发现这个问题在 Iconv 列表中,它描述了相同的问题。最终的结论如下:

In the original code snippet, there's a call to 
    iconv(the_iconv, NULL, NULL, &utf8, &bytes_written);
missing at the end. 

这与 Ruby Iconv 文档(我已经 复制到此 Gist),它强调了在输入末尾添加 nil 的重要性。

我的代码中没有任何地方使用 Iconv 的 Array 或块版本;我总是使用 Iconv.iconv 辅助方法,该方法添加了 nil 。我已经检查了 TMail 源代码,它使用相同的 Iconv.iconv 帮助程序,

有人见过这样的东西吗?

I am trying to process some incoming emails that contain Hebrew characters encoded in Windows-1255.

Some example content:

From: =?windows-1255...
Subject: =?windows-1255...
...

--Boundary_(ID_/GX/qGlPt4gpL8Dqc2zQQg)
Content-type: text/plain;   charset="windows-1255"
Content-transfer-encoding: quoted-printable
...

The subject is supposed to be "שאלה - ליאור צדוק", but is instead "שאלה -
ליאור צדו". That is, the last character is dropped. The same is true of the From name.

I found this issue on the Iconv list, which describes the same issue. The final word is as follows:

In the original code snippet, there's a call to 
    iconv(the_iconv, NULL, NULL, &utf8, &bytes_written);
missing at the end. 

This jives with the Ruby Iconv documentation (which I've copied to this Gist), which emphasizes the importance of adding nil to the end of the input.

Nowhere in my code do I use the Array or block versions of Iconv; I always use the Iconv.iconv helper method, which adds the nil for you. I've checked the TMail source and it uses the same Iconv.iconv helper.

Has anyone seen anything like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2024-10-14 18:27:33

嗯,这实际上比我想象的要容易。我曾尝试将 nil 添加到我的 Iconv.iconv 调用的末尾,但没有成功。我没有尝试过对结果调用 join 。因此,最终的正确结果是

Iconv.iconv(to, from, text_to_transcode, nil).join

Well, that was actually easier than I thought. I had tried adding nil to the ends of my Iconv.iconv calls to no avail. What I hadn't tried was calling join on the result. Thus, the final correct result is

Iconv.iconv(to, from, text_to_transcode, nil).join
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文