1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* EGroupware - Mail hooks |
4
|
|
|
* |
5
|
|
|
* @link http://www.egroupware.org |
6
|
|
|
* @package api |
7
|
|
|
* @subpackage amil |
8
|
|
|
* @author Klaus Leithoff <leithoff-AT-stylite.de> |
9
|
|
|
* @author Ralf Becker <[email protected]> |
10
|
|
|
* @copyright (c) 2008-16 by leithoff-At-stylite.de |
11
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
12
|
|
|
* @version $Id$ |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace EGroupware\Api\Mail; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* diverse static Mail hooks |
19
|
|
|
*/ |
20
|
|
|
class Hooks |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Password changed hook --> unset cached objects, as password might be used for email connection |
24
|
|
|
* |
25
|
|
|
* @param array $hook_data |
26
|
|
|
*/ |
27
|
|
|
public static function changepassword($hook_data) |
28
|
|
|
{ |
29
|
|
|
if (!empty($hook_data['old_passwd'])) |
30
|
|
|
{ |
31
|
|
|
Credentials::changepassword($hook_data); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Hook called before an account get deleted |
37
|
|
|
* |
38
|
|
|
* @param array $data |
39
|
|
|
* @param int $data['account_id'] numerical id |
40
|
|
|
* @param string $data['account_lid'] account-name |
41
|
|
|
* @param int $data['new_owner'] account-id of new owner, or false if data should get deleted |
42
|
|
|
*/ |
43
|
|
|
static function deleteaccount(array $data) |
44
|
|
|
{ |
45
|
|
|
self::run_plugin_hooks('deleteAccount', $data); |
46
|
|
|
|
47
|
|
|
// as mail accounts contain credentials, we do NOT assign them to user users |
48
|
|
|
Account::delete(0, $data['account_id']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Hook called before a group get deleted |
53
|
|
|
* |
54
|
|
|
* @param array $data |
55
|
|
|
* @param int $data['account_id'] numerical id |
56
|
|
|
* @param string $data['account_name'] account-name |
57
|
|
|
*/ |
58
|
|
|
static function deletegroup(array $data) |
59
|
|
|
{ |
60
|
|
|
Account::delete(0, $data['account_id']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Hook called when an account get added or edited |
65
|
|
|
* |
66
|
|
|
* @param array $data |
67
|
|
|
* @param int $data['account_id'] numerical id |
68
|
|
|
* @param string $data['account_lid'] account-name |
69
|
|
|
* @param string $data['account_email'] email |
70
|
|
|
*/ |
71
|
|
|
static function addaccount(array $data) |
72
|
|
|
{ |
73
|
|
|
$method = $data['location'] == 'addaccount' ? 'addAccount' : 'updateAccount'; |
74
|
|
|
self::run_plugin_hooks($method, $data); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Run hook on plugins of all mail-accounts of given account_id |
79
|
|
|
* |
80
|
|
|
* @param string $method plugin method to run |
81
|
|
|
* @param array $data hook-data incl. value for key account_id |
82
|
|
|
*/ |
83
|
|
|
protected static function run_plugin_hooks($method, array $data) |
84
|
|
|
{ |
85
|
|
|
foreach(Account::search((int)$data['account_id'], 'params') as $params) |
86
|
|
|
{ |
87
|
|
|
if (!Account::is_multiple($params)) continue; // no need to waste time on personal accounts |
88
|
|
|
|
89
|
|
|
try { |
90
|
|
|
$account = new Account($params); |
91
|
|
|
if ($account->acc_smtp_type != __NAMESPACE__.'\\Smtp' && ($smtp = $account->smtpServer(true)) && |
|
|
|
|
92
|
|
|
is_a($smtp, __NAMESPACE__.'\\Smtp') && get_class($smtp) != __NAMESPACE__.'\\Smtp') |
93
|
|
|
{ |
94
|
|
|
$smtp->$method($data); |
95
|
|
|
} |
96
|
|
|
if ($account->acc_imap_type != __NAMESPACE__.'\\Imap' && $account->acc_imap_admin_username && |
97
|
|
|
$account->acc_imap_admin_password && ($imap = $account->imapServer(true)) && |
98
|
|
|
is_a($imap, __NAMESPACE__.'\\Imap') && get_class($imap) != __NAMESPACE__.'\\Imap') |
99
|
|
|
{ |
100
|
|
|
$imap->$method($data); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
catch(\Exception $e) { |
104
|
|
|
_egw_log_exception($e); |
105
|
|
|
// ignore exception, without stalling other hooks |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.