Modify virtual_alias_maps function to check mailboxes/relocated first v0.6.x
authormartin f. krafft <madduck@madduck.net>
Tue, 10 Apr 2012 00:50:55 +0200
branchv0.6.x
changeset 512 821d3ffaaaca
parent 511 0244f1344b04
child 513 557c4703986c
Modify virtual_alias_maps function to check mailboxes/relocated first
pgsql/create_tables-dovecot-1.2.x.pgsql
pgsql/create_tables.pgsql
pgsql/update_tables_0.5.x-0.6-dovecot-1.2.x.pgsql
pgsql/update_tables_0.5.x-0.6.pgsql
--- 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;