db->quote('%'.$email.'%')); if (defined('IS_JOEY')) $report .= $sql . PHP_EOL; // FIXME foreach ($this->db->fetchObjectList($sql) as $row) { $domain = new VMail_Domain($row->vmail_domain_id); $report .= sprintf("Lösche %s aus Alias %s@%s\n", $email, $row->username, $domain->get('name')); $destination = array_map("trim", preg_split("/(\r?\n|\r|,)/", strtolower(trim($row->destination, " \n\r\t\v\x00,")))); if (count($destination) == 1) { $alias = new VMail_Alias($row->id); $report .= $alias->deleteAlias($commit); } else { $idx = array_search($email, $destination); if ($idx !== false) { unset($destination[$idx]); if (count($destination) < 5) $dst_new = implode(", ", $destination); else $dst_new = implode("\r\n", $destination); $sql = sprintf("UPDATE vmail_alias SET destination = %s WHERE id = %d", $this->db->quote($dst_new), $row->id); if (defined('IS_JOEY')) $report .= $sql . PHP_EOL; // FIXME if ($commit) $this->db->execute($sql); } } } return $report; } public function deleteFromRoundcubeIdentities($email, $commit=false) { $report = ''; foreach (['ROUNDCUBE_DBDRIVER', 'ROUNDCUBE_DBHOST', 'ROUNDCUBE_DBNAME', 'ROUNDCUBE_DBUSER', 'ROUNDCUBE_DBPASS'] AS $key) if (!defined($key)) throw new Exception("Configuration define {$key} not set"); $rdb = new Database(ROUNDCUBE_DBDRIVER, ROUNDCUBE_DBHOST, ROUNDCUBE_DBNAME, ROUNDCUBE_DBUSER, ROUNDCUBE_DBPASS); if (defined('MAIL_ERROR')) $rdb->setErrorMail(MAIL_ERROR); $sql = sprintf("SELECT identity_id,name,email,username FROM identities JOIN users using(user_id) WHERE email ILIKE %s", $rdb->quote($email)); foreach ($rdb->fetchObjectList($sql) as $row) { $name = $row->username; if ($row->name) $name .= " (" . $row->name . ")"; $report .= sprintf("Lösche %s aus den Roundcube Identitäten des Users %s\n", $email, $name); $sql = sprintf("DELETE FROM identities WHERE identity_id = %d", $row->identity_id); if (defined('IS_JOEY')) $report .= $sql . PHP_EOL; // FIXME if ($commit) $this->db->execute($sql); } return $report; } public function deleteAlias($commit=false) { if (!$this->id) throw new Exception("No user id provided"); $report = ''; $domain = new VMail_Domain($this->data->vmail_domain_id); $email = sprintf("%s@%s", $this->data->username, $domain->get('name')); $report .= $this->deleteFromDestination($email, $commit); if (defined('ROUNDCUBE_DBDRIVER')) { $report .= $this->deleteFromRoundcubeIdentities($email, $commit); } $report .= sprintf("Lösche %s aus Aliasen\n", $email); $sql = sprintf("DELETE FROM %s WHERE id = %d", $this->table, $this->id); if (defined('IS_JOEY')) $report .= $sql . PHP_EOL; // FIXME if ($commit) $this->db->execute($sql); return $report; } public function ajaxDeleteReport(Array $data) { $report = $this->deleteAlias(false); debug(utf8_decode($report)); return ['report' => nl2br($report)]; } public function ajaxDeleteAlias(Array $data) { $report = $this->deleteAlias(IS_JOEY != false); debug(utf8_decode($report)); return ['text' => sprintf("Alias %s gelöscht", $this->data->username)]; } }