我正在尝试在我的Mac OS X上为postfix创建一个content_filter,它会改变我机器上的某些外发消息,并保留其他所有内容(读取:标题)。交替是“简单” - 采用现有的顶级multipart/mixed
并使其成为multipart/alternative
;把它作为新multipart/mixed
消息的第一部分;作为第二部分,从原始消息中获取第一个附件。为此,我使用Email::MIME
,并且使用标题并不是一件容易的事。最后,我使用Email::Sender::Simple
使用本地/usr/sbin/sendmail
发送电子邮件。
不幸的是,我收到的邮件是乱码。原始标题有双重换行符,如下所示:
Return-Path: <me@somewhere>
X-Original-To: just_me
Delivered-To: just_me@machine.localhost
Received: by machine.localhost (Postfix, from userid 31415)
id 0FD2A1A4E997; Wed, 5 Feb 2014 21:10:44 +0100 (CET)
From: =?utf-8?Q?Nikola_Kne=C5=BEevi=C4=87?= <me@somewhere>
Message-Id: <20140205201044.0FD2A1A4E997@machine.localhost>
Date: Wed, 5 Feb 2014 21:10:44 +0100 (CET)
Content-Type: multipart/mixed;
boundary="Apple-Mail=_DC7009F8-33E0-4FA7-B0BB-5E30B8371C10"
Mime-Version: 1.0 (Mac OS X com.apple.MailServiceAgent 7.1 \(1827\))
Subject: Event invitation: New Event
X-Mail-Calendar-Part: Yes
X-Smtp-Server: mailer.at.some.company
To: somewhere@else.com
我用来修补新邮件的代码如下:
my $new_email = Email::MIME->create();
$new_email->header_obj_set($email->header_obj);
$new_email->parts_set([
Email::MIME->create(
attributes => {
content_type => 'multipart/alternative',
},
parts => [ @new_email_parts ],
),
$alternate_part,
]);
$email_txt = $new_email->as_string;
这是我用来发送消息的部分($to
和$from
是Email::Address
个对象):
try_to_sendmail(
$email,
{
to => $to->address,
from => $from->address,
}
) or syslog('err', "Problem delivering message to '$to'.");
原始标题是:
Content-Type: multipart/mixed;
boundary="Apple-Mail=_DC7009F8-33E0-4FA7-B0BB-5E30B8371C10"
Mime-Version: 1.0 (Mac OS X com.apple.MailServiceAgent 7.1 \(1827\))
Subject: Event invitation: New Event
X-Mail-Calendar-Part: Yes
X-Smtp-Server: mailer.at.some.company
To: somewhere@else.com
关于我做错了什么的想法,以及我该怎样做才能让它发挥作用?
TIA