2

我正在使用 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--

请注意,Content-Type 从text/html; charset=ISO-8859-1原来的变为text/plain; charset="utf-8". 我不知道它为什么会改变。

如何使用回复中包含的原始电子邮件进行回复,以便收件人可以剪切和粘贴其原始回复的文本?

4

1 回答 1

0

您是否考虑过从邮件中删除所有 HTML?你可以试试 https://metacpan.org/pod/HTML::Strip

于 2013-11-27T14:52:39.613 回答