@@ -25,10 +25,12 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
* optional, the email-address-id
|
||||
* @param string $emailaddr
|
||||
* optional, the email-address to add the forwarder for
|
||||
* @param int $customerid
|
||||
* optional, admin-only, the customer-id
|
||||
* @param string $loginname
|
||||
* optional, admin-only, the loginname
|
||||
* @param string $destination
|
||||
* email-address to add as forwarder
|
||||
* @param int $customerid
|
||||
* optional, required when called as admin/reseller
|
||||
*
|
||||
* @access admin,customer
|
||||
* @throws Exception
|
||||
@@ -39,28 +41,28 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
|
||||
throw new Exception("You cannot access this resource", 405);
|
||||
}
|
||||
|
||||
|
||||
if ($this->getUserDetail('email_forwarders_used') < $this->getUserDetail('email_forwarders') || $this->getUserDetail('email_forwarders') == '-1') {
|
||||
|
||||
|
||||
// parameter
|
||||
$id = $this->getParam('id', true, 0);
|
||||
$ea_optional = ($id <= 0 ? false : true);
|
||||
$emailaddr = $this->getParam('emailaddr', $ea_optional, '');
|
||||
$destination = $this->getParam('destination');
|
||||
|
||||
|
||||
// validation
|
||||
$idna_convert = new idna_convert_wrapper();
|
||||
$destination = $idna_convert->encode($destination);
|
||||
|
||||
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'id' => $id,
|
||||
'emailaddr' => $emailaddr
|
||||
));
|
||||
$id = $result['id'];
|
||||
|
||||
|
||||
// current destination array
|
||||
$result['destination_array'] = explode(' ', $result['destination']);
|
||||
|
||||
|
||||
if (! validateEmail($destination)) {
|
||||
standard_error('destinationiswrong', $destination, true);
|
||||
} elseif ($destination == $result['email']) {
|
||||
@@ -68,10 +70,10 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
} elseif (in_array($destination, $result['destination_array'])) {
|
||||
standard_error('destinationalreadyexist', $destination, true);
|
||||
}
|
||||
|
||||
|
||||
// get needed customer info to reduce the email-forwarder-counter by one
|
||||
$customer = $this->getCustomerData('email_forwarders');
|
||||
|
||||
|
||||
// add destination to address
|
||||
$result['destination'] .= ' ' . $destination;
|
||||
$stmt = Database::prepare("
|
||||
@@ -84,15 +86,15 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
"id" => $id
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
|
||||
|
||||
// update customer usage
|
||||
Customers::increaseUsage($customer['customerid'], 'email_forwarders_used');
|
||||
|
||||
|
||||
// update admin usage
|
||||
Admins::increaseUsage($customer['adminid'], 'email_forwarders_used');
|
||||
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] added email forwarder for '" . $result['email_full'] . "'");
|
||||
|
||||
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $result['email_full']
|
||||
));
|
||||
@@ -101,16 +103,28 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
throw new Exception("No more resources available", 406);
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot directly get an email forwarder.
|
||||
* You need to call Emails.get()
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
throw new Exception('You cannot directly get an email forwarder. You need to call Emails.get()', 303);
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot update an email forwarder.
|
||||
* You need to delete the entry and create a new one.
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
throw new Exception('You cannot update an email forwarder. You need to delete the entry and create a new one.', 303);
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot directly list email forwarders.
|
||||
* You need to call Emails.listing()
|
||||
*/
|
||||
public function listing()
|
||||
{
|
||||
throw new Exception('You cannot directly list email forwarders. You need to call Emails.listing()', 303);
|
||||
@@ -122,11 +136,13 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
* @param int $id
|
||||
* optional, the email-address-id
|
||||
* @param string $emailaddr
|
||||
* optional, the email-address to add the forwarder for
|
||||
* optional, the email-address to delete the forwarder from
|
||||
* @param int $customerid
|
||||
* optional, admin-only, the customer-id
|
||||
* @param string $loginname
|
||||
* optional, admin-only, the loginname
|
||||
* @param int $forwarderid
|
||||
* id of the forwarder to delete
|
||||
* @param int $customerid
|
||||
* optional, required when called as admin/reseller
|
||||
*
|
||||
* @access admin,customer
|
||||
* @throws Exception
|
||||
@@ -137,26 +153,26 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
|
||||
throw new Exception("You cannot access this resource", 405);
|
||||
}
|
||||
|
||||
|
||||
// parameter
|
||||
$id = $this->getParam('id', true, 0);
|
||||
$ea_optional = ($id <= 0 ? false : true);
|
||||
$emailaddr = $this->getParam('emailaddr', $ea_optional, '');
|
||||
$forwarderid = $this->getParam('forwarderid');
|
||||
|
||||
|
||||
// validation
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'id' => $id,
|
||||
'emailaddr' => $emailaddr
|
||||
));
|
||||
$id = $result['id'];
|
||||
|
||||
|
||||
$result['destination'] = explode(' ', $result['destination']);
|
||||
if (isset($result['destination'][$forwarderid]) && $result['email'] != $result['destination'][$forwarderid]) {
|
||||
|
||||
|
||||
// get needed customer info to reduce the email-forwarder-counter by one
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
|
||||
// unset it from array
|
||||
unset($result['destination'][$forwarderid]);
|
||||
// rebuild destination-string
|
||||
@@ -172,15 +188,15 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
"id" => $id
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
|
||||
|
||||
// update customer usage
|
||||
Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used');
|
||||
|
||||
|
||||
// update admin usage
|
||||
Admins::decreaseUsage($customer['adminid'], 'email_forwarders_used');
|
||||
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email forwarder for '" . $result['email_full'] . "'");
|
||||
|
||||
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $result['email_full']
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user