Re: [EXIM] .mailfilter to .forward

Página Principal
Apagar esta mensagem
Responder a esta mensagem
Autor: Kevin J Collins
Data:  
Para: Nicholas Blackaby
CC: exim-users, d.j.morriss
Assunto: Re: [EXIM] .mailfilter to .forward
Hi -

We've just finished such a move here at Heriot-Watt. Below is a
perl script written by our Dave Morriss to achieve the
conversion. Dave's quite happy for this to be distributed. It
will no doubt need some tailoring to your own needs.

Regards,

Kevin Collins


--- [ dot-forward.pl ] -------------------------------------------

#!/usr/bin/perl -w

################################################################################
# Find all .mailfilter files on pp and turn them into
# .forward files which forward mail to the same place
################################################################################
#
# D.J.Morriss, Heriot-Watt
#

$debug = 0;

# Where to find the uid, gid and pathname in the output of 'find'
$uidpos = 4;
$gidpos = 5;
$pathpos = 10;

# Use variables for things to aid changes later
$basedir = "/home";
$mailfilter = ".mailfilter";
$forward = ".forward";

$echo = "echo";        # Usually built-in
$chown = "/bin/chown";    # Usually not


# Run a find command and grab the output
open(PIPE,"find $basedir -name $mailfilter -prune -ls|") || 
    die "Unable to open find pipe: $!\n";


# Loop through all lines returned by find and stash the relevant stuff in
# an array
while (<PIPE>) {
    chop;


    # Pick out space delimited fields like AWK
    @items = split(' ');


    # Remove the "/.mailfilter" string from the path to leave the directory
    $items[$pathpos] =~ s:/$mailfilter::;


    # Stash the three items we're interested in: uid, gid and path. 
    # Use commas to delimit them
    push(@stack,join(',',$items[$uidpos],$items[$gidpos],$items[$pathpos]));
}
close(PIPE);


# Chew through the stored items and do the necessary .forward file creation
foreach (@stack) {
    print "$_\n" if $debug;


    # Pick out the items in the current array element
    ($uid,$gid,$mfdir) = split(',');


    # Open the .mailfilter file and abort if unable (may not be wise)
    $mfpath = "$mfdir/$mailfilter";
    open(MAILFILTER,$mfpath) || die "Unable to open $mfpath: $!\n";


    $fwdaddr = "";


    # Dig out the information we need from the mailfilter file
    while (<MAILFILTER>) {
        if (/^ignore pipe "\S+ ([^"]+)";$/) {
        # Here we have found the filtering info and picked out the
        # destination address
        $fwdaddr = $1;
        $fwdpath = "$mfdir/$forward";


        print "$fwdpath => $fwdaddr\n";


        # Create the forward file (or re-create if already existing)
        system("$echo $fwdaddr > $fwdpath");


        # If the file exists change ownership, otherwise complain
        if (-f "$fwdpath") {
        # New file is owned by the sameuid/gid as .mailfilter
            system("$chown $uid.$gid $fwdpath");
        } else {
            warn "Unable to create $fwdpath\n"
            }
    }
    }
    close(MAILFILTER);


    # Report any anomalies discovered when parsing the .mailfilter file
    print "** Unable to find forwarding address in $mfpath\n" unless ($fwdaddr);
}


# All done
exit;

--- [ dot-forward.pl ] -------------------------------------------





On Wed, 5 May 1999 13:28:42 +0100 (BST) Nicholas Blackaby
<N.D.Blackaby@???> wrote:

>
> Hi,
>
> We are in the process of migrating from Nexor's MMTA (PP)
> software to Exim and will need to convert users' .mailfilter
> files to suitable .forward files. Before I attempt to write my
> own Perl script to convert .mailfilter files to .forward files, I
> wonder if such a script is already "available". I would be
> grateful for any help.
>
> Thanks,
> Nick.
> --
> Nicholas D. Blackaby            Email: 
> N.D.Blackaby@??? Information Systems, IRS        
> Phone: 0171 911 5000 (ext. 3824) University of Westminster       
> Fax:   0171 911 5093 115 New Cavendish Street
> London  W1M 8JS

>
>
> --
> *** Exim information can be found at http://www.exim.org/ ***
>


__________________________________________________________________
Kevin Collins, Computing Services     | Tel.   +44 (0)131 451 3265
Heriot-Watt University, EDINBURGH     | Fax.   +44 (0)131 451 3261
Scotland, UK.  EH14 4AS               | K.J.Collins@???



--
*** Exim information can be found at http://www.exim.org/ ***