Adapts imap action according to the number of other active reidrection of the user.
authorStéphane Jacob <sj@m4x.org>
Sun, 6 Mar 2011 19:34:19 +0000 (20:34 +0100)
committerStéphane Jacob <sj@m4x.org>
Mon, 7 Mar 2011 00:49:19 +0000 (01:49 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
bin/cron/emails.check.php
include/emails.inc.php

index 8bab8ab..fb5fdd5 100755 (executable)
@@ -129,5 +129,15 @@ if ($opt_verbose) {
     echo "\n";
 }
 
+/*
+ * Updates imap settings for users with no active redirection. Their emails
+ * must go to imap and bounce.
+ */
+XDB::execute("UPDATE  email_redirect_account AS r
+           LEFT JOIN  email_redirect_account AS a ON (r.uid = a.uid AND a.flags = 'active' AND a.type != 'imap')
+                 SET  r.action = 'imap_and_bounce'
+               WHERE  r.type = 'imap' AND a.redirect IS NULL");
+
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index c9f35aa..4f0e1ba 100644 (file)
@@ -651,6 +651,7 @@ class Redirect
             }
         }
         check_redirect($this);
+        $this->update_imap();
         return SUCCESS;
     }
 
@@ -696,6 +697,7 @@ class Redirect
         // security stuff
         check_email($email, "Ajout d'une adresse surveillée aux redirections de " . $this->user->login());
         check_redirect($this);
+        $this->update_imap();
         return SUCCESS;
     }
 
@@ -710,6 +712,7 @@ class Redirect
             $email->set_rewrite($emails_rewrite[$email->email]);
         }
         check_redirect($this);
+        $this->update_imap();
         return SUCCESS;
     }
 
@@ -732,6 +735,7 @@ class Redirect
             $this->emails[$thisone]->deactivate();
         }
         check_redirect($this);
+        $this->update_imap();
         if ($allinactive && !$activate) {
             return ERROR_INACTIVE_REDIRECTION;
         }
@@ -744,6 +748,7 @@ class Redirect
             if ($mail->email == $email) {
                 $mail->set_rewrite($redirect);
                 check_redirect($this);
+                $this->update_imap();
                 return;
             }
         }
@@ -754,6 +759,7 @@ class Redirect
         foreach ($this->emails as &$mail) {
             if ($mail->email == $email) {
                 check_redirect($this);
+                $this->update_imap();
                 return $mail->clean_errors();
             }
         }
@@ -772,6 +778,7 @@ class Redirect
             }
         }
         check_redirect($this);
+        $this->update_imap();
     }
 
     public function enable()
@@ -786,6 +793,7 @@ class Redirect
             }
             check_redirect($this);
         }
+        $this->update_imap();
     }
 
     public function get_broken_mx()
@@ -838,6 +846,22 @@ class Redirect
     {
         return $this->user->id();
     }
+
+    private function update_imap()
+    {
+        // Imaps must bounce if and only if the user has no active redirection.
+        if (!$this->other_active('')) {
+            XDB::execute('UPDATE  email_redirect_account
+                             SET  action = \'imap_and_bounce\'
+                           WHERE  type = \'imap\' AND uid = {?}',
+                         $this->user->id());
+        } else {
+            XDB::execute('UPDATE  email_redirect_account
+                             SET  action = \'let_spams\'
+                           WHERE  type = \'imap\' AND uid = {?}',
+                         $this->user->id());
+        }
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: