equal
deleted
inserted
replaced
479 -- Parameters (from recipients address (MAIL TO) [localpart@the_domain]): |
479 -- Parameters (from recipients address (MAIL TO) [localpart@the_domain]): |
480 -- varchar localpart |
480 -- varchar localpart |
481 -- varchar the_domain |
481 -- varchar the_domain |
482 -- Returns: recipient_destination records |
482 -- Returns: recipient_destination records |
483 -- --- |
483 -- --- |
|
484 CREATE OR REPLACE FUNCTION _interpolate_destination( |
|
485 IN destination varchar, localpart varchar, IN the_domain varchar) |
|
486 RETURNS varchar |
|
487 AS $$ |
|
488 DECLARE |
|
489 result varchar(320); |
|
490 BEGIN |
|
491 IF position('%' in destination) = 0 THEN |
|
492 RETURN destination; |
|
493 END IF; |
|
494 result := replace(destination, '%n', localpart); |
|
495 result := replace(result, '%d', the_domain); |
|
496 result := replace(result, '%=', localpart || '=' || the_domain); |
|
497 RETURN result; |
|
498 END; |
|
499 $$ LANGUAGE plpgsql STABLE |
|
500 RETURNS NULL ON NULL INPUT |
|
501 EXTERNAL SECURITY INVOKER; |
|
502 |
484 CREATE OR REPLACE FUNCTION postfix_virtual_alias_map( |
503 CREATE OR REPLACE FUNCTION postfix_virtual_alias_map( |
485 IN localpart varchar, IN the_domain varchar) |
504 IN localpart varchar, IN the_domain varchar) |
486 RETURNS SETOF recipient_destination |
505 RETURNS SETOF recipient_destination |
487 AS $$ |
506 AS $$ |
488 DECLARE |
507 DECLARE |
491 catchall_cursor refcursor; |
510 catchall_cursor refcursor; |
492 recipient varchar(320) := localpart || '@' || the_domain; |
511 recipient varchar(320) := localpart || '@' || the_domain; |
493 did bigint := (SELECT gid FROM domain_name WHERE domainname=the_domain); |
512 did bigint := (SELECT gid FROM domain_name WHERE domainname=the_domain); |
494 BEGIN |
513 BEGIN |
495 FOR record IN |
514 FOR record IN |
496 SELECT recipient, destination |
515 SELECT recipient, |
|
516 _interpolate_destination(destination, localpart, the_domain) |
497 FROM alias |
517 FROM alias |
498 WHERE gid = did |
518 WHERE gid = did |
499 AND address = localpart |
519 AND address = localpart |
500 LOOP |
520 LOOP |
501 RETURN NEXT record; |
521 RETURN NEXT record; |
509 -- over mailboxes/relocated, which is not what we want. Therefore, |
529 -- over mailboxes/relocated, which is not what we want. Therefore, |
510 -- we must first find out if the query is for an existing mailbox |
530 -- we must first find out if the query is for an existing mailbox |
511 -- or relocated entry and return the identity mapping if that is |
531 -- or relocated entry and return the identity mapping if that is |
512 -- the case |
532 -- the case |
513 OPEN catchall_cursor FOR |
533 OPEN catchall_cursor FOR |
514 SELECT recipient, destination |
534 SELECT recipient, |
|
535 _interpolate_destination(destination, localpart, the_domain) |
515 FROM catchall |
536 FROM catchall |
516 WHERE gid = did; |
537 WHERE gid = did; |
517 FETCH NEXT FROM catchall_cursor INTO recordc; |
538 FETCH NEXT FROM catchall_cursor INTO recordc; |
518 |
539 |
519 IF recordc IS NOT NULL THEN |
540 IF recordc IS NOT NULL THEN |