Perl如何一次将电子邮件正文推送到一个数组

时间:2015-07-11 12:54:22

标签: arrays perl

您好我有一个脚本,它从具有特定主题行的outlook文件夹中抓取电子邮件正文。接下来我要做的是,只保留使用正则表达式从某些单词开始的行。 我可以实现这一点,如果我将电子邮件正文保存到文件句柄,然后重新打开它,但它看起来很乱。 如果我尝试将电子邮件正文推送到数组,则将其作为一行加载, 所以正则表达式将无法正常工作! 我的问题是,如何将电子邮件逐行推送到阵列。

这是代码示例,它可以运行

        #!/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;          
}

代码示例不起作用,因为数组是一个大行。

        #!/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;          
}

0 个答案:

没有答案