Moving .forward files to postfix aliases
Wed Jul 09, 2008 · 142 words

I don't like .forward files. They destroy any hope of having any kind of idea what aliases are being used. Postfix aliases are pretty bad too, but at least they're all in the same place.

Here's a handy and very simple PHP snippet that converts .forward files to postfix aliases. It's not perfect, especially if you have vacation autoresponses enabled (ie |/bin/vacation -a …), but it does save time:

#!/usr/bin/env php
<?php

# "Convert" .forward files to postfix aliases

if (!is_dir($argv[1])) {
 exit(sprintf("usage: %s dirn", basename($argv[0])));
}

$fws = trim(`find $argv[1] -maxdepth 2 -name .forward`);
printf("# postfix aliases %s by %sn", date('d.m.y'), `whoami`);

foreach (explode("\n", $fws) as $f)
{
  $b = basename (dirname ($f));
  # Trim empty lines
  $u = preg_replace ("/^$/", "", file_get_contents ($f));
  $u = str_replace ("n", ", ", $u);
  printf ("%s t:t %sn", $b, rtrim ($u, ", "));
}

back · essays · credits ·