Better viewing of postfix mail queue files than postcat?

Posted by Geekman on Stack Overflow See other posts from Stack Overflow or by Geekman
Published on 2010-04-30T10:05:50Z Indexed on 2010/05/02 7:57 UTC
Read the original article Hit count: 380

Filed under:
|
|
|
|

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?

Here'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.

© Stack Overflow or respective owner

Related posts about perl

Related posts about postfix