Fixes display and (de)activation of email storages (Closes #1477).
[platal.git] / include / reminder / email_backup.inc.php
index 957422a..9264d37 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -25,9 +25,7 @@ class ReminderEmailBackup extends Reminder
     {
         if ($action == 'yes') {
             require_once 'emails.inc.php';
-            $storage = new EmailStorage($this->user, 'imap');
-            $storage->activate();
-
+            Email::activate_storage($this->user, 'imap', Bogo::IMAP_DEFAULT);
             $this->UpdateOnYes();
         }
 
@@ -55,14 +53,18 @@ class ReminderEmailBackup extends Reminder
         return 'Xorg/IMAP';
     }
 
-    public static function IsCandidate(User &$user, $candidate)
+    public static function IsCandidate(User $user, $candidate)
     {
+        if (!$user->checkPerms(User::PERM_MAIL)) {
+            return false;
+        }
+
         require_once 'emails.inc.php';
-        $storage  = new EmailStorage($user, 'imap');
-        if ($storage->active) {
+        $active = Email::is_active_storage($user, 'imap');
+        if ($active) {
             Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
         }
-        return !$storage->active;
+        return !$active;
     }
 }