class DBMysqli extends DBImpl {
- private static $_instance = null;
- private $con = null;
- private $charset = 'utf8';
- private $numRows = -1;
-
- private function __construct() {
- $this->connect();
- }
-
- function __destruct() {
- if ($this->con) {
- $this->con->close();
- $this->con = null;
- }
- }
-
- private function __clone() {}
-
- public static function getInstance() {
- if (!is_object(self::$_instance)) {
- self::$_instance = new DBMysqli();
- }
- return self::$_instance;
- }
-
- private function connect() {
- global $CFG;
-
- if (!$this->con) {
- $this->con = new mysqli($CFG->amavisd_db_host, $CFG->amavisd_db_user,
- $CFG->amavisd_db_password, $CFG->amavisd_db_name,
- $CFG->amavisd_db_port);
- if ($this->con->connect_error) {
- die ('Connect error ('.$this->con->connect_errno.') '.
- $this->con->connect_error);
- }
- }
- }
-
- public function setCharset($charset = 'utf8') {
- $this->charset = $charset;
- }
-
- private function changeCharset() {
- if (!$this->con->set_charset($this->charset)) {
- printf("Error loading character set %s: %s\n", $this->charset, $this->con->error);
- }
- }
-
- public function update($sql) {
- $success = true;
-
- if (! is_array($sql)) {
- $sql = array($sql);
- }
-
- $this->con->autocommit(false);
- foreach ($sql as $query) {
- $this->con->query($query) ? null : $success = false;
- }
- $success ? $this->con->commit() : $this->con->rollback();
- $this->con->autocommit(true);
-
- return $success;
- }
-
- function getMarked($recipient = 'all') {
- $all = array();
-
- $query = "select distinct m.mail_id as id from quarantine q, msgrcpt m, msgs s, maddr r ";
- $query .= "where m.mail_id = q.mail_id and q.mail_id = s.mail_id and m.rid = r.id ";
- $query .= "and (m.rs = 'R' or m.rs = 'D')";
+ private static $_instance = null;
+ private $con = null;
+ private $charset = 'utf8';
+ private $numRows = -1;
+
+ private function __construct() {
+ $this->connect();
+ }
+
+ function __destruct() {
+ if ($this->con) {
+ $this->con->close();
+ $this->con = null;
+ }
+ }
+
+ private function __clone() {}
+
+ public static function getInstance() {
+ if (!is_object(self::$_instance)) {
+ self::$_instance = new DBMysqli();
+ }
+ return self::$_instance;
+ }
+
+ private function connect() {
+ global $CFG;
+
+ if (!$this->con) {
+ $this->con = new mysqli($CFG->amavisd_db_host, $CFG->amavisd_db_user,
+ $CFG->amavisd_db_password, $CFG->amavisd_db_name,
+ $CFG->amavisd_db_port);
+ if ($this->con->connect_error) {
+ die ('Connect error ('.$this->con->connect_errno.') '.
+ $this->con->connect_error);
+ }
+ }
+ }
+
+ public function setCharset($charset = 'utf8') {
+ $this->charset = $charset;
+ }
+
+ private function changeCharset() {
+ if (!$this->con->set_charset($this->charset)) {
+ printf("Error loading character set %s: %s\n", $this->charset, $this->con->error);
+ }
+ }
+
+ public function update($sql) {
+ $success = true;
+
+ if (! is_array($sql)) {
+ $sql = array($sql);
+ }
+
+ $this->con->autocommit(false);
+ foreach ($sql as $query) {
+ $this->con->query($query) ? null : $success = false;
+ }
+ $success ? $this->con->commit() : $this->con->rollback();
+ $this->con->autocommit(true);
+
+ return $success;
+ }
+
+ function getMarked($recipient = 'all') {
+ $all = array();
+
+ $query = "select distinct m.mail_id as id from quarantine q, msgrcpt m, msgs s, maddr r ";
+ $query .= "where m.mail_id = q.mail_id and q.mail_id = s.mail_id and m.rid = r.id ";
+ $query .= "and (m.rs = 'R' or m.rs = 'D')";
if ($recipient != 'all') {
$query .= " and email = '$recipient'";
}
if ($result = $this->con->query($query)) {
- while ($row = $result->fetch_object()) {
- $all[] = $row->id;
- }
- }
-
- return $all;
- }
-
- public function getQMails($offset = -1, $rowsPerPage = -1, $recipient = 'all') {
- $row = array();
- $this->changeCharset();
- $query = "SELECT DISTINCT quarantine.mail_id, secret_id, rs, bspam_level, ";
- $query .= "(UNIX_TIMESTAMP(time_iso) + (3600 * 2)) AS time_iso, ";
- $query .= "SUBSTRING(sender.email,1,35) AS sender, ";
- $query .= "SUBSTRING(recipient.email,1,28) AS recipient, size, msgrcpt.content ";
- $query .= "AS quaratinefor, SUBSTRING( subject, 1, 25) AS subject FROM ";
- $query .= "`quarantine` LEFT JOIN msgrcpt ON msgrcpt.mail_id = quarantine.mail_id ";
- $query .= "LEFT JOIN msgs ON msgs.mail_id = quarantine.mail_id LEFT JOIN maddr AS ";
- $query .= "recipient ON msgrcpt.rid = recipient.id LEFT JOIN maddr AS sender ON ";
- $query .= "msgs.sid = sender.id WHERE msgrcpt.rs != 'R' AND msgrcpt.rs != 'D'";
-
- if ($recipient != 'all') {
- $query .= " and recipient.email = '$recipient'";
- }
-
- if ($offset >= 0 && $rowsPerPage >= 0) {
- $result = $this->con->query($query, MYSQLI_STORE_RESULT);
- if ($result) {
- $this->numRows = $result->num_rows;
- $result->free();
- } else {
- $this->numRows = 0;
- }
- $query .= " ORDER BY time_iso DESC LIMIT $offset, $rowsPerPage";
- }
-
- if ($result = $this->con->query($query, MYSQLI_USE_RESULT)) {
- if ($this->numRows < 0)
- $this->numRows = $result->num_rows;
- while ($obj = $result->fetch_object()) {
- $row[] = $obj;
- }
- $result->free();
- }
-
- return $row;
- }
-
- public function numRows() {
- return $this->numRows;
- }
-
- public function getMail($id) {
- $row = null;
-
- $this->changeCharset();
- $query = "SELECT * FROM quarantine WHERE mail_id = '$id'";
- if ($result = $this->con->query($query, MYSQLI_USE_RESULT)) {
- $row = $result->fetch_object();
- }
-
- return $row;
- }
+ while ($row = $result->fetch_object()) {
+ $all[] = $row->id;
+ }
+ }
+
+ return $all;
+ }
+
+ public function getQMails($offset = -1, $rowsPerPage = -1, $recipient = 'all') {
+ $row = array();
+ $this->changeCharset();
+ $query = "SELECT DISTINCT quarantine.mail_id, secret_id, rs, bspam_level, ";
+ $query .= "(UNIX_TIMESTAMP(time_iso) + (3600 * 2)) AS time_iso, ";
+ $query .= "SUBSTRING(sender.email,1,35) AS sender, ";
+ $query .= "SUBSTRING(recipient.email,1,28) AS recipient, size, msgrcpt.content ";
+ $query .= "AS quaratinefor, SUBSTRING( subject, 1, 25) AS subject FROM ";
+ $query .= "`quarantine` LEFT JOIN msgrcpt ON msgrcpt.mail_id = quarantine.mail_id ";
+ $query .= "LEFT JOIN msgs ON msgs.mail_id = quarantine.mail_id LEFT JOIN maddr AS ";
+ $query .= "recipient ON msgrcpt.rid = recipient.id LEFT JOIN maddr AS sender ON ";
+ $query .= "msgs.sid = sender.id WHERE msgrcpt.rs != 'R' AND msgrcpt.rs != 'D'";
+
+ if ($recipient != 'all') {
+ $query .= " and recipient.email = '$recipient'";
+ }
+
+ if ($offset >= 0 && $rowsPerPage >= 0) {
+ $result = $this->con->query($query, MYSQLI_STORE_RESULT);
+ if ($result) {
+ $this->numRows = $result->num_rows;
+ $result->free();
+ } else {
+ $this->numRows = 0;
+ }
+ $query .= " ORDER BY time_iso DESC LIMIT $offset, $rowsPerPage";
+ }
+
+ if ($result = $this->con->query($query, MYSQLI_USE_RESULT)) {
+ if ($this->numRows < 0)
+ $this->numRows = $result->num_rows;
+ while ($obj = $result->fetch_object()) {
+ $row[] = $obj;
+ }
+ $result->free();
+ }
+
+ return $row;
+ }
+
+ public function numRows() {
+ return $this->numRows;
+ }
+
+ public function getMail($id) {
+ $row = null;
+
+ $this->changeCharset();
+ $query = "SELECT * FROM quarantine WHERE mail_id = '$id'";
+ if ($result = $this->con->query($query, MYSQLI_USE_RESULT)) {
+ $row = $result->fetch_object();
+ }
+
+ return $row;
+ }
}