{
    # vim: ft=perl:
    $OUT = '';

    use esmith::config;
    use esmith::db;

    my %accounts;
    tie %accounts, 'esmith::config', '/home/e-smith/accounts';

    # get $USERNAME from esmith::config - put there by the
    # email-update-user action as a temporary variable
    die "Username argument missing." unless defined ($USERNAME);

    my $type = db_get_type(\%accounts, $USERNAME);

    die
        "Account $USERNAME is not a user account; "
        . "update email forwarding failed.\n"
        unless $type eq 'user';

    my $EmailForward = db_get_prop(\%accounts, $USERNAME, "EmailForward");
    my $ForwardAddress = db_get_prop(\%accounts, $USERNAME, "ForwardAddress");
    my $filter = db_get_prop(\%accounts, $USERNAME, "Filter") || 'yes';

    my $default = './Maildir/';
    my $preprocessing = "";
    my $dt = $qmail{DeliveryType} || '';
    if ($dt eq 'program')
    {
        $preprocessing .= '| ';
    }
    $preprocessing .= $qmail{DeliveryInstruction} || '';

    # Don't preprocess if filter is no.
    unless ($filter eq 'yes') { $preprocessing = '' }

    $OUT = "$preprocessing\n" if $preprocessing;

    if ($EmailForward eq 'local')
    {
        $OUT .= $default;
    }
    elsif ($EmailForward eq 'forward')
    {
        $OUT .= '&' . $ForwardAddress;
    }
    elsif ($EmailForward eq 'both')
    {
        $OUT .= '&' . $ForwardAddress . "\n";
        $OUT .= $default;
    }
    else
    {
        # Shouldn't happen, but default.
        $OUT .= $default;
    }
}
