开发者

Is there a better tool than postcat for viewing postfix mail queue files?

So I got a call early this morning about a client needing to see what email they have waiting to be delivered sitting in our secondary mail server. Their link for the main server had (still is) been down for two days and they needed to see their email.

So I wrote up a quick Perl script to use mailq in combination with postcat to dump each email for their address into separate files, tar'd it up and sent it off. Horrible code, I know, but it was urgent.

My solution works OK in that it at least gives a raw view, but I thought tonight it would be nice if I had a solution where I could provide their email attachments and maybe remove some "garbage" header text as well. Most of the important emails seem to have a PDF or similar attached.

I've been looking around but the only method of viewing queue files I can see is the postcat command, and I really don't want to write my own parser - so I was wondering if any of you have already done so, or know of a better command to use?

Her开发者_开发百科e's the code for my current solution:

#!/usr/bin/perl

$qCmd="mailq | grep -B 2 \"someemailaddress@isp\" | cut -d \" \" -f 1";

@data = split(/\n/, `$qCmd`);
$i = 0;

foreach $line (@data)
{
    $i++;

    $remainder = $i % 2;
    if ($remainder == 0)
    {
            next;
    }

    if ($line =~ /\(/ || $line =~ /\n/ || $line eq "")
    {
        next;
    }
    print "Processing: " . $line . "\n";
    `postcat -q $line > $line.email.txt`;
    $subject=`cat $line.email.txt | grep "Subject:"`;
    #print "SUB" . $subject;
    #`cat $line.email.txt > \"$subject.$line.email.txt\"`;
}

Any advice appreciated.


You may find the Postfix::Parse::Mailq module of use here, as well as the pfcat script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