3 # This script takes a list of .forward files and generates a list of colon
4 # delimited fields for import into a ldap directory. The fields represent
5 # the user and their email forwarding.
7 # A sample invokation..
9 # find -name ".foward" -maxdepth 2 | mkforwardlist | sort | less
10 # Then correct any invalid forward files if possible. After that stash the
11 # output in a file, remove the invalid lines and import it.
13 # It also understand .qmail type files
15 import re, time, getopt, os, sys, pwd, stat;
17 SSHAuthSplit = re.compile('^(.* )?(\d+) (\d+) (\d+) ?(.+)$');
20 File = sys.stdin.readline().strip()
24 # Attempt to determine the UID
26 User = pwd.getpwuid(os.stat(File)[stat.ST_UID])[0];
28 print "Invalid0", File;
31 # Read the first two non comment non empty lines
32 Forward = open(File,"r");
35 Line = Forward.readline().strip()
38 if Line[0] == '#' or Line[0] == '\n':
40 if SSHAuthSplit.match(Line) == None:
41 print "Bad line", File;