<<< Date Index >>>     <<< Thread Index >>>

Re: alias = save-hook?



Hi Rudy,

> Is there an easy way to use the aliases as save-hooks?  Or do I need
> to write a separate save-hook line for every single alias?  If so,
> does anyone know of a script that does this?

you need a script. Tobi, a colleague has written one (I cced him).

format for persons.db is:
        [Thomas Glanzmann]
        email1=sithglan@xxxxxxxxxxxxxxxxxxxx
        alias1=tg
        mboxName=Thomas_Glanzmann

        Thomas
#!/usr/bin/perl -w

use Config::IniFiles;
use strict;

my $cfg;
my @aliases;
my @savehooks;

sub openConfig {
        $cfg = Config::IniFiles->new(-file => "persons.db");
        #FIXME error-check
        
        my $mboxname = undef;
        my $alias = undef;
        my $mail = undef;
        my $noAliases = 0;
        
        foreach my $section($cfg->Sections) {
                $mboxname = undef;

                if (defined $cfg->val($section, 'mboxName')) {
                        $mboxname = $cfg->val($section, 'mboxName');
                }

                my $counter = 1;
                while (1 == 1) {
                        if (defined $cfg->val($section, "email$counter")) {
                                $mail = $cfg->val($section, "email$counter");
                                if (defined $cfg->val($section, 
"alias$counter")) {
                                        $alias = $cfg->val($section, 
"alias$counter");
                                } else {
                                        $noAliases += 1;
                                        $alias = "zzzzz$noAliases";
                                }

                                my $aliasentry = "alias $alias $section 
<$mail>";
                                push(@aliases, $aliasentry);
#                               print "$aliasentry\n";
                                
                                if (defined $mboxname) {
                                        my $savehookentry = "save-hook '$mail' 
=$mboxname";
                                        push(@savehooks, $savehookentry);
#                                       print "$savehookentry\n";
                                }
                        } else {
                                last;
                        }
                        $counter += 1;
                }
        }
}

sub writeFiles {
        open (ALIASES, ">aliases");
                foreach my $alias(@aliases) {
                        print ALIASES "$alias\n";
                }
        close (ALIASES);
        open (HOOKS, ">save-hook");
                foreach my $hook(@savehooks) {
                        print HOOKS "$hook\n";
                }
        close (HOOKS);
}

openConfig();
writeFiles();