-
Notifications
You must be signed in to change notification settings - Fork 23
/
AmacubeAbstract.php
73 lines (63 loc) · 1.98 KB
/
AmacubeAbstract.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* AmacubeAbstract - super class for AmavisConfig, AmavisQuarantine and AccountConfig
*/
/*
This file is part of the amacube Roundcube plugin
Copyright (C) 2013, Alexander Köb <[email protected]>
Licensed under the GNU General Public License version 3.
See the COPYING file for a full license statement.
*/
class AmacubeAbstract {
// The roundcube login name must be the same as amavis recipient email address
protected $user_email = ''; // User login
private $db_config; // Store DB config
protected $db_conn; // DB connection
public $errors = array(); // Store errors
// Constructor
function __construct($db_config)
{
// Set the DB connection config
$this->db_config = $db_config;
// RCMail
$this->rc = rcmail::get_instance();
// This plugin assumes the the username equals the email address we want to have amavis checking for
$this->user_email = $this->rc->user->data['username'];
}
// Connect to DB
function init_db()
{
// Initialize a persistent DB connection
if (!$this->db_conn) {
if (!class_exists('rcube_db')) {
// Version: < 0.9
$this->db_conn = new rcube_mdb2($this->db_config, '', TRUE);
} else {
// Version: > 0.9
$this->db_conn = rcube_db::factory($this->db_config, '', TRUE);
}
}
$this->db_conn->db_connect('w');
// Error check
if ($error = $this->db_conn->is_error()) {
$this->rc->amacube->errors[] = 'db_connect_error';
rcube::write_log('errors','AMACUBE: Database connect error: '.$error);
return false;
}
return true;
}
// Return the last database error
function db_error()
{
if (!$this->db_conn) {
return false;
}
elseif (!$this->db_conn->is_error()) {
return false;
}
else {
return $this->db_conn->is_error();
}
}
}
?>