Users without email redirection cannot be lost.
[platal.git] / modules / email.php
index ef77898..ece008d 100644 (file)
@@ -67,10 +67,9 @@ class EmailModule extends PLModule
                            WHERE  uid = {?}", $user->id());
             // Then gives the bestalias flag to the given email.
             list($email, $domain) = explode('@', $email);
-            XDB::execute("UPDATE  email_source_account  AS s
-                      INNER JOIN  email_virtual_domains AS d ON (s.domain = d.id)
-                             SET  s.flags = CONCAT_WS(',', IF(s.flags = '', NULL, s.flags), 'bestalias')
-                           WHERE  s.uid = {?} AND s.email = {?} AND d.name = {?}", $user->id(), $email, $domain);
+            XDB::execute("UPDATE  email_source_account
+                             SET  flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
+                           WHERE  uid = {?} AND email = {?}", $user->id(), $email);
             XDB::execute('UPDATE  accounts              AS a
                       INNER JOIN  email_virtual_domains AS d ON (d.name = {?})
                              SET  a.best_domain = d.id
@@ -81,6 +80,8 @@ class EmailModule extends PLModule
             // plat/al's code, we do an a posteriori check on the
             // validity of the bestalias.
             fix_bestalias($user);
+            // Then refetch the user to update its bestalias.
+            S::set('user', User::getWithUID(S::user()->id()));
         }
 
         // Fetch and display aliases.
@@ -297,6 +298,7 @@ class EmailModule extends PLModule
                            ORDER BY  NOT(s.type = \'alias_aux\'), s.email, d.name',
                             $user->id());
         $page->assign('alias', $alias->fetchAllAssoc());
+        $page->assign('best_email', $user->bestEmail());
 
         $page->assign('emails', $redirect->emails);