aboutsummaryrefslogtreecommitdiffstats
path: root/fripost-newalias
diff options
context:
space:
mode:
Diffstat (limited to 'fripost-newalias')
-rwxr-xr-xfripost-newalias63
1 files changed, 46 insertions, 17 deletions
diff --git a/fripost-newalias b/fripost-newalias
index 0ca009b..3fc68f8 100755
--- a/fripost-newalias
+++ b/fripost-newalias
@@ -23,6 +23,33 @@ If I<goto> is not fully qualified, C<fripost.org> is appended.
If I<from> is already an existing username or alias,
B<fripost-newalias> raises an error.
+Inserted aliases conform to Postfix's B<virtual>(5) alias table format,
+with the restriction that I<from> has to be either in the form:
+
+=over 4
+
+=item .
+
+I<user>@I<domain>, to redirect emails for I<user>@I<domain> to I<goto>, or
+
+=item .
+
+@I<domain>, to catch all emails for users in I<domain> and redirect them
+to I<goto>.
+This form has the lowest precedence: If there is an alias from
+I<user>@I<domain> to I<goto2>, emails to I<user>@I<domain> will be
+redirected to I<goto2> only.
+See B<virtual>(5) for details and warnings.
+
+=back
+
+If serveral entries are matching, for instance if there are an alias from
+I<user>@I<domain> to I<goto> and another for I<user>@I<domain> to
+I<goto2>, emails to I<user>@I<domain> will be redirected to BOTH I<goto>
+and I<goto2>. Note that B<fripost-newalias> forbids the creation of such
+aliases, unless B<--force> is set.
+
+
=head1 OPTIONS
=over 8
@@ -157,7 +184,7 @@ say "goto adress: $goto";
# Show from adresses
@addr = grep {
- if (Email::Valid->address($_)) {
+ if (Email::Valid->address('fake'.$_)) {
# Warn if the domain is unknown.
my $domain = (split /\@/, $_, 2)[1];
if ($ldap->domain->search({ domain => $domain })->count) {
@@ -183,28 +210,30 @@ confirm_or_abort();
## Insert alias into database
for my $addr (@addr) {
- my $rs = $ldap->alias->search({ address => $addr });
- if (!$rs->count or defined $conf->{force}) {
- if (!$ldap->user->search({ username => $addr })->count) {
- if (!$conf->{pretend}) {
- $ldap->alias->add({ address => $addr, goto => $goto,
- isActive => 'TRUE' });
- say "New alias added from $addr to $goto.";
- } else {
- vsay "Pretending, will not add alias."
- }
- }
- else {
- die "Error: Username $addr already exists.\n";
- }
- }
- else {
+
+ my ($u,$d) = split /\@/, $addr, 2;
+ my $rs;
+
+ # Ensure that the alias doesn't already exist.
+ $rs = $ldap->alias->search({ address => $addr });
+ if ($rs->count and not (defined $conf->{force})) {
print STDERR "Error: Alias $addr already exists. ";
print STDERR "(Targetting to ";
print STDERR (join ', ', map { $_->{goto} } $rs->entries);
say STDERR ".)";
exit 1;
}
+
+ die "Error: Username $addr exists.\n"
+ if ($ldap->user->search({ username => $addr })->count);
+
+ if (!$conf->{pretend}) {
+ $ldap->alias->add({ address => $addr, goto => $goto,
+ isActive => 'TRUE' });
+ say "New alias added from $addr to $goto.";
+ } else {
+ vsay "Pretending, will not add alias."
+ }
}
$ldap->unbind();