--- a/pgsql/create_tables-dovecot-1.2.x.pgsql Wed Apr 11 09:08:19 2012 +0200
+++ b/pgsql/create_tables-dovecot-1.2.x.pgsql Wed Apr 11 16:23:27 2012 +0200
@@ -584,6 +584,25 @@
--
-- For more details see postconf(5) section virtual_alias_maps and virtual(5)
-- ---
+CREATE OR REPLACE FUNCTION _interpolate_destination(
+ IN destination varchar, localpart varchar, IN the_domain varchar)
+ RETURNS varchar
+AS $$
+ DECLARE
+ result varchar(320);
+ BEGIN
+ IF position('%' in destination) = 0 THEN
+ RETURN destination;
+ END IF;
+ result := replace(destination, '%n', localpart);
+ result := replace(result, '%d', the_domain);
+ result := replace(result, '%=', localpart || '=' || the_domain);
+ RETURN result;
+ END;
+$$ LANGUAGE plpgsql STABLE
+RETURNS NULL ON NULL INPUT
+EXTERNAL SECURITY INVOKER;
+
CREATE OR REPLACE FUNCTION postfix_virtual_alias_map(
IN localpart varchar, IN the_domain varchar)
RETURNS SETOF recipient_destination
@@ -596,7 +615,8 @@
did bigint := (SELECT gid FROM domain_name WHERE domainname=the_domain);
BEGIN
FOR record IN
- SELECT recipient, destination
+ SELECT recipient,
+ _interpolate_destination(destination, localpart, the_domain)
FROM alias
WHERE gid = did
AND address = localpart
@@ -614,7 +634,8 @@
-- or relocated entry and return the identity mapping if that is
-- the case
OPEN catchall_cursor FOR
- SELECT recipient, destination
+ SELECT recipient,
+ _interpolate_destination(destination, localpart, the_domain)
FROM catchall
WHERE gid = did;
FETCH NEXT FROM catchall_cursor INTO recordc;