MIME::Entity 标头编码正确吗?
我使用 Perl 中的 MIME::Entity 模块来创建 MIME 消息。一些标头似乎编码正常,而其他标头似乎存在折叠问题。
代码:
use strict;
use Encode;
use MIME::Entity;
my %build_params = (
'Charset' => 'UTF-8',
'From' => encode('MIME-Header', 'Fantasy Email <[email protected]>'),
'Subject' => encode('MIME-Header', "A very long subject that will span on multiple lines in the headers, with a leading sp\
ace at the beginning of each new line."),
'Type' => 'multipart/alternative',
);
my $top = MIME::Entity->build(%build_params);
$top->print_header();
输出:
Content-Type: multipart/alternative;
boundary="----------=_1312196104-11708-0";
charset="UTF-8"
Content-Transfer-Encoding: binary
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Subject: A very long subject that will span on multiple lines in the
headers, with a leading space at the beginning of each new line.
From: Fantasy Email
<vujerldujhgurtelhwgutrwhgunwlhvulhgvnuwlhvuwlnhvgnulwh@gmail .com>
Subject
似乎被正确地分成多行。 From
没有,在 com
之前留了一个空格,但换行符消失了。
这是标准行为还是我在 MIME::Entity 中发现了错误?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Encode::MIME::Header(称为
encode('MIME-Header', ...)
)会进行一些行分割(在 RFC 822)。不幸的是,MIME::Entity 也进行了一些行分割,可能是以不同的方式。它还消除了 Encode::MIME::Header 生成的换行符。但它留下了空间。
我很乐意让 MIME::Entity 处理我的标头的编码,但看起来它只是执行行分割部分。所以我想我还是得自己编码。
作为解决方法,我从编码的标头中删除了行分割标记
(对于主题也是如此。)
现在输出如下所示:
我想知道是否有更优雅的解决方案,例如 Encode::MIME::Header具有 MIME::Entity 兼容模式或类似模式。
Encode::MIME::Header (called as
encode('MIME-Header', ...)
) does some line splitting (called folding in the RFC 822).Unfortunately, MIME::Entity does some line splitting too, probably in a different way. It also gets rid of the newline generated by Encode::MIME::Header. It leaves the spaces though.
I would be happy to leave MIME::Entity deal with the encoding of my headers, but it looks like it just does the line splitting part. So I guess I still have to encode them myself.
As a workaround, I removed the line splitting markers from my encoded headers with
(And same thing for the subject.)
Now the output looks like this:
I'm wondering if there's a more elegant solution, like Encode::MIME::Header featuring a MIME::Entity compatibility mode or something like that.