我正在使用Perl和模块Mail::Message
编写电子邮件自动回复器。我希望脚本响应发件人,顶部有一些文本,底部是原始发送电子邮件的正文。
对于我的应用程序来说,底部包含的原始电子邮件的文本是可以剪切和粘贴的。
以下是代码:
use Mail::Message;
use Perl6::Slurp;
my $email_text = slurp \*STDIN;
my $mail_message = Mail::Message->read($email_text);
my $reply = $mail_message->reply(
'prelude' => $prelude,
'include' => 'ATTACH',
);
$reply->send();
如果发送的原始电子邮件的正文以纯文本形式发送,则此方法可以正常工作。但是,如果发件人使用HTML撰写邮件,则电子邮件响应包含文字HTML。也就是说,如果发件人发送的电子邮件是“ Hello , world 。”,则发件人会收到一封类似于此内容的电子邮件:
Our Help Desk cannot respond to individual e-mails,
but please file a ticket using our web form at
https://fake.fake/fake.
Your original message is included below:
[Your message is attached]
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<b>Hello</b>, <i>world</i>.<br>
</body>
</html>
这是原始邮件的正文(发送给自动回复者的邮件):
Content-Type: multipart/alternative;
boundary="------------020206020509070600040305"
This is a multi-part message in MIME format.
--------------020206020509070600040305
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
*Hello*, /world/.
--------------020206020509070600040305
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<b>Hello</b>, <i>world</i>.<br>
</body>
</html>
--------------020206020509070600040305--
以下是回复的正文:
--boundary-1381765589
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Our Help Desk cannot respond to individual e-mails,
but please file a ticket using our web form at
https://fake.fake/fake.
[Your message is attached]
--boundary-1381765589
Content-Type: multipart/alternative;
boundary="------------020206020509070600040305"
This is a multi-part message in MIME format.
--------------020206020509070600040305
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
*Hello*, /world/.
--------------020206020509070600040305
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<b>Hello</b>, <i>world</i>.<br>
</body>
</html>
--------------020206020509070600040305--
--boundary-1381765589--
请注意,内容类型已从原始中的text/html; charset=ISO-8859-1
更改为text/plain; charset="utf-8"
。我不知道为什么会改变。
如何回复回复中包含的原始电子邮件,以便收件人可以剪切并粘贴其原始回复的文本?