需要帮助解析mime subject perl

时间:2013-07-24 00:35:47

标签: perl mime

我设法从gmail收到电子邮件,其主题包含UTF-8字符,

Subject: =?utf-8?B?5L2g5aW9IOS9oOWlvQ==?=

我搜索了互联网,发现它的编码引用可打印

我尝试使用显示的代码来解码主题

use MIME::QuotedPrint;

print decode_qp("?utf-8?B?5L2g5aW9IOS9oOWlvQ==?=");

但它会打印相同的消息,我也尝试删除?utf-8?但没有用,所以可以帮助我将上述主题转换为utf-8字符而不是上面的编码

2 个答案:

答案 0 :(得分:2)

使用Encode::MIME::Header模块,如

$ perl -MEncode -le 'print Encode::encode("utf8", \
  Encode::decode("MIME-Header", "=?utf-8?B?5L2g5aW9IOS9oOWlvQ==?="))'
你好 你好

#! /usr/bin/env perl

use v5.10.0;
use strict;
use warnings;

use Encode qw/ decode /;

my $subject = "=?utf-8?B?5L2g5aW9IOS9oOWlvQ==?=";

binmode STDOUT, ":encoding(UTF-8)";
say decode "MIME-Header", $subject;

答案 1 :(得分:1)

使用MIME::Base64,从头开始删除?utf-8?B?,从结尾删除?=

use MIME::Base64;
print decode_base64('5L2g5aW9IOS9oOWlvQ=='), "\n";