--- a/pgsql/create_tables-dovecot-1.2.x.pgsql Tue Apr 10 00:33:53 2012 +0200
+++ b/pgsql/create_tables-dovecot-1.2.x.pgsql Tue Apr 10 00:50:55 2012 +0200
@@ -599,13 +599,30 @@
RETURN NEXT record;
END LOOP;
IF NOT FOUND THEN
+ -- First, we have to check existing mailboxes and
+ -- return identity if one exists
FOR record IN
- SELECT recipient, destination
- FROM catchall
+ SELECT recipient, recipient as destination
+ FROM users
WHERE gid = did
+ AND local_part = localpart
+ UNION SELECT recipient, recipient as destination
+ FROM relocated
+ WHERE gid = did
+ AND address = localpart
LOOP
RETURN NEXT record;
END LOOP;
+ -- Only now can we think about catchalls...
+ IF NOT FOUND THEN
+ FOR record IN
+ SELECT recipient, destination
+ FROM catchall
+ WHERE gid = did
+ LOOP
+ RETURN NEXT record;
+ END LOOP;
+ END IF;
END IF;
RETURN;
END;
--- a/pgsql/create_tables.pgsql Tue Apr 10 00:33:53 2012 +0200
+++ b/pgsql/create_tables.pgsql Tue Apr 10 00:50:55 2012 +0200
@@ -576,13 +576,30 @@
RETURN NEXT record;
END LOOP;
IF NOT FOUND THEN
+ -- First, we have to check existing mailboxes and
+ -- return identity if one exists
FOR record IN
- SELECT recipient, destination
- FROM catchall
+ SELECT recipient, recipient as destination
+ FROM users
WHERE gid = did
+ AND local_part = localpart
+ UNION SELECT recipient, recipient as destination
+ FROM relocated
+ WHERE gid = did
+ AND address = localpart
LOOP
RETURN NEXT record;
END LOOP;
+ -- Only now can we think about catchalls...
+ IF NOT FOUND THEN
+ FOR record IN
+ SELECT recipient, destination
+ FROM catchall
+ WHERE gid = did
+ LOOP
+ RETURN NEXT record;
+ END LOOP;
+ END IF;
END IF;
RETURN;
END;
--- a/pgsql/update_tables_0.5.x-0.6-dovecot-1.2.x.pgsql Tue Apr 10 00:33:53 2012 +0200
+++ b/pgsql/update_tables_0.5.x-0.6-dovecot-1.2.x.pgsql Tue Apr 10 00:50:55 2012 +0200
@@ -496,13 +496,30 @@
RETURN NEXT record;
END LOOP;
IF NOT FOUND THEN
+ -- First, we have to check existing mailboxes and
+ -- return identity if one exists
FOR record IN
- SELECT recipient, destination
- FROM catchall
+ SELECT recipient, recipient as destination
+ FROM users
WHERE gid = did
+ AND local_part = localpart
+ UNION SELECT recipient, recipient as destination
+ FROM relocated
+ WHERE gid = did
+ AND address = localpart
LOOP
RETURN NEXT record;
END LOOP;
+ -- Only now can we think about catchalls...
+ IF NOT FOUND THEN
+ FOR record IN
+ SELECT recipient, destination
+ FROM catchall
+ WHERE gid = did
+ LOOP
+ RETURN NEXT record;
+ END LOOP;
+ END IF;
END IF;
RETURN;
END;
--- a/pgsql/update_tables_0.5.x-0.6.pgsql Tue Apr 10 00:33:53 2012 +0200
+++ b/pgsql/update_tables_0.5.x-0.6.pgsql Tue Apr 10 00:50:55 2012 +0200
@@ -474,13 +474,30 @@
RETURN NEXT record;
END LOOP;
IF NOT FOUND THEN
+ -- First, we have to check existing mailboxes and
+ -- return identity if one exists
FOR record IN
- SELECT recipient, destination
- FROM catchall
+ SELECT recipient, recipient as destination
+ FROM users
WHERE gid = did
+ AND local_part = localpart
+ UNION SELECT recipient, recipient as destination
+ FROM relocated
+ WHERE gid = did
+ AND address = localpart
LOOP
RETURN NEXT record;
END LOOP;
+ -- Only now can we think about catchalls...
+ IF NOT FOUND THEN
+ FOR record IN
+ SELECT recipient, destination
+ FROM catchall
+ WHERE gid = did
+ LOOP
+ RETURN NEXT record;
+ END LOOP;
+ END IF;
END IF;
RETURN;
END;