more api-doc

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-11-19 20:38:18 +01:00
parent 02ba4b5f67
commit 8a565532b2
3 changed files with 191 additions and 134 deletions

View File

@@ -18,14 +18,36 @@
class EmailAccounts extends ApiCommand implements ResourceEntity class EmailAccounts extends ApiCommand implements ResourceEntity
{ {
/**
* add a new email account for a given email-address either by id or emailaddr
*
* @param int $id
* optional email-address-id of email-address to add the account for
* @param string $emailaddr
* optional email-address to add the account for
* @param int $customerid
* optional, admin-only, the customer-id
* @param string $loginname
* optional, admin-only, the loginname
* @param string $email_password
* password for the account
* @param string $alternative_email
* optional email address to send account information to, default is the account that is being created
* @param int $email_quota
* optional quota if enabled in MB, default 0
*
* @access admin, customer
* @throws Exception
* @return array
*/
public function add() public function add()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new Exception("You cannot access this resource", 405);
} }
if ($this->getUserDetail('email_accounts_used') < $this->getUserDetail('email_accounts') || $this->getUserDetail('email_accounts') == '-1') { if ($this->getUserDetail('email_accounts_used') < $this->getUserDetail('email_accounts') || $this->getUserDetail('email_accounts') == '-1') {
// parameter // parameter
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true); $ea_optional = ($id <= 0 ? false : true);
@@ -33,41 +55,41 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$email_password = $this->getParam('email_password'); $email_password = $this->getParam('email_password');
$alternative_email = $this->getParam('alternative_email', true, ''); $alternative_email = $this->getParam('alternative_email', true, '');
$quota = $this->getParam('email_quota', true, 0); $quota = $this->getParam('email_quota', true, 0);
// validation // validation
$quota = validate($quota, 'email_quota', '/^\d+$/', 'vmailquotawrong', array(), true); $quota = validate($quota, 'email_quota', '/^\d+$/', 'vmailquotawrong', array(), true);
// get needed customer info to reduce the email-account-counter by one // get needed customer info to reduce the email-account-counter by one
$customer = $this->getCustomerData('email_accounts'); $customer = $this->getCustomerData('email_accounts');
// check for imap||pop3 == 1, see #1298 // check for imap||pop3 == 1, see #1298
if ($customer['imap'] != '1' && $customer['pop3'] != '1') { if ($customer['imap'] != '1' && $customer['pop3'] != '1') {
standard_error('notallowedtouseaccounts', '', true); standard_error('notallowedtouseaccounts', '', true);
} }
// get email address // get email address
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'id' => $id, 'id' => $id,
'emailaddr' => $emailaddr 'emailaddr' => $emailaddr
)); ));
$id = $result['id']; $id = $result['id'];
$email_full = $result['email_full']; $email_full = $result['email_full'];
$idna_convert = new idna_convert_wrapper(); $idna_convert = new idna_convert_wrapper();
$username = $idna_convert->decode($email_full); $username = $idna_convert->decode($email_full);
$password = validate($email_password, 'password', '', '', array(), true); $password = validate($email_password, 'password', '', '', array(), true);
$password = validatePassword($password, true); $password = validatePassword($password, true);
if ($result['popaccountid'] != 0) { if ($result['popaccountid'] != 0) {
throw new Exception("Email address '" . $email_full . "' has already an account assigned.", 406); throw new Exception("Email address '" . $email_full . "' has already an account assigned.", 406);
} }
if (checkMailAccDeletionState($email_full)) { if (checkMailAccDeletionState($email_full)) {
standard_error(array( standard_error(array(
'mailaccistobedeleted' 'mailaccistobedeleted'
), $email_full, true); ), $email_full, true);
} }
// alternative email address to send info to // alternative email address to send info to
if (Settings::Get('panel.sendalternativemail') == 1) { if (Settings::Get('panel.sendalternativemail') == 1) {
$alternative_email = $idna_convert->encode(validate($alternative_email, 'alternative_email', '', '', array(), true)); $alternative_email = $idna_convert->encode(validate($alternative_email, 'alternative_email', '', '', array(), true));
@@ -77,7 +99,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
} else { } else {
$alternative_email = ''; $alternative_email = '';
} }
// validate quota if enabled // validate quota if enabled
if (Settings::Get('system.mail_quota_enabled') == 1) { if (Settings::Get('system.mail_quota_enabled') == 1) {
if ($customer['email_quota'] != '-1' && ($quota == 0 || ($quota + $customer['email_quota_used']) > $customer['email_quota'])) { if ($customer['email_quota'] != '-1' && ($quota == 0 || ($quota + $customer['email_quota_used']) > $customer['email_quota'])) {
@@ -87,14 +109,14 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
// disable // disable
$quota = 0; $quota = 0;
} }
if ($password == $email_full) { if ($password == $email_full) {
standard_error('passwordshouldnotbeusername', '', true); standard_error('passwordshouldnotbeusername', '', true);
} }
// encrypt the password // encrypt the password
$cryptPassword = makeCryptPassword($password); $cryptPassword = makeCryptPassword($password);
$email_user = substr($email_full, 0, strrpos($email_full, "@")); $email_user = substr($email_full, 0, strrpos($email_full, "@"));
$email_domain = substr($email_full, strrpos($email_full, "@") + 1); $email_domain = substr($email_full, strrpos($email_full, "@") + 1);
$maildirname = trim(Settings::Get('system.vmail_maildirname')); $maildirname = trim(Settings::Get('system.vmail_maildirname'));
@@ -103,7 +125,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
if (! empty($maildirname) && substr($maildirname, - 1) != "/") { if (! empty($maildirname) && substr($maildirname, - 1) != "/") {
$maildirpath .= "/"; $maildirpath .= "/";
} }
// insert data // insert data
$stmt = Database::prepare("INSERT INTO `" . TABLE_MAIL_USERS . "` SET $stmt = Database::prepare("INSERT INTO `" . TABLE_MAIL_USERS . "` SET
`customerid` = :cid, `customerid` = :cid,
@@ -139,7 +161,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
} }
Database::pexecute($stmt, $params, true, true); Database::pexecute($stmt, $params, true, true);
$popaccountid = Database::lastInsertId(); $popaccountid = Database::lastInsertId();
// add email address to its destination field // add email address to its destination field
$result['destination'] .= ' ' . $email_full; $result['destination'] .= ' ' . $email_full;
$stmt = Database::prepare(" $stmt = Database::prepare("
@@ -153,34 +175,35 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
"id" => $id "id" => $id
); );
Database::pexecute($stmt, $params, true, true); Database::pexecute($stmt, $params, true, true);
// update customer usage // update customer usage
Customers::increaseUsage($customer['customerid'], 'email_accounts_used'); Customers::increaseUsage($customer['customerid'], 'email_accounts_used');
Customers::increaseUsage($customer['customerid'], 'email_quota_used', '', $quota); Customers::increaseUsage($customer['customerid'], 'email_quota_used', '', $quota);
// update admin usage // update admin usage
Admins::increaseUsage($customer['adminid'], 'email_accounts_used'); Admins::increaseUsage($customer['adminid'], 'email_accounts_used');
Admins::increaseUsage($customer['adminid'], 'email_quota_used', '', $quota); Admins::increaseUsage($customer['adminid'], 'email_quota_used', '', $quota);
// replacer array for mail to create account on server // replacer array for mail to create account on server
$replace_arr = array( $replace_arr = array(
'EMAIL' => $email_full, 'EMAIL' => $email_full,
'USERNAME' => $username, 'USERNAME' => $username,
'PASSWORD' => $password 'PASSWORD' => $password
); );
// get the customers admin // get the customers admin
$stmt = Database::prepare("SELECT `name`, `email` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid`= :adminid"); $stmt = Database::prepare("SELECT `name`, `email` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid`= :adminid");
$admin = Database::pexecute_first($stmt, array( $admin = Database::pexecute_first($stmt, array(
"adminid" => $customer['adminid'] "adminid" => $customer['adminid']
)); ));
// get template for mail subject // get template for mail subject
$mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_subject', $replace_arr, $this->lng['mails']['pop_success']['subject']); $mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_subject', $replace_arr, $this->lng['mails']['pop_success']['subject']);
// get template for mail body // get template for mail body
$mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_mailbody', $replace_arr, $this->lng['mails']['pop_success']['mailbody']); $mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_mailbody', $replace_arr, $this->lng['mails']['pop_success']['mailbody']);
$_mailerror = false; $_mailerror = false;
$mailerr_msg = "";
try { try {
$this->mailer()->SetFrom($admin['email'], getCorrectUserSalutation($admin)); $this->mailer()->SetFrom($admin['email'], getCorrectUserSalutation($admin));
$this->mailer()->Subject = $mail_subject; $this->mailer()->Subject = $mail_subject;
@@ -195,21 +218,21 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$mailerr_msg = $e->getMessage(); $mailerr_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
if ($_mailerror) { if ($_mailerror) {
$log->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_ERR, "[API] Error sending mail: " . $mailerr_msg); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_ERR, "[API] Error sending mail: " . $mailerr_msg);
standard_error('errorsendingmail', $email_full, true); standard_error('errorsendingmail', $email_full, true);
} }
$this->mailer()->ClearAddresses(); $this->mailer()->ClearAddresses();
// customer wants to send the e-mail to an alternative email address too // customer wants to send the e-mail to an alternative email address too
if (Settings::Get('panel.sendalternativemail') == 1) { if (Settings::Get('panel.sendalternativemail') == 1) {
// get template for mail subject // get template for mail subject
$mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_subject', $replace_arr, $this->lng['mails']['pop_success_alternative']['subject']); $mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_subject', $replace_arr, $this->lng['mails']['pop_success_alternative']['subject']);
// get template for mail body // get template for mail body
$mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_mailbody', $replace_arr, $this->lng['mails']['pop_success_alternative']['mailbody']); $mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_mailbody', $replace_arr, $this->lng['mails']['pop_success_alternative']['mailbody']);
$_mailerror = false; $_mailerror = false;
try { try {
$this->mailer()->SetFrom($admin['email'], getCorrectUserSalutation($admin)); $this->mailer()->SetFrom($admin['email'], getCorrectUserSalutation($admin));
@@ -225,17 +248,17 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$mailerr_msg = $e->getMessage(); $mailerr_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
if ($_mailerror) { if ($_mailerror) {
$log->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_ERR, "[API] Error sending mail: " . $mailerr_msg); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_ERR, "[API] Error sending mail: " . $mailerr_msg);
standard_error(array( standard_error(array(
'errorsendingmail' 'errorsendingmail'
), $alternative_email, true); ), $alternative_email, true);
} }
$this->mailer()->ClearAddresses(); $this->mailer()->ClearAddresses();
} }
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] added email account for '" . $result['email_full'] . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] added email account for '" . $result['email_full'] . "'");
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'emailaddr' => $result['email_full'] 'emailaddr' => $result['email_full']
@@ -245,9 +268,13 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
throw new Exception("No more resources available", 406); throw new Exception("No more resources available", 406);
} }
/**
* You cannot directly get an email account.
* You need to call Emails.get()
*/
public function get() public function get()
{ {
throw new Exception('You cannot directly get an email forwarder. You need to call Emails.get()', 303); throw new Exception('You cannot directly get an email account. You need to call Emails.get()', 303);
} }
/** /**
@@ -256,9 +283,11 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
* @param int $id * @param int $id
* optional, the email-address-id * optional, the email-address-id
* @param string $emailaddr * @param string $emailaddr
* optional, the email-address to add the forwarder for * optional, the email-address to update
* @param int $customerid * @param int $customerid
* optional, required when called as admin/reseller * optional, admin-only, the customer-id
* @param string $loginname
* optional, admin-only, the loginname
* @param int $email_quota * @param int $email_quota
* optional, update quota * optional, update quota
* @param string $email_password * @param string $email_password
@@ -273,32 +302,32 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new Exception("You cannot access this resource", 405);
} }
// parameter // parameter
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true); $ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, ''); $emailaddr = $this->getParam('emailaddr', $ea_optional, '');
// validation // validation
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'id' => $id, 'id' => $id,
'emailaddr' => $emailaddr 'emailaddr' => $emailaddr
)); ));
$id = $result['id']; $id = $result['id'];
if (empty($result['popaccountid']) || $result['popaccountid'] == 0) { if (empty($result['popaccountid']) || $result['popaccountid'] == 0) {
throw new Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406); throw new Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406);
} }
$password = $this->getParam('email_password', true, ''); $password = $this->getParam('email_password', true, '');
$quota = $this->getParam('email_quota', true, $result['quota']); $quota = $this->getParam('email_quota', true, $result['quota']);
// get needed customer info to reduce the email-account-counter by one // get needed customer info to reduce the email-account-counter by one
$customer = $this->getCustomerData(); $customer = $this->getCustomerData();
// validation // validation
$quota = validate($quota, 'email_quota', '/^\d+$/', 'vmailquotawrong', array(), true); $quota = validate($quota, 'email_quota', '/^\d+$/', 'vmailquotawrong', array(), true);
$upd_query = ""; $upd_query = "";
$upd_params = array( $upd_params = array(
"id" => $result['popaccountid'], "id" => $result['popaccountid'],
@@ -316,7 +345,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$upd_params['password'] = $password; $upd_params['password'] = $password;
} }
} }
if (Settings::Get('system.mail_quota_enabled') == 1) { if (Settings::Get('system.mail_quota_enabled') == 1) {
if ($quota != $result['quota']) { if ($quota != $result['quota']) {
if ($customer['email_quota'] != '-1' && ($quota == 0 || ($quota + $customer['email_quota_used'] - $result['quota']) > $customer['email_quota'])) { if ($customer['email_quota'] != '-1' && ($quota == 0 || ($quota + $customer['email_quota_used'] - $result['quota']) > $customer['email_quota'])) {
@@ -332,7 +361,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
// disable // disable
$quota = 0; $quota = 0;
} }
// build update query // build update query
if (! empty($upd_query)) { if (! empty($upd_query)) {
$upd_stmt = Database::prepare(" $upd_stmt = Database::prepare("
@@ -340,12 +369,12 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
"); ");
Database::pexecute($upd_stmt, $upd_params, true, true); Database::pexecute($upd_stmt, $upd_params, true, true);
} }
if ($customer['email_quota'] != '-1') { if ($customer['email_quota'] != '-1') {
Customers::increaseUsage($customer['customerid'], 'email_quota_used', '', ($quota - $result['quota'])); Customers::increaseUsage($customer['customerid'], 'email_quota_used', '', ($quota - $result['quota']));
Admins::increaseUsage($customer['adminid'], 'email_quota_used', '', ($quota - $result['quota'])); Admins::increaseUsage($customer['adminid'], 'email_quota_used', '', ($quota - $result['quota']));
} }
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] updated email account '" . $result['email_full'] . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] updated email account '" . $result['email_full'] . "'");
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'emailaddr' => $result['email_full'] 'emailaddr' => $result['email_full']
@@ -353,6 +382,10 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
/**
* You cannot directly list email forwarders.
* You need to call Emails.listing()
*/
public function listing() public function listing()
{ {
throw new Exception('You cannot directly list email forwarders. You need to call Emails.listing()', 303); throw new Exception('You cannot directly list email forwarders. You need to call Emails.listing()', 303);
@@ -364,11 +397,13 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
* @param int $id * @param int $id
* optional, the email-address-id * optional, the email-address-id
* @param string $emailaddr * @param string $emailaddr
* optional, the email-address to add the forwarder for * optional, the email-address to delete the account for
* @param int $customerid
* optional, admin-only, the customer-id
* @param string $loginname
* optional, admin-only, the loginname
* @param bool $delete_userfiles * @param bool $delete_userfiles
* optional, default false * optional, default false
* @param int $customerid
* optional, required when called as admin/reseller
* *
* @access admin,customer * @access admin,customer
* @throws Exception * @throws Exception
@@ -379,27 +414,27 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new Exception("You cannot access this resource", 405);
} }
// parameter // parameter
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true); $ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, ''); $emailaddr = $this->getParam('emailaddr', $ea_optional, '');
$delete_userfiles = $this->getParam('delete_userfiles', true, 0); $delete_userfiles = $this->getParam('delete_userfiles', true, 0);
// validation // validation
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'id' => $id, 'id' => $id,
'emailaddr' => $emailaddr 'emailaddr' => $emailaddr
)); ));
$id = $result['id']; $id = $result['id'];
if (empty($result['popaccountid']) || $result['popaccountid'] == 0) { if (empty($result['popaccountid']) || $result['popaccountid'] == 0) {
throw new Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406); throw new Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406);
} }
// get needed customer info to reduce the email-account-counter by one // get needed customer info to reduce the email-account-counter by one
$customer = $this->getCustomerData(); $customer = $this->getCustomerData();
// delete entry // delete entry
$stmt = Database::prepare(" $stmt = Database::prepare("
DELETE FROM `" . TABLE_MAIL_USERS . "` WHERE `customerid`= :cid AND `id`= :id DELETE FROM `" . TABLE_MAIL_USERS . "` WHERE `customerid`= :cid AND `id`= :id
@@ -408,10 +443,10 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
"cid" => $customer['customerid'], "cid" => $customer['customerid'],
"id" => $result['popaccountid'] "id" => $result['popaccountid']
), true, true); ), true, true);
// update mail-virtual entry // update mail-virtual entry
$result['destination'] = str_replace($result['email_full'], '', $result['destination']); $result['destination'] = str_replace($result['email_full'], '', $result['destination']);
$stmt = Database::prepare(" $stmt = Database::prepare("
UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `destination` = :dest, `popaccountid` = '0' WHERE `customerid`= :cid AND `id`= :id UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `destination` = :dest, `popaccountid` = '0' WHERE `customerid`= :cid AND `id`= :id
"); ");
@@ -422,24 +457,24 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
); );
Database::pexecute($stmt, $params, true, true); Database::pexecute($stmt, $params, true, true);
$result['popaccountid'] = 0; $result['popaccountid'] = 0;
if (Settings::Get('system.mail_quota_enabled') == '1' && $customer['email_quota'] != '-1') { if (Settings::Get('system.mail_quota_enabled') == '1' && $customer['email_quota'] != '-1') {
$quota = (int) $result['quota']; $quota = (int) $result['quota'];
} else { } else {
$quota = 0; $quota = 0;
} }
if ($delete_userfiles) { if ($delete_userfiles) {
inserttask('7', $customer['loginname'], $result['email_full']); inserttask('7', $customer['loginname'], $result['email_full']);
} }
// decrease usage for customer // decrease usage for customer
Customers::decreaseUsage($customer['customerid'], 'email_accounts_used'); Customers::decreaseUsage($customer['customerid'], 'email_accounts_used');
Customers::decreaseUsage($customer['customerid'], 'email_quota_used', '', $quota); Customers::decreaseUsage($customer['customerid'], 'email_quota_used', '', $quota);
// decrease admin usage // decrease admin usage
Admins::decreaseUsage($customer['adminid'], 'email_accounts_used'); Admins::decreaseUsage($customer['adminid'], 'email_accounts_used');
Admins::decreaseUsage($customer['adminid'], 'email_quota_used', '', $quota); Admins::decreaseUsage($customer['adminid'], 'email_quota_used', '', $quota);
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email account for '" . $result['email_full'] . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email account for '" . $result['email_full'] . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }

