From f9740ff5455a28f2e514cfda4fa077bef7671b98 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Thu, 10 Mar 2016 10:54:32 +0100 Subject: [PATCH] check whether an email account is to be deleted when re-adding an email account with the same name, fixes #1519 Signed-off-by: Michael Kaufmann (d00p) --- customer_email.php | 16 ++++--- .../function.checkMailAccDeletionState.php | 43 +++++++++++++++++++ lng/english.lng.php | 1 + lng/german.lng.php | 1 + 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 lib/functions/froxlor/function.checkMailAccDeletionState.php diff --git a/customer_email.php b/customer_email.php index 5ec678b4..2ace4ad5 100644 --- a/customer_email.php +++ b/customer_email.php @@ -412,10 +412,11 @@ if ($page == 'overview') { standard_error('notallowedtouseaccounts'); } - $stmt = Database::prepare("SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid`, `popaccountid`, `domainid` FROM `" . TABLE_MAIL_VIRTUAL . "` - WHERE `customerid`= :cid - AND `id`= :id" - ); + $stmt = Database::prepare(" + SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid`, `popaccountid`, `domainid` + FROM `" . TABLE_MAIL_VIRTUAL . "` + WHERE `customerid`= :cid AND `id`= :id + "); $result = Database::pexecute_first($stmt, array("cid" => $userinfo['customerid'], "id" => $id)); if (isset($result['email']) && $result['email'] != '' && $result['popaccountid'] == '0') { @@ -595,7 +596,7 @@ if ($page == 'overview') { if ($_mailerror) { $log->logAction(USR_ACTION, LOG_ERR, "Error sending mail: " . $mailerr_msg); - standard_error(array('errorsendingmail', $alternative_email)); + standard_error(array('errorsendingmail'), $alternative_email); } $mail->ClearAddresses(); @@ -604,6 +605,11 @@ if ($page == 'overview') { redirectTo($filename, array('page' => 'emails', 'action' => 'edit', 'id' => $id, 's' => $s)); } } else { + + if (checkMailAccDeletionState($result['email_full'])) { + standard_error(array('mailaccistobedeleted'), $result['email_full']); + } + $result['email_full'] = $idna_convert->decode($result['email_full']); $result = htmlentities_array($result); $quota = Settings::Get('system.mail_quota'); diff --git a/lib/functions/froxlor/function.checkMailAccDeletionState.php b/lib/functions/froxlor/function.checkMailAccDeletionState.php new file mode 100644 index 00000000..ea73da63 --- /dev/null +++ b/lib/functions/froxlor/function.checkMailAccDeletionState.php @@ -0,0 +1,43 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Functions + * + */ + +/** + * check whether an email account is to be deleted + * reference: #1519 + * + * @return bool true if the domain is to be deleted, false otherwise + * + */ +function checkMailAccDeletionState($email_addr = null) +{ + // example data of task 7: a:2:{s:9:"loginname";s:4:"webX";s:5:"email";s:20:"deleteme@example.tld";} + + // check for task + $result_tasks_stmt = Database::prepare(" + SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '7' AND `data` LIKE :emailaddr + "); + Database::pexecute($result_tasks_stmt, array( + 'emailaddr' => "%" . $email_addr . "%" + )); + $num_results = Database::num_rows(); + + // is there a task for deleting this email account? + if ($num_results > 0) { + return true; + } + return false; +} diff --git a/lng/english.lng.php b/lng/english.lng.php index 226a3d40..de848e18 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1973,3 +1973,4 @@ $lng['domains']['termination_date'] = 'Date of termination'; $lng['domains']['termination_date_overview'] = 'canceled until '; $lng['panel']['set'] = 'Apply'; $lng['customer']['selectserveralias_addinfo'] = 'This option can be set when editing the domain. Its initial value is inherited from the parent-domain.'; +$lng['error']['mailaccistobedeleted'] = "Another account with the same name (%s) is currently being deleted and can therefore not be added at this moment."; diff --git a/lng/german.lng.php b/lng/german.lng.php index 6423a18c..c76c4980 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1626,3 +1626,4 @@ $lng['domains']['termination_date'] = 'Kündigungsdatum'; $lng['domains']['termination_date_overview'] = 'gekündigt zum '; $lng['panel']['set'] = 'Setzen'; $lng['customer']['selectserveralias_addinfo'] = 'Diese Option steht beim Bearbeiten der Domain zur Verfügung. Als Initial-Wert wird die Einstellung der Hauptdomain vererbt.'; +$lng['error']['mailaccistobedeleted'] = "Ein vorheriges Konto mit dem gleichen Namen (%s) wird aktuell noch gelöscht und kann daher derzeit nicht angelegt werden";