From f08827407a2156c0bc7daf63f44e8ac3707c2a12 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Fri, 22 Feb 2008 11:04:11 +0100 Subject: [PATCH] Switches to 'opt-out' mode for IMAP backend storage. Fixes code consistency mistakes in last commit. Signed-off-by: Vincent Zanotti --- include/emails.inc.php | 25 ++++++++++++------------- templates/emails/index.tpl | 5 ++--- upgrade/0.9.16/03_mail_storage.sql | 3 +-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/include/emails.inc.php b/include/emails.inc.php index 35b76d3..bf1ba1a 100644 --- a/include/emails.inc.php +++ b/include/emails.inc.php @@ -413,34 +413,33 @@ class Redirect class MailStorage { protected $uid; protected $name; + protected $storage; public function __construct($_uid, $_name) { $this->uid = $_uid; $this->name = $_name; - } - public function disable() - { $res = XDB::query("SELECT mail_storage FROM auth_user_md5 WHERE user_id = {?}", $this->uid); - $storages = explode(',', $res->fetchOneCell()); + $this->storages = new FlagSet($res->fetchOneCell()); + } - if (in_array($this->name, $storages)) { - array_splice($storages, array_search($this->name, $storages), 1); - XDB::execute("UPDATE auth_user_md5 - SET mail_storage = {?} - WHERE user_id = {?}", implode(',', $storages), $this->uid); - } + public function disable() + { + $this->storages->rmFlag($this->name); + XDB::execute("UPDATE auth_user_md5 + SET mail_storage = {?} + WHERE user_id = {?}", $this->storages->flags(), $this->uid); } public function enable() { + $this->storages->addFlag($this->name); XDB::execute("UPDATE auth_user_md5 - SET mail_storage = CONCAT_WS(',', IF(mail_storage = '', NULL, mail_storage), {?}) - WHERE user_id = {?} AND - FIND_IN_SET({?}, mail_storage) = 0", $this->name, $this->uid, $this->name); + SET mail_storage = {?} + WHERE user_id = {?}", $this->storages->flags(), $this->uid); } } diff --git a/templates/emails/index.tpl b/templates/emails/index.tpl index a5312c8..4d7c07c 100644 --- a/templates/emails/index.tpl +++ b/templates/emails/index.tpl @@ -102,17 +102,16 @@ ton homonyme et toi-même ne disposeraient plus que des adresses de la forme pre {if count($storage) neq 0} Ton courrier est également stocké sur {if count($storage) eq 1}le compte suivant{else} les comptes suivants{/if} : {/if} {test_email} diff --git a/upgrade/0.9.16/03_mail_storage.sql b/upgrade/0.9.16/03_mail_storage.sql index 7739c95..4774a53 100644 --- a/upgrade/0.9.16/03_mail_storage.sql +++ b/upgrade/0.9.16/03_mail_storage.sql @@ -1,4 +1,3 @@ -ALTER TABLE auth_user_md5 ADD COLUMN mail_storage SET('imap', 'googleapps') DEFAULT '' NOT NULL AFTER smtppass; -UPDATE auth_user_md5 SET mail_storage = 'imap' WHERE mail_storage = ''; +ALTER TABLE auth_user_md5 ADD COLUMN mail_storage SET('imap', 'googleapps') DEFAULT 'imap' NOT NULL AFTER smtppass; # vim:set syntax=mysql: -- 2.1.4