Merge branch 'xorg/maint' into xorg/master
[platal.git] / modules / email.php
index de8af94..e5049c5 100644 (file)
@@ -27,10 +27,10 @@ class EmailModule extends PLModule
             'emails'                  => $this->make_hook('emails',      AUTH_COOKIE, 'mail'),
             'emails/alias'            => $this->make_hook('alias',       AUTH_MDP,    'mail'),
             'emails/antispam'         => $this->make_hook('antispam',    AUTH_MDP,    'mail'),
-            'emails/broken'           => $this->make_hook('broken',      AUTH_COOKIE),
+            'emails/broken'           => $this->make_hook('broken',      AUTH_COOKIE, 'user'),
             'emails/redirect'         => $this->make_hook('redirect',    AUTH_MDP,    'mail'),
             'emails/send'             => $this->make_hook('send',        AUTH_MDP,    'mail'),
-            'emails/antispam/submit'  => $this->make_hook('submit',      AUTH_COOKIE),
+            'emails/antispam/submit'  => $this->make_hook('submit',      AUTH_COOKIE, 'user'),
             'emails/test'             => $this->make_hook('test',        AUTH_COOKIE, 'mail', NO_AUTH),
 
             'emails/rewrite/in'       => $this->make_hook('rewrite_in',  AUTH_PUBLIC),
@@ -67,14 +67,18 @@ 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
+            XDB::execute("UPDATE  email_source_account  AS s
+                      INNER JOIN  email_virtual_domains AS m ON (m.id = s.domain)
+                      INNER JOIN  email_virtual_domains AS d ON (d.aliasing = m.id)
                              SET  flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
-                           WHERE  uid = {?} AND email = {?}", $user->id(), $email);
+                           WHERE  s.uid = {?} AND s.email = {?} AND d.name = {?}",
+                         $user->id(), $email, $domain);
             XDB::execute('UPDATE  accounts              AS a
                       INNER JOIN  email_virtual_domains AS d ON (d.name = {?})
+                      INNER JOIN  email_virtual_domains AS m ON (d.aliasing = m.id)
                              SET  a.best_domain = d.id
-                           WHERE  a.uid = {?}',
-                         $domain, $user->id());
+                           WHERE  a.uid = {?} AND m.name = {?}',
+                         $domain, $user->id(), $user->mainEmailDomain());
 
             // As having a non-null bestalias value is critical in
             // plat/al's code, we do an a posteriori check on the
@@ -615,12 +619,12 @@ class EmailModule extends PLModule
         require_once 'emails.inc.php';
         $page->assign('ok', false);
         if (S::logged() && (is_null($user) || $user->id() == S::i('uid'))) {
-            Email::activate_storage(S::user(), 'imap');
+            Email::activate_storage(S::user(), 'imap', Bogo::IMAP_DEFAULT);
             $page->assign('ok', true);
             $page->assign('yourself', S::user()->displayName());
             $page->assign('sexe', S::user()->isFemale());
         } else if (!S::logged() && $user) {
-            Email::activate_storage($user, 'imap');
+            Email::activate_storage($user, 'imap', Bogo::IMAP_DEFAULT);
             $page->assign('ok', true);
             $page->assign('yourself', $user->displayName());
             $page->assign('sexe', $user->isFemale());
@@ -872,10 +876,11 @@ class EmailModule extends PLModule
 
                 $csv = fopen('php://output', 'w');
                 fputcsv($csv, array('nom', 'promo', 'bounces', 'nbmails', 'url', 'corps', 'job', 'networking'), ';');
+                $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
                 foreach ($broken_user_list as $uid => $mails) {
                     $profile = Profile::get($uid);
                     $corps = $profile->getCorps();
-                    $current_corps = ($corps && $corps->current) ? $corps->current : '';
+                    $current_corps = ($corps && $corps->current) ? $corpsList[$corps->current] : '';
                     $jobs = $profile->getJobs();
                     $companies = array();
                     foreach ($jobs as $job) {