split
changeset 0 2a5f2464f8c6
equal deleted inserted replaced
-1:000000000000 0:2a5f2464f8c6
       
     1 #! /usr/bin/perl
       
     2 # © 2005 Heiko Schlittermann <hs@schlittermannn.de>
       
     3 # $Id$
       
     4 # $URL$
       
     5 #
       
     6 # Einlesen von Schubis mail.csv und aufteilen in fetchmailrc/users/aliases
       
     7 # zur bequemen Weiterverarbeitung
       
     8 my $USAGE = <<'#';
       
     9 Usage: {{ME}} [options] ...
       
    10        --fetchmailrc=s  Name of the fetchmailrc file [{{$::Cf->fetchmailrc}}]
       
    11        --users=s	Name of the fetchmailrc file [{{$::Cf->users}}]
       
    12        --aliases=s	Name of the fetchmailrc file [{{$::Cf->aliases}}]
       
    13        --help
       
    14 
       
    15        Hint: use '/dev/null' as file name to supress the generation
       
    16        $Id$
       
    17 #
       
    18 
       
    19 
       
    20 use strict;
       
    21 use warnings;
       
    22 use AppConfig;
       
    23 use File::Basename;
       
    24 use IO::File;
       
    25 
       
    26 use constant ME => basename $0;
       
    27 
       
    28 use constant CONFIG => (
       
    29     { CASE => 1 },
       
    30     fetchmailrc =>  { DEFAULT => "fetchmailrc", ARGS => "=s" },	
       
    31     users =>	    { DEFAULT => "users", ARGS => "=s" },
       
    32     aliases =>	    { DEFAULT => "aliases", ARGS => "=s" },
       
    33     help =>	    { DEFAULT => 0, ARGS => "!" }
       
    34 
       
    35 );
       
    36 
       
    37 $::Cf = new AppConfig CONFIG;
       
    38 $::Cf->getopt(\@ARGV);
       
    39 
       
    40 if ($::Cf->help) {
       
    41     $USAGE =~ s/{{(.*?)}}/eval $1/eg;
       
    42     print $USAGE;
       
    43     exit;
       
    44 }
       
    45 
       
    46 
       
    47 
       
    48 MAIN: {
       
    49     our $Cf;
       
    50     my %groups;
       
    51 
       
    52     my $fetchmailrc = new IO::File $_ = $Cf->fetchmailrc, "w" or die ME.": Can't open >$_: $!\n" 
       
    53 	if $Cf->fetchmailrc;
       
    54     my $users = new IO::File $_ = $Cf->users, "w" or die ME.": Can't open >$_: $!\n" 
       
    55 	if $Cf->users;
       
    56 
       
    57 
       
    58     while (<>) {
       
    59 	$. == 1 and next;
       
    60 	s/\s*$//;
       
    61 	my ($mailto, $popbox, $poppass, $intern, $group, $imapuser, $imappass)
       
    62 	    = split /;/;
       
    63 
       
    64 	# externes Postfach?
       
    65 	if ($fetchmailrc and $popbox) {
       
    66 	    print $fetchmailrc "user \"$popbox\" with password \"$poppass\" is $mailto here\n";
       
    67 	}
       
    68 
       
    69 	# realser Nutzer?
       
    70 	if ($mailto =~ /^\Q$imapuser\E/) {
       
    71 	    my ($first, $last) = split /\./, $imapuser;
       
    72 	    $last or $last = $first, $first = "";
       
    73 	    print $users join(":", 
       
    74 		    $imapuser, 
       
    75 		    $imappass, 
       
    76 		    join(" ", $first ? ucfirst($first) : (), ucfirst($last)),
       
    77 		    join(",", $imapuser, $last, $first ? substr($first, 0, 1) . ".$last" : ()), 
       
    78 		    "\n");
       
    79 	} else {
       
    80 	    $mailto =~ s/\@.*//;
       
    81 	    push @{$groups{$mailto}}, $imapuser;
       
    82 	}
       
    83     }
       
    84 
       
    85     if ($Cf->aliases) {
       
    86 	my $aliases = new IO::File $_ = $Cf->aliases, "w" or die ME . ": Can't open >$_: $!\n";
       
    87 	print $aliases map { "$_: ". join(", ", @{$groups{$_}}). "\n" } sort keys %groups;
       
    88     }
       
    89 
       
    90 }
       
    91 
       
    92 __END__
       
    93 
       
    94 mailadresse;popmailbox;popmailpw;intern;intern-gruppe;imapaccount;imappw
       
    95 annika.henze@vw-audi-dresden-reick.de;;;intern;;annika.henze;ahenze
       
    96 isabell.zeiske@vw-audi-dresden-reick.de;;;intern;;isabell.zeiske;izeiske
       
    97 julia.micheel@vw-audi-dresden-reick.de;;;intern;;jilia.micheel;jmicheel
       
    98 mandy.stranz@vw-audi-dresden-reick.de;;;intern;;mandy.stranz;mstranz
       
    99 susann.kolodziejczyk@vw-audi-dresden-reick.de;;;intern;;susann.kolodziejczyk;skolo
       
   100 renate.feurich@vw-audi-dresden-reick.de;;;intern;;renate.feurich;rfeurich
       
   101 rwks01@vw-audi-dresden-reick.de;;;intern;;rwks01;rwks01
       
   102 rwks02@vw-audi-dresden-reick.de;;;intern;;rwks02;rwks02
       
   103 rwks03@vw-audi-dresden-reick.de;;;intern;;rwks03;rwks03
       
   104 
       
   105 # vim:sts=4 sw=4 aw ai sm: