mason/common/autohandler: Add an AGPL link to the HTML header.
[odin-cgi] / lib / Odin.pm
index a575e83..3983e8f 100644 (file)
@@ -1,4 +1,27 @@
 ### -*-perl-*-
+###
+### Common library for Odin
+###
+### (c) 2015 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of the `odin.gg' service, `odin-cgi'.
+###
+### `odin-cgi' is free software; you can redistribute it and/or modify
+### it under the terms of the GNU Affero General Public License as
+### published by the Free Software Foundation; either version 3 of the
+### License, or (at your option) any later version.
+###
+### `odin-cgi' is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU Affero General Public License for more details.
+###
+### You should have received a copy of the GNU Affero General Public
+### License along with `odin-cgi'; if not, see
+### <http://www.gnu.org/licenses/>.
 
 package Odin;
 
@@ -24,8 +47,9 @@ our $DSN = "dbi:Pg(pg_enable_utf8=>1):host=db";
 our $RETRY = 10;
 our @BACKOFF = (0.1, 10, 1.5, 0.5, 2.0);
 
-our $BASEURL = "http://odin.gg/";
-our $STATIC = "http://odin.gg/";
+our $BASEURL = "https://odin.gg/";
+our $STATIC = "https://odin.gg/static/";
+our $SRCURL = "https://git.distorted.org.uk/~mdw/odin-cgi/";
 
 our $SHORTURL_PATH = "u";
 our $PASTEBIN_PATH = "p";
@@ -574,7 +598,7 @@ sub gen_redir_name ($$) {
 sub qualify_recip ($) {
   my ($r) = @_;
 
-  return $r =~ /\@/ || !defined $MAIL_QUALDOM ? $r : "$r\@$MAIL_QUALDOM";
+  return $r =~ /\@/ || !defined $MAIL_QUALDOM ? $r : "$r\@\%d";
 }
 
 sub check_fixup_redir ($) {
@@ -586,6 +610,13 @@ sub check_fixup_redir ($) {
   }
 }
 
+sub subst_recip ($$) {
+  my ($l, $r) = @_;
+  my %d = ('%' => '%', 'l' => $l, 'd' => $MAIL_QUALDOM);
+  $r =~ s{%([%a-z])}{$d{$1} // fail "undefined substitution `\%$1'"}eg;
+  return $r;
+}
+
 sub new_redir ($$\%;$) {
   my ($dom, $gen, $r, $n) = @_;
   my $db = open_db;
@@ -600,7 +631,7 @@ sub new_redir ($$\%;$) {
       insert_record $db, "odin_mailredir",
        lpart => $l, dom => $dom, st => 'live',
        owner => $WHO, creator => $WHO,
-       recip => $r->{recip} // qualify_recip $Odin::WHO,
+       recip => subst_recip($l, $r->{recip} // qualify_recip $Odin::WHO),
        expire => $r->{expire} // -1,
        comment => $r->{comment} // "";
       push @l, $l;
@@ -688,7 +719,8 @@ sub modify_redir ($\%@) {
          WHERE lpart = ? AND dom = ? AND owner = ?", undef,
         $l, $dom, $WHO);
       if (!defined $recip) { Odin::fail "unknown local part `$l'"; }
-      elsif ($recip eq "") { $r{recip} //= qualify_recip $WHO; }
+      elsif ($recip eq "" || defined $r{recip})
+       { $r{recip} = subst_recip $l, $r{recip} // qualify_recip $WHO; }
       if ($st ne "live") { $r{st} = "live"; $r{expire} //= -1; }
       my @var = ();
       my @val = ();