-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcpanel_api_email.php
More file actions
executable file
·493 lines (465 loc) · 18.9 KB
/
cpanel_api_email.php
File metadata and controls
executable file
·493 lines (465 loc) · 18.9 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Description of Cpanel_Api_Email
*
* @author nunenuh@gmail.com
* @modified by: Dean Elzey @ BitShout
*/
class Cpanel_Api_Email extends Cpanel_Api_Query{
private $param=array();
function __construct($param=array()) {
$this->param = $param;
parent::__construct($param);
}
/**
* List email accounts associated with a particular domain.
* This function will also list quota and disk usage information.
*
* @return type array of object
*
*/
public function list_mail(){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'listpopswithdisk'
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $status=$ob->cpanelresult->data;
}
/**
* Add (create) an e-mail account.
*
* Description <br>
* <b>$domain</b> Domain name for the e-mail account.<br>
* <b>$email</b> The address part before "@".<br>
* <b>$password</b> Password for the e-mail account.<br>
* <b>$quota</b> Positive integer, 0 for unlimited<br>
*
* @param type $domain string
* @param type $email string
* @param type $password string
* @param type $quota integer
* @return type boolean (true/false)
*
*/
public function add_mail($domain, $email, $password, $quota){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'addpop',
'domain' => $domain,
'email' => $email,
'password' => $password,
'quota' => $quota
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
$status=$ob->cpanelresult->data[0]->result;
if ($status==1) {
return TRUE;
} else {
return FALSE;
}
}
/**
* Modify an email account's quota.
*
* Description <br>
* <b>$domain</b> Domain name for the e-mail account.<br>
* <b>$email</b> The address part before "@".<br>
* <b>$quota</b> Positive integer, 0 for unlimited<br>
*
* @param type $domain
* @param type $email
* @param type $quota
* @return type
*/
public function edit_mail_quota($domain, $email, $quota){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'editquota',
'domain' => $domain,
'email' => $email,
'quota' => $quota
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
$status=$ob->cpanelresult->data[0]->result;
if ($status==1) {
return TRUE;
} else {
return FALSE;
}
}
/**
* Delete an Email Account
*
* Description <br>
* <b>$domain</b> Domain name for the e-mail account.<br>
* <b>$email</b> The address part before "@".<br>
*
* @param type $domain
* @param type $email
* @return type
*/
public function delete_mail($domain, $email){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'delpop',
'domain' => $domain,
'email' => $email
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
$status=$ob->cpanelresult->data[0]->result;
if ($status==1) {
return TRUE;
} else {
return FALSE;
}
}
/**
* Change an email account's password.
* Description <br>
* <b>$domain</b> Domain name for the e-mail account.<br>
* <b>$email</b> The address part before "@".<br>
* <b>$new_password</b> The new password for the account<br>
*
* @param type $domain string
* @param type $email string
* @param type $new_password string
* @return type
*/
public function update_mail_password($domain, $email, $new_password){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'passwdpop',
'domain' => $domain,
'email' => $email,
'password' => $new_password
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
$status=$ob->cpanelresult->data[0]->result;
if ($status==1) {
return TRUE;
} else {
return FALSE;
}
}
/**
* List all mail exchangers associated with a domain.
*
* Description <br>
* <b>$domain</b> The domain whose mail exchangers you wish to view.<br>
*
* @param type $domain string
* @return type
*/
public function list_mx($domain=''){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'listmxs'
);
!empty($domain) && array_push($input, array('domain' => $domain));
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
* Add an MX record. This function will not work if you do not have access to the 'changemx' feature.
*
* Descriptions <br>
* <b>$domain</b> The domain to which you wish to add the mail exchanger. <br>
* <b>exchange</b> The name of the mail exchanger (e.g. mail.example.com). <br>
* <b>$preference</b> priority of the mail exchanger.<br>
* <b>$alwaysaccept</b> This value describes whether or not the local machine should accept mail for this domain. <br>
* <br>
* Possible values for $alwaysaccept are as follows<br>
* <b>'auto'</b><br>
* Allow cPanel to determine the appropriate role based on a DNS query on the MX record.<br>
* <b>'local'</b><br>
* Always accept and route mail for the domain.<br>
* <b>'secondary'</b><br>
* Accept mail for the domain until a higher priority (lower numbered) mail server becomes available.<br>
* <b>'remote'</b><br>
* Do not accept mail for the domain. <br>
*
* @param type $domain string
* @param type $exchange string
* @param type $preference integer
* @param type $always_accept string
* @return type object
*/
public function add_mx($domain, $exchange, $preference, $always_accept=''){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'addmx',
'domain' => $domain,
'exchange' => $exchange,
'preference' => $preference
);
!empty($always_accept) && array_push($input, array('alwaysaccept' => $always_accept));
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
* Change values for a specific MX record.
* This function is not available in DEMO mode.
* You must have access to the 'changemx' feature to use this function.
*
* Descriptions <br>
* <b>$domain</b> The domain corresponding to the MX record you wish to change.<br>
* <b>$exchange</b> The name you wish to give to the new exchanger.<br>
* <b>$oldexchange</b> The name of the exchanger you wish to replace.<br>
* <b>$oldpreference</b> The priority value of the old exchanger. <br>
* <b>$preference</b> The new exchanger's priority value. <br>
* <b>$alwaysaccept</b> This parameter specifies how the new exchanger should behave. <br>
* <br>
* Possible values are for <b>$alwaysaccept</b> are : <br>
* 'local', 'secondary', 'backup', or 'remote'.
* If you choose not to specify this parameter, cPanel will choose the best possible value
*
* @param type $domain string
* @param type $exchange string
* @param type $old_exchange string
* @param type $old_preference integer
* @param type $preference integer
* @param type $always_accept string
* @return type object
*/
public function change_mx($domain, $exchange, $old_exchange, $old_preference, $preference, $always_accept=''){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'changemx',
'domain' => $domain,
'exchange' => $exchange,
'oldexchange' => $old_exchange,
'oldpreference' => $old_preference,
'preference' => $preference
);
!empty($always_accept) && array_push($input, array('alwaysaccept' => $always_accept));
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
* Delete an MX record.
* This function will not work if the 'changemx' feature is disabled for the current user.
*
* Descriptions<br>
*
* <b>$domain</b> The domain that corresponds to the mail exchanger you wish to remove. <br>
* <b>$exchange</b> The name of the mail exchanger you wish to remove (e.g. 'mail.example.com').<br>
* <b>$preference</b> The priority of the mail exchanger, 0 being the highest priority exchanger. <br>
*
* @param type $domain string
* @param type $exchange string
* @param type $preference integer
* @return type object
*/
public function delete_mx($domain, $exchange, $preference){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'delmx',
'domain' => $domain,
'exchange' => $exchange,
'preference' => $preference
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
* Set a mail exchanger for a specified domain to local, remote, secondary, or auto.
* The 'auto' value allows cPanel to determine the appropriate role for the mail exchanger.
* Note: This function only affects the cPanel configuration.
* You will need to configure the MX's DNS entry elsewhere.
* Remember: This function is not available if the 'changemx' feature is not enabled for the user.
* Internally, this call functions as an alias to Email::setalwaysaccept.
* However, this call will be parsed as a unique call when used in a hook or custom event handler.
*
* Descriptions<br>
* <b>$domain</b> The domain corresponding to the mail exchanger you wish to set.<br>
* <b>$mxcheck</b> The status of the mail exchanger as it corresponds to cPanel's configuration.<br>
* <br>
* Input options for <b>$mxcheck</b> are as follows:<br>
* <b>'auto'</b> - Allow cPanel to determine the appropriate role based on a DNS query on the MX record.<br>
* <b>'local'</b> - Always accept and route mail for the domain.<br>
* <b>'secondary'</b> - Accept mail for the domain until a high priority (lower numbered) mail server becomes available.<br>
* <b>'remote'</b> - Do not accept mail for the domain.<br>
*
* @param type $domain string
* @param type $mxcheck string
* @return type object
*/
public function set_mx_check($domain, $mxcheck){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'setmxcheck',
'domain' => $domain,
'mxcheck' => $mxcheck
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
* List forwarders associated with a specific domain<br>
*
* Descriptions <br>
* <b>$domain</b> The domain name whose forwarders you wish to review. <br>
* <b>$regex</b> Regular expressions allow you to filter results based on a set of criteria.<br>
*
* @param type $domain
* @param type $regex
* @return type
*/
public function list_forwarders($domain='', $regex=''){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'listforwards'
);
!empty($domain) && array_push($input, array('domain' =>$domain));
!empty($regex) && array_push($input, array('regex' =>$regex));
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
* Create an email forwarder for a specified address.
* You can forward mail to a new address or pipe incoming email to a program. <br>
*
* Descriptions<br>
* <b>$domain</b> The domain for which you wish to add a forwarder (e.g. example.com).<br>
* <b>$email</b> The local address you wish to use as a forwarder (e.g. 'user' if the address was user@example.com)<br>
* <b>$fwdopt</b> This parameter defines what type of forwarder should be used.<br>
* The valid values for this option are: <br>
* <b>'pipe'</b> - for forwarding to a program <br>
* <b>'fwd'</b> - for forwarding to another non-system email address <br>
* <b>'system'</b> - for forwarding to an account on the system <br>
* <b>'blackhole'</b> - for bouncing emails using the blackhole functionality<br>
* <b>'fail'</b> - for bounding emails using the fail functionality.<br>
* <br>
* <b>$fwdemail</b> The email address to which you want to forward mail.<br>
* <b>$fwdsystem</b> The system account that you wish to forward email to, this should only be used if 'fwdopt' equals 'system'. <br>
* <b>$failmsgs</b> If fwdopt is 'fail' this needs to be defined to determine the correct failure message. This should only be used if 'fwdopt' equals 'fail'. <br>
* <b>$pipefwd</b> The path to the program to which you wish to pipe email. <br>
*
* @param type $domain
* @param type $email
* @param type $fwdopt
* @param type $fwdemail
* @param type $fwdsystem
* @param type $failmsgs
* @param type $pipefwd
* @return type
*/
public function add_forwader($domain, $email, $fwdopt,
$fwdemail='', $fwdsystem='',$failmsgs='',$pipefwd=''){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'addforward',
'domain' => $domain,
'email' => $email,
'fwdopt' => $fwdopt
);
!empty($fwdemail) && array_push($input, array('fwdemail' =>$fwdemail));
!empty($fwdsystem) && array_push($input, array('fwdsystem' =>$fwdsystem));
!empty($failmsgs) && array_push($input, array('failmsgs' =>$failmsgs));
!empty($pipefwd) && array_push($input, array('failmsgs' =>$pipefwd));
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
* Retrieve the default address or action taken
* when unroutable messages are received by the default address.
*
* Descriptions<br>
* <b>$domain</b> The domain that corresponds to the default address and information you wish to view.<br>
*
* @param type $domain
* @return type
*/
public function list_default_adresses($domain){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'listdefaultaddresses',
'domain' => $domain
);
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
/**
*
* Configure a default (catchall) email address.
* A default address handles unroutable mail sent to a domain.
* Note: Irrelevant parameters are passed to the function
* regardless of its configuration and will be included in the rule.
* This will not cause any problems.
*
* Descriptions<br>
* <b>$fwdopt</b> Describes how unroutable mail will be handled.<br>
* The following options are available:<br>
* <b>'fail'</b> Bounce unroutable messages, returning a failure message to the sender.<br>
* <b>'fwd'</b>Forward unroutable messages to another email address.<br>
* <b>'blackhole'</b> Send undeliverable mail to /dev/null. <br>
* <b>'pipe'</b> Pipe undeliverable mail to a program.<br><br>
* <b>$domain</b> The domain to which the rule will apply. Note: The user must own this domain.<br>
* <b>$failmsgs</b> Note: This parameter only takes effect if fwdopt = 'fail'.<br>
* <b>$fwdemail</b> Note: This parameter only takes effect if fwdopt = 'fwd'. <br>
* <b>$pipefwd</b> Note: cPanel will append the user's home directory to the beginning of the value.<br>
*
* @param type $fwdopt string
* @param type $domain string
* @param type $failmsgs string
* @param type $fwdemail string
* @param type $pipefwd string
* @return type object
*/
public function set_default_address($fwdopt, $domain, $failmsgs='', $fwdemail='', $pipefwd=''){
$input=array(
'apiversion' => 2,
'module' => 'Email',
'function' => 'setdefaultaddress',
'fwdopt' => $fwdopt,
'domain' => $domain
);
!empty($fwdemail) && array_push($input, array('fwdemail' =>$fwdemail));
!empty($failmsgs) && array_push($input, array('failmsgs' =>$failmsgs));
!empty($pipefwd) && array_push($input, array('failmsgs' =>$pipefwd));
$query=$this->build_query($input);
$raw=$this->query($query);
$ob=json_decode($raw, false);
return $ob->cpanelresult->data;
}
}