bin/mailredir.userv, lib/Odin.pm: Allocate multiple local parts at once.
[odin-cgi] / lib / Odin.pm
index a89ba88..d9307b2 100644 (file)
@@ -574,23 +574,27 @@ sub check_fixup_redir ($) {
   }
 }
 
-sub new_redir ($$\%) {
-  my ($dom, $gen, $r) = @_;
+sub new_redir ($$\%;$) {
+  my ($dom, $gen, $r, $n) = @_;
   my $db = open_db;
-  my $l;
+  my @l;
 
+  $n //= 1;
   check_fixup_redir $r;
   Odin::xact {
     clear_redir_reservations $db;
-    $l = Odin::gen_redir_name $db, $gen;
-    insert_record $db, "odin_mailredir",
-      lpart => $l, dom => $dom, owner => $WHO, st => 'live',
-      recip => $r->{recip} // qualify_recip $Odin::WHO,
-      expire => $r->{expire} // -1,
-      comment => $r->{comment} // "";
+    while (@l < $n) {
+      my $l = Odin::gen_redir_name $db, $gen;
+      insert_record $db, "odin_mailredir",
+       lpart => $l, dom => $dom, owner => $WHO, st => 'live',
+       recip => $r->{recip} // qualify_recip $Odin::WHO,
+       expire => $r->{expire} // -1,
+       comment => $r->{comment} // "";
+      push @l, $l;
+    }
     check_redir_limits $db;
   } $db;
-  return $l;
+  return @l;
 }
 
 sub reserve_redir ($$$) {