Catalyst Deployment with Apache 2 and mod_fcgid

Posted by Adam Jacob Thu, 19 Jul 2007 18:38:00 GMT

Catalyst has long had FastCGI support built in, but all of the recipes are for the much older mod_fastcgi. As a Debian user, and fan of software that’s still maintained, I prefer mod_fcgid.

What follows is a simple Apache 2 virtual host for a Catalyst application, using mod_fcgid:


<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    ErrorLog logs/www.example.com.error_log
    TransferLog logs/www.example.com.access_log

    # This should point at your myapp/root
    DocumentRoot /srv/myapp/root
    Alias /static /srv/myapp/root/static

    <Location /static>
        SetHandler default-handler
    </Location>

    Alias / /srv/myapp/script/myapp_fastcgi.pl/

    <Location />
        Options ExecCGI
        Order allow,deny
        Allow from all
        AddHandler fcgid-script .pl
    </Location>
</VirtualHost>

Re-Queing a mailbox full of bounced messages

Posted by Adam Jacob Tue, 12 Jun 2007 00:04:00 GMT

We've recently run in to a situation where we had a fairly large number of legitimate messages bounce due to a misconfigured MTA. Once we fixed the MTA, we needed to get all of those messages back out the door again. It was a job for CPAN.
    

use strict;
use warnings;        
use Mail::Box::Manager;
use Email::MIME;
use Email::Send;

foreach my $mbox (@ARGV) {
    my $mgr = Mail::Box::Manager->new;
    my $folder = $mgr->open(folder => $mbox);
    my $sender = Email::Send->new({mailer => 'SMTP'});
    $sender->mailer_args([Host => 'localhost']);

    foreach my $msg ($folder->messages) {
        PART: foreach my $part ($msg->parts('ALL')) {  
            my $body =  $part->decoded;
            if ($body =~ /This is the mail system at/) {
                next PART;
            } elsif ($part->decoded =~ /Action: failed/) {
                next PART;
            } else {
                my $email = Email::MIME->new(\$part->decoded);
                print "Sending to: " . $email->header("To") . "\n";
                $sender->send($email);
            }
        }
    }
}

The code uses a couple of different modules:
  1. Mail::Box::Manager: handles opening a mailbox (in pretty much every common format) and extracting messages.
  2. Email::MIME: lets you construct a new email from a MIME encoded message.
  3. Email::Send: takes our Email::MIME object and sends it out (in this case, via SMTP, but you can choose your mechanism.)
So should you ever find yourself with a couple thousand erroneously bounced messages, don't fret. ;)