Mail :: Header - 无法让它向我显示标题

时间:2016-07-22 09:28:02

标签: perl

我试图找出如何使用 Perl模块

http://search.cpan.org/~markov/MailTools-2.18/lib/Mail/Header.pod

我尝试了几种方法:

my $fh = open (READIT, "./test.eml");

use Mail::Header;
my $head = Mail::Header->new();
   $head->read($fh);

print Dumper($head);

尽管如此,打印出一些空值:

$VAR1 = bless( {
                 'mail_hdr_foldlen' => 79,
                 'mail_hdr_modify' => 0,
                 'mail_hdr_list' => [],
                 'mail_hdr_hash' => {},
                 'mail_hdr_mail_from' => 'KEEP',
                 'mail_hdr_lengths' => {}
               }, 'Mail::Header' );

我还在 $ message 中使用电子邮件作为字符串进行了尝试:

my $head = Mail::Header->new( $message );

同样的问题。

我对自己做错了什么感到有些困惑。有人可以建议尝试一下吗?

1 个答案:

答案 0 :(得分:1)

问题是您已使用READIT句柄打开了.eml文件,但是您正在从文件句柄$fh中读取以填充Mail::Header对象。您还将收到警告消息

  

名称“main :: READIT”仅使用一次:可能错字

  

名称“main :: fh”仅使用一次:可能的拼写错误

你真的应该报道

这个程序运行正常

use strict;
use warnings 'all';

use Mail::Header;

open my $fh, '<', 'Support Account Password Assistance.eml' or die $!;
my $head = Mail::Header->new($fh);
print $head->as_string;

与此文件一起用于输入

simple.eml

From: example@example.com
To: example2@example.com
Subject: As basic as it gets

This is the plain text body of the message.  Note the blank line
between the header information and the body of the message.

它会生成此输出

输出

From: example@example.com
To: example2@example.com
Subject: As basic as it gets