Merge branch 'xorg/maint' into xorg/master
[platal.git] / modules / email.php
index df211d6..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
@@ -307,7 +311,7 @@ class EmailModule extends PLModule
         $page->assign('googleapps', GoogleAppsAccount::account_status($user->id()));
 
         require_once 'emails.combobox.inc.php';
-        fill_email_combobox($page);
+        fill_email_combobox($page, array('job', 'stripped_directory'));
     }
 
     function handler_antispam($page, $filter_status = null, $redirection = null)
@@ -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());
@@ -740,7 +744,7 @@ class EmailModule extends PLModule
                                   FROM  email_watch            AS w
                             INNER JOIN  email_redirect_account AS r ON (w.email = r.redirect)
                             INNER JOIN  email_source_account   AS s ON (s.uid = r.uid AND s.type = \'forlife\')
-                            INNER JOIN  accounts               AS a ON (r.uid = a.uid)
+                             LEFT JOIN  accounts               AS a ON (w.uid = a.uid)
                                  WHERE  w.email = {?}
                               ORDER BY  s.email',
                                $email);
@@ -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) {