将 7 位文本转换为纯文本 perl

发布于 2024-10-07 21:51:23 字数 53 浏览 0 评论 0原文

我解析电子邮件消息,发现编码部分:7bit 如何将这部分的文本转换为纯文本? 我用 Perl

I parsing email message and i found part with encoding: 7bit
how a can convert text of this part to plain text?
i use perl

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

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

发布评论

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

评论(2

捶死心动 2024-10-14 21:51:23
Content-Transfer-Encoding: 7bit

意味着文本已经是纯旧的 ASCII 文本。无需转换。 (好吧,除非 Content-Type 标头指示基于非 ASCII 的字符集,但这种情况非常罕见,尤其是对于 7 位文本。)

Content-Transfer-Encoding: 7bit

means that the text is already plain old ASCII text. No conversion is necessary. (Well, unless the Content-Type header indicates a non-ASCII-based charset, but those are pretty rare, especially with 7bit text.)

倾其所爱 2024-10-14 21:51:23

听起来您有 UU 编码 数据(旧方法)或 MIME 编码。要解决这个问题,您可以使用 Convert::UU MIME::Base64 CPAN 模块。

要使用 MIME::Base64(或其纯 Perl 实现,MIME::Base64::Perl):

use MIME::Base64::Perl;
my $decoded = decode_base64($encoded);

你怎么知道其中的区别?

现代 MIME 编码的文本看起来像这样(特别注意MIME-Version: 标头告诉您它是 MIME 编码的,Content-Transfer-Encoding 标头告诉您编码基础 - 如果它不是 base64,您需要一个不同的 CPAN 模块:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="frontier"

This is a message with multiple parts in MIME format.
--frontier
Content-Type: text/plain

This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

UU 编码文本看起来像这样:

begin 644 cat.txt
#0V%T
`
end

如果编码数据看起来与上述示例不同,请发布确切的格式,以便我们确定它是什么。

It sounds like you have UU-encoded data (older method) or MIME-encoded. To deal with that, you can use Convert::UU and MIME::Base64 CPAN modules respectively.

To use MIME::Base64 (or its pure-Perl implementation, MIME::Base64::Perl):

use MIME::Base64::Perl;
my $decoded = decode_base64($encoded);

How do you know the difference?

The modern MIME encoded text looks like this (Especially pay attention to MIME-Version: header which tells you it's MIME-encoded as well as Content-Transfer-Encoding header which tells you the encoding base - if it's not base64, you need a different CPAN module:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="frontier"

This is a message with multiple parts in MIME format.
--frontier
Content-Type: text/plain

This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

UU-encoded text would look something like:

begin 644 cat.txt
#0V%T
`
end

If the encoded data looks differently than either of the above samples, please post the exact format so we can determine what it is.

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