View File

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

View File

@@ -28,8 +28,10 @@ class Emails extends ApiCommand implements ResourceEntity
* @param boolean $iscatchall * @param boolean $iscatchall
* optional, make this address a catchall address, default: no * optional, make this address a catchall address, default: no
* @param int $customerid * @param int $customerid
* optional, required when called as admin/reseller * optional, admin-only, the customer-id
* * @param string $loginname
* optional, admin-only, the loginname
*
* @access admin, customer * @access admin, customer
* @throws Exception * @throws Exception
* @return array * @return array
@@ -39,22 +41,22 @@ class Emails extends ApiCommand implements ResourceEntity
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new Exception("You cannot access this resource", 405);
} }
if ($this->getUserDetail('emails_used') < $this->getUserDetail('emails') || $this->getUserDetail('emails') == '-1') { if ($this->getUserDetail('emails_used') < $this->getUserDetail('emails') || $this->getUserDetail('emails') == '-1') {
// required parameters // required parameters
$email_part = $this->getParam('email_part'); $email_part = $this->getParam('email_part');
$domain = $this->getParam('domain'); $domain = $this->getParam('domain');
// parameters // parameters
$iscatchall = $this->getParam('iscatchall', true, 0); $iscatchall = $this->getParam('iscatchall', true, 0);
// validation // validation
if (substr($domain, 0, 4) != 'xn--') { if (substr($domain, 0, 4) != 'xn--') {
$idna_convert = new idna_convert_wrapper(); $idna_convert = new idna_convert_wrapper();
$domain = $idna_convert->encode(validate($domain, 'domain', '', '', array(), true)); $domain = $idna_convert->encode(validate($domain, 'domain', '', '', array(), true));
} }
// check domain and whether it's an email-enabled domain // check domain and whether it's an email-enabled domain
$domain_check = $this->apiCall('SubDomains.get', array( $domain_check = $this->apiCall('SubDomains.get', array(
'domainname' => $domain 'domainname' => $domain
@@ -62,11 +64,11 @@ class Emails extends ApiCommand implements ResourceEntity
if ($domain_check['isemaildomain'] == 0) { if ($domain_check['isemaildomain'] == 0) {
standard_error('maindomainnonexist', $domain, true); standard_error('maindomainnonexist', $domain, true);
} }
if (Settings::Get('catchall.catchall_enabled') != '1') { if (Settings::Get('catchall.catchall_enabled') != '1') {
$iscatchall = 0; $iscatchall = 0;
} }
// check for catchall-flag // check for catchall-flag
if ($iscatchall) { if ($iscatchall) {
$iscatchall = '1'; $iscatchall = '1';
@@ -75,18 +77,18 @@ class Emails extends ApiCommand implements ResourceEntity
$iscatchall = '0'; $iscatchall = '0';
$email = $email_part . '@' . $domain; $email = $email_part . '@' . $domain;
} }
// full email value // full email value
$email_full = $email_part . '@' . $domain; $email_full = $email_part . '@' . $domain;
// validate it // validate it
if (! validateEmail($email_full)) { if (! validateEmail($email_full)) {
standard_error('emailiswrong', $email_full, true); standard_error('emailiswrong', $email_full, true);
} }
// get needed customer info to reduce the email-address-counter by one // get needed customer info to reduce the email-address-counter by one
$customer = $this->getCustomerData('emails'); $customer = $this->getCustomerData('emails');
// duplicate check // duplicate check
$stmt = Database::prepare(" $stmt = Database::prepare("
SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid` FROM `" . TABLE_MAIL_VIRTUAL . "` SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid` FROM `" . TABLE_MAIL_VIRTUAL . "`
@@ -99,13 +101,13 @@ class Emails extends ApiCommand implements ResourceEntity
"cid" => $customer['customerid'] "cid" => $customer['customerid']
); );
$email_check = Database::pexecute_first($stmt, $params, true, true); $email_check = Database::pexecute_first($stmt, $params, true, true);
if (strtolower($email_check['email_full']) == strtolower($email_full)) { if (strtolower($email_check['email_full']) == strtolower($email_full)) {
standard_error('emailexistalready', $email_full, true); standard_error('emailexistalready', $email_full, true);
} elseif ($email_check['email'] == $email) { } elseif ($email_check['email'] == $email) {
standard_error('youhavealreadyacatchallforthisdomain', '', true); standard_error('youhavealreadyacatchallforthisdomain', '', true);
} }
$stmt = Database::prepare(" $stmt = Database::prepare("
INSERT INTO `" . TABLE_MAIL_VIRTUAL . "` SET INSERT INTO `" . TABLE_MAIL_VIRTUAL . "` SET
`customerid` = :cid, `customerid` = :cid,
@@ -122,15 +124,15 @@ class Emails extends ApiCommand implements ResourceEntity
"domainid" => $domain_check['id'] "domainid" => $domain_check['id']
); );
Database::pexecute($stmt, $params, true, true); Database::pexecute($stmt, $params, true, true);
// update customer usage // update customer usage
Customers::increaseUsage($customer['customerid'], 'emails_used'); Customers::increaseUsage($customer['customerid'], 'emails_used');
// update admin usage // update admin usage
Admins::increaseUsage($customer['adminid'], 'emails_used'); Admins::increaseUsage($customer['adminid'], 'emails_used');
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] added email address '" . $email_full . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] added email address '" . $email_full . "'");
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'emailaddr' => $email_full 'emailaddr' => $email_full
)); ));
@@ -156,15 +158,15 @@ class Emails extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true); $ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, ''); $emailaddr = $this->getParam('emailaddr', $ea_optional, '');
$params = array(); $params = array();
$customer_ids = $this->getAllowedCustomerIds('email'); $customer_ids = $this->getAllowedCustomerIds('email');
$params['idea'] = ($id <= 0 ? $emailaddr : $id); $params['idea'] = ($id <= 0 ? $emailaddr : $id);
$result_stmt = Database::prepare("SELECT v.`id`, v.`email`, v.`email_full`, v.`iscatchall`, v.`destination`, v.`customerid`, v.`popaccountid`, v.`domainid`, u.`quota` $result_stmt = Database::prepare("SELECT v.`id`, v.`email`, v.`email_full`, v.`iscatchall`, v.`destination`, v.`customerid`, v.`popaccountid`, v.`domainid`, u.`quota`
FROM `" . TABLE_MAIL_VIRTUAL . "` v FROM `" . TABLE_MAIL_VIRTUAL . "` v
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id` LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id`
WHERE v.`customerid` IN (".implode(", ", $customer_ids).") WHERE v.`customerid` IN (" . implode(", ", $customer_ids) . ")
AND (v.`id`= :idea OR (v.`email` = :idea OR v.`email_full` = :idea)) AND (v.`id`= :idea OR (v.`email` = :idea OR v.`email_full` = :idea))
"); ");
$result = Database::pexecute_first($result_stmt, $params, true, true); $result = Database::pexecute_first($result_stmt, $params, true, true);
@@ -180,13 +182,15 @@ class Emails extends ApiCommand implements ResourceEntity
* toggle catchall flag of given email address either by id or email-address * toggle catchall flag of given email address either by id or email-address
* *
* @param int $id * @param int $id
* optional, the customer-id * optional, the email-address-id
* @param string $emailaddr * @param string $emailaddr
* optional, the email-address * optional, the email-address
* @param int $customerid
* optional, admin-only, the customer-id
* @param string $loginname
* optional, admin-only, the loginname
* @param boolean $iscatchall * @param boolean $iscatchall
* optional * optional
* @param int $customerid
* optional, required when called as admin/reseller
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws Exception
@@ -197,7 +201,7 @@ class Emails extends ApiCommand implements ResourceEntity
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new Exception("You cannot access this resource", 405);
} }
// if enabling catchall is not allowed by settings, we do not need // if enabling catchall is not allowed by settings, we do not need
// to run update() // to run update()
if (Settings::Get('catchall.catchall_enabled') != '1') { if (Settings::Get('catchall.catchall_enabled') != '1') {
@@ -206,23 +210,23 @@ class Emails extends ApiCommand implements ResourceEntity
'featureisdisabled' 'featureisdisabled'
), 'catchall', true); ), 'catchall', true);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true); $ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, ''); $emailaddr = $this->getParam('emailaddr', $ea_optional, '');
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'id' => $id, 'id' => $id,
'emailaddr' => $emailaddr 'emailaddr' => $emailaddr
)); ));
$id = $result['id']; $id = $result['id'];
// parameters // parameters
$iscatchall = $this->getParam('iscatchall', true, $result['iscatchall']); $iscatchall = $this->getParam('iscatchall', true, $result['iscatchall']);
// get needed customer info to reduce the email-address-counter by one // get needed customer info to reduce the email-address-counter by one
$customer = $this->getCustomerData(); $customer = $this->getCustomerData();
// check for catchall-flag // check for catchall-flag
if ($iscatchall) { if ($iscatchall) {
$iscatchall = '1'; $iscatchall = '1';
@@ -232,7 +236,7 @@ class Emails extends ApiCommand implements ResourceEntity
$iscatchall = '0'; $iscatchall = '0';
$email = $result['email_full']; $email = $result['email_full'];
} }
$stmt = Database::prepare(" $stmt = Database::prepare("
UPDATE `" . TABLE_MAIL_VIRTUAL . "` UPDATE `" . TABLE_MAIL_VIRTUAL . "`
SET `email` = :email , `iscatchall` = :caflag SET `email` = :email , `iscatchall` = :caflag
@@ -246,7 +250,7 @@ class Emails extends ApiCommand implements ResourceEntity
); );
Database::pexecute($stmt, $params, true, true); Database::pexecute($stmt, $params, true, true);
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] toggled catchall-flag for email address '" . $result['email_full'] . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] toggled catchall-flag for email address '" . $result['email_full'] . "'");
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'emailaddr' => $result['email_full'] 'emailaddr' => $result['email_full']
)); ));
@@ -257,9 +261,9 @@ class Emails extends ApiCommand implements ResourceEntity
* list all email addresses, if called from an admin, list all email addresses of all customers you are allowed to view, or specify id or loginname for one specific customer * list all email addresses, if called from an admin, list all email addresses of all customers you are allowed to view, or specify id or loginname for one specific customer
* *
* @param int $customerid * @param int $customerid
* optional, admin-only, select ftp-users of a specific customer by id * optional, admin-only, select email addresses of a specific customer by id
* @param string $loginname * @param string $loginname
* optional, admin-only, select ftp-users of a specific customer by loginname * optional, admin-only, select email addresses of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws Exception
@@ -274,7 +278,7 @@ class Emails extends ApiCommand implements ResourceEntity
FROM `" . TABLE_MAIL_VIRTUAL . "` m FROM `" . TABLE_MAIL_VIRTUAL . "` m
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON (m.`domainid` = d.`id`) LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON (m.`domainid` = d.`id`)
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON (m.`popaccountid` = u.`id`) LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON (m.`popaccountid` = u.`id`)
WHERE m.`customerid` IN (".implode(", ", $customer_ids).") WHERE m.`customerid` IN (" . implode(", ", $customer_ids) . ")
"); ");
Database::pexecute($result_stmt, null, true, true); Database::pexecute($result_stmt, null, true, true);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
@@ -291,13 +295,15 @@ class Emails extends ApiCommand implements ResourceEntity
* delete an email address by either id or username * delete an email address by either id or username
* *
* @param int $id * @param int $id
* optional, the customer-id * optional, the email-address-id
* @param string $emailaddr * @param string $emailaddr
* optional, the email-address * optional, the email-address
* @param boolean $delete_userfiles
* optional, delete email data from filesystem, default: no
* @param int $customerid * @param int $customerid
* optional, required when called as admin/reseller * optional, admin-only, the customer-id
* @param string $loginname
* optional, admin-only, the loginname
* @param boolean $delete_userfiles
* optional, delete email data from filesystem, default: 0 (false)
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws Exception
@@ -308,23 +314,23 @@ class Emails extends ApiCommand implements ResourceEntity
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new Exception("You cannot access this resource", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
$ea_optional = ($id <= 0 ? false : true); $ea_optional = ($id <= 0 ? false : true);
$emailaddr = $this->getParam('emailaddr', $ea_optional, ''); $emailaddr = $this->getParam('emailaddr', $ea_optional, '');
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
'id' => $id, 'id' => $id,
'emailaddr' => $emailaddr 'emailaddr' => $emailaddr
)); ));
$id = $result['id']; $id = $result['id'];
// parameters // parameters
$delete_userfiles = $this->getParam('delete_userfiles', true, 0); $delete_userfiles = $this->getParam('delete_userfiles', true, 0);
// get needed customer info to reduce the email-address-counter by one // get needed customer info to reduce the email-address-counter by one
$customer = $this->getCustomerData(); $customer = $this->getCustomerData();
// check for forwarders // check for forwarders
$number_forwarders = 0; $number_forwarders = 0;
if ($result['destination'] != '') { if ($result['destination'] != '') {
@@ -355,15 +361,15 @@ class Emails extends ApiCommand implements ResourceEntity
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email account '" . $result['email_full'] . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email account '" . $result['email_full'] . "'");
$number_forwarders --; $number_forwarders --;
} }
// decrease forwarder counter // decrease forwarder counter
Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders); Customers::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders);
Admins::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders); Admins::decreaseUsage($customer['customerid'], 'email_forwarders_used', '', $number_forwarders);
if ($delete_userfiles) { if ($delete_userfiles) {
inserttask('7', $customer['loginname'], $result['email_full']); inserttask('7', $customer['loginname'], $result['email_full']);
} }
// delete address // delete address
$stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`= :customerid AND `id`= :id"); $stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`= :customerid AND `id`= :id");
Database::pexecute($stmt, array( Database::pexecute($stmt, array(
@@ -372,7 +378,7 @@ class Emails extends ApiCommand implements ResourceEntity
), true, true); ), true, true);
Customers::decreaseUsage($customer['customerid'], 'emails_used'); Customers::decreaseUsage($customer['customerid'], 'emails_used');
Admins::decreaseUsage($customer['customerid'], 'emails_used'); Admins::decreaseUsage($customer['customerid'], 'emails_used');
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email address '" . $result['email_full'] . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] deleted email address '" . $result['email_full'] . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }