Only notifies user about a broken redirection twice a month, fixes a few things.
[platal.git] / modules / email.php
index ef77898..d872eda 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);
 
@@ -831,9 +833,10 @@ class EmailModule extends PLModule
 
                 foreach ($broken_list as $email) {
                     if ($user = mark_broken_email($email, true)) {
-                        if ($user['nb_mails'] > 0) {
+                        if ($user['nb_mails'] > 0 && $user['notify']) {
                             $mail = new PlMailer('emails/broken.mail.tpl');
-                            $mail->addTo($user);
+                            $dest = User::getSilentWithUID($user['uid']);
+                            $mail->setTo($dest);
                             $mail->assign('user', $user);
                             $mail->assign('email', $email);
                             $mail->send();