1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2021. Plesk International GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
|
6
|
|
|
use PleskX\Api\Struct\Mail as Struct; |
7
|
|
|
|
8
|
|
|
class Mail extends \PleskX\Api\Operator |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param string $name |
12
|
|
|
* @param int $siteId |
13
|
|
|
* @param bool $mailbox |
14
|
|
|
* @param string $password |
15
|
|
|
* |
16
|
|
|
* @return Struct\Info |
17
|
|
|
*/ |
18
|
|
|
public function create($name, $siteId, $mailbox = false, $password = '') |
19
|
|
|
{ |
20
|
|
|
$packet = $this->_client->getPacket(); |
21
|
|
|
$info = $packet->addChild($this->_wrapperTag)->addChild('create'); |
22
|
|
|
|
23
|
|
|
$filter = $info->addChild('filter'); |
24
|
|
|
$filter->addChild('site-id', $siteId); |
25
|
|
|
$mailname = $filter->addChild('mailname'); |
26
|
|
|
$mailname->addChild('name', $name); |
27
|
|
|
if ($mailbox) { |
28
|
|
|
$mailname->addChild('mailbox')->addChild('enabled', 'true'); |
29
|
|
|
} |
30
|
|
|
if (!empty($password)) { |
31
|
|
|
$mailname->addChild('password')->addChild('value', $password); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$response = $this->_client->request($packet); |
35
|
|
|
|
36
|
|
|
return new Struct\Info($response->mailname); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $field |
41
|
|
|
* @param int|string $value |
42
|
|
|
* @param int $siteId |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function delete($field, $value, $siteId) |
47
|
|
|
{ |
48
|
|
|
$packet = $this->_client->getPacket(); |
49
|
|
|
$filter = $packet->addChild($this->_wrapperTag)->addChild('remove')->addChild('filter'); |
50
|
|
|
$filter->addChild('site-id', $siteId); |
51
|
|
|
$filter->addChild($field, $value); |
52
|
|
|
$response = $this->_client->request($packet); |
53
|
|
|
|
54
|
|
|
return 'ok' === (string) $response->status; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $name |
59
|
|
|
* @param int $siteId |
60
|
|
|
* |
61
|
|
|
* @return Struct\GeneralInfo |
62
|
|
|
*/ |
63
|
|
|
public function get($name, $siteId) |
64
|
|
|
{ |
65
|
|
|
$items = $this->getAll($siteId, $name); |
66
|
|
|
|
67
|
|
|
return reset($items); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param int $siteId |
72
|
|
|
* @param string|null $name |
73
|
|
|
* |
74
|
|
|
* @return Struct\GeneralInfo[] |
75
|
|
|
*/ |
76
|
|
|
public function getAll($siteId, $name = null) |
77
|
|
|
{ |
78
|
|
|
$packet = $this->_client->getPacket(); |
79
|
|
|
$getTag = $packet->addChild($this->_wrapperTag)->addChild('get_info'); |
80
|
|
|
|
81
|
|
|
$filterTag = $getTag->addChild('filter'); |
82
|
|
|
$filterTag->addChild('site-id', $siteId); |
83
|
|
|
if (!is_null($name)) { |
84
|
|
|
$filterTag->addChild('name', $name); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
88
|
|
|
$items = []; |
89
|
|
|
foreach ($response->xpath('//result') as $xmlResult) { |
90
|
|
|
if (!isset($xmlResult->mailname)) { |
91
|
|
|
continue; |
92
|
|
|
} |
93
|
|
|
$item = new Struct\GeneralInfo($xmlResult->mailname); |
94
|
|
|
$items[] = $item; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $items; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|