Arrays Perl如何将电子邮件正文一次一行地推送到数组中
您好,我有一个脚本,可以从outlook文件夹中获取带有特定主题行的电子邮件正文。我想做的下一件事,就是使用正则表达式只保留以某些单词开头的行。 如果我将电子邮件正文保存到一个文件句柄中,然后重新打开它,我可以实现这一点,但它看起来很凌乱。 如果我尝试将电子邮件正文推送到一个数组,它将仅作为一行加载, 所以正则表达式不起作用! 我的问题是,如何将电子邮件逐行推送到数组中 这是一个有效的代码示例Arrays Perl如何将电子邮件正文一次一行地推送到数组中,arrays,perl,Arrays,Perl,您好,我有一个脚本,可以从outlook文件夹中获取带有特定主题行的电子邮件正文。我想做的下一件事,就是使用正则表达式只保留以某些单词开头的行。 如果我将电子邮件正文保存到一个文件句柄中,然后重新打开它,我可以实现这一点,但它看起来很凌乱。 如果我尝试将电子邮件正文推送到一个数组,它将仅作为一行加载, 所以正则表达式不起作用! 我的问题是,如何将电子邮件逐行推送到数组中 这是一个有效的代码示例 #!/usr/bin/perl use strict; use warnings; #
#!/usr/bin/perl
use strict;
use warnings;
#use diagnostics;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
my $in = "C:\\Temp\\Qmail.txt";
open( my $ifh, "+>", $in ) or die "$in";
my $outlook = Win32::OLE->new('Outlook.Application')
or warn "Failed Opening Outlook.";
my $namespace = $outlook->GetNamespace("MAPI");
my $folder = $namespace->Folders("test")->Folders("Inbox");
my $items = $folder->Items;
foreach my $msg ( $items->in ) {
if ( $msg->{Subject} =~ m/^(.*test alert) / ) {
my $name = $1;
print " processing Email for $name \n";
print $ifh $msg->{Body};
}
}
close $ifh;
open( $ifh, "<", $in ) or die "$in";
for(<$ifh>) {
next unless /^\s*owner|^\s*description/i;
print;
}
push@Qmail,split/\R\K/,$msg->{Body}代码>非常好,非常感谢。
#!/usr/bin/perl
use strict;
use warnings;
#use diagnostics;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
my @Qmail;
my $outlook = Win32::OLE->new('Outlook.Application')
or warn "Failed Opening Outlook.";
my $namespace = $outlook->GetNamespace("MAPI");
my $folder = $namespace->Folders("test")->Folders("Inbox");
my $items = $folder->Items;
foreach my $msg ( $items->in ) {
if ( $msg->{Subject} =~ m/^(.*test alert) / ) {
my $name = $1;
print " processing Email for $name \n";
push @Qmail, $msg->{Body};
}
}
for(@Qmail) {
next unless /^\s*owner|^\s*description/i;
print;
}