diff --git a/data/web/edit.php b/data/web/edit.php index b7f65e407..8eaae6af1 100644 --- a/data/web/edit.php +++ b/data/web/edit.php @@ -673,17 +673,27 @@ if (isset($_SESSION['mailcow_cc_role'])) { elseif (isset($_GET['recipient_map']) && !empty($_GET["recipient_map"])) { $map = intval($_GET["recipient_map"]); $result = recipient_map('details', $map); + if (substr($result['recipient_map_old'], 0, 1) == '@') { + $result['recipient_map_old'] = substr($result['recipient_map_old'], 1); + } if (!empty($result)) { ?> -

Recipient map:

+

:


- +
- - Recipient map destinations can only be valid email addresses. Separated by whitespace, semicolon, new line or comma. + + +
+
+
+ +
+ +
diff --git a/data/web/inc/functions.address_rewriting.inc.php b/data/web/inc/functions.address_rewriting.inc.php index ce2cf5787..4f7f624b6 100644 --- a/data/web/inc/functions.address_rewriting.inc.php +++ b/data/web/inc/functions.address_rewriting.inc.php @@ -290,15 +290,11 @@ function recipient_map($_action, $_data = null, $attr = null) { switch ($_action) { case 'add': $old_dest = strtolower(trim($_data['recipient_map_old'])); - $new_dest = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['recipient_map_new'])); - $active = intval($_data['active']); - if (empty($new_dest)) { - $_SESSION['return'] = array( - 'type' => 'danger', - 'msg' => 'Recipient map destination cannot be empty' - ); - return false; + if (substr($old_dest, 0, 1) == '@') { + $old_dest = substr($old_dest, 1); } + $new_dest = strtolower(trim($_data['recipient_map_new'])); + $active = intval($_data['active']); if (is_valid_domain_name($old_dest)) { $old_dest_sane = '@' . idn_to_ascii($old_dest); } @@ -308,42 +304,25 @@ function recipient_map($_action, $_data = null, $attr = null) { else { $_SESSION['return'] = array( 'type' => 'danger', - 'msg' => 'Invalid original recipient specified: ' . $old_dest + 'msg' => sprintf($lang['danger']['invalid_recipient_map_old'], htmlspecialchars($old_dest)) ); return false; } - foreach ($new_dest as &$new_dest_e) { - if (!filter_var($new_dest_e, FILTER_VALIDATE_EMAIL)) { - $new_dest_e = null; - } - $new_dest_e = strtolower($new_dest_e); - } - $new_dest = array_filter($new_dest); - $new_dest = implode(",", $new_dest); - if (empty($new_dest)) { + if (!filter_var($new_dest, FILTER_VALIDATE_EMAIL)) { $_SESSION['return'] = array( 'type' => 'danger', - 'msg' => 'Recipient map destination cannot be empty' + 'msg' => sprintf($lang['danger']['invalid_recipient_map_new'], htmlspecialchars($new_dest)) ); return false; } - try { - $stmt = $pdo->prepare("SELECT `id` FROM `recipient_maps` - WHERE `old_dest` = :old_dest"); - $stmt->execute(array(':old_dest' => $old_dest_sane)); - $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC)); + $rmaps = recipient_map('get'); + foreach ($rmaps as $rmap) { + $old_dests_existing[] = recipient_map('details', $rmap)['recipient_map_old']; } - catch(PDOException $e) { + if (in_array($old_dest_sane, $old_dests_existing)) { $_SESSION['return'] = array( 'type' => 'danger', - 'msg' => 'MySQL: '.$e - ); - return false; - } - if ($num_results != 0) { - $_SESSION['return'] = array( - 'type' => 'danger', - 'msg' => 'A Recipient map entry "' . htmlspecialchars($old_dest_sane) . '" exists' + 'msg' => sprintf($lang['danger']['recipient_map_entry_exists'], htmlspecialchars($old_dest)) ); return false; } @@ -365,7 +344,7 @@ function recipient_map($_action, $_data = null, $attr = null) { } $_SESSION['return'] = array( 'type' => 'success', - 'msg' => 'Recipient map entry saved' + 'msg' => sprintf($lang['success']['recipient_map_entry_saved'], htmlspecialchars($old_dest_sane)) ); break; case 'edit': @@ -375,7 +354,10 @@ function recipient_map($_action, $_data = null, $attr = null) { if (!empty($is_now)) { $active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int']; $new_dest = (!empty($_data['recipient_map_new'])) ? $_data['recipient_map_new'] : $is_now['recipient_map_new']; - $old_dest = $is_now['old_dest']; + $old_dest = (!empty($_data['recipient_map_old'])) ? $_data['recipient_map_old'] : $is_now['recipient_map_old']; + if (substr($old_dest, 0, 1) == '@') { + $old_dest = substr($old_dest, 1); + } } else { $_SESSION['return'] = array( @@ -384,46 +366,47 @@ function recipient_map($_action, $_data = null, $attr = null) { ); return false; } - $new_dest = array_map('trim', preg_split( "/( |,|;|\n)/", $new_dest)); + if (is_valid_domain_name($old_dest)) { + $old_dest_sane = '@' . idn_to_ascii($old_dest); + } + elseif (filter_var($old_dest, FILTER_VALIDATE_EMAIL)) { + $old_dest_sane = $old_dest; + } + else { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => sprintf($lang['danger']['invalid_recipient_map_old'], htmlspecialchars($old_dest)) + ); + return false; + } $active = intval($_data['active']); - foreach ($new_dest as &$new_dest_e) { - if (!filter_var($new_dest_e, FILTER_VALIDATE_EMAIL)) { - $new_dest_e = null;; - } - $new_dest_e = strtolower($new_dest_e); - } - $new_dest = array_filter($new_dest); - $new_dest = implode(",", $new_dest); - if (empty($new_dest)) { + if (!filter_var($new_dest, FILTER_VALIDATE_EMAIL)) { $_SESSION['return'] = array( 'type' => 'danger', - 'msg' => 'Recipient map destination cannot be empty' + 'msg' => sprintf($lang['danger']['invalid_recipient_map_new'], htmlspecialchars($new_dest)) ); return false; } + $rmaps = recipient_map('get'); + foreach ($rmaps as $rmap) { + $old_dests_existing[] = recipient_map('details', $rmap)['recipient_map_old']; + } + if (in_array($old_dest_sane, $old_dests_existing) && + recipient_map('details', $id)['recipient_map_old'] != $old_dest_sane) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => sprintf($lang['danger']['recipient_map_entry_exists'], htmlspecialchars($old_dest_sane)) + ); + return false; + } try { - $stmt = $pdo->prepare("SELECT `id` FROM `recipient_maps` - WHERE `old_dest` = :old_dest"); - $stmt->execute(array(':old_dest' => $old_dest)); - $id_now = $stmt->fetch(PDO::FETCH_ASSOC)['id']; - } - catch(PDOException $e) { - $_SESSION['return'] = array( - 'type' => 'danger', - 'msg' => 'MySQL: '.$e - ); - return false; - } - if (isset($id_now) && $id_now != $id) { - $_SESSION['return'] = array( - 'type' => 'danger', - 'msg' => 'A Recipient map entry ' . htmlspecialchars($old_dest) . ' exists' - ); - return false; - } - try { - $stmt = $pdo->prepare("UPDATE `recipient_maps` SET `new_dest` = :new_dest, `active` = :active WHERE `id`= :id"); + $stmt = $pdo->prepare("UPDATE `recipient_maps` SET + `old_dest` = :old_dest, + `new_dest` = :new_dest, + `active` = :active + WHERE `id`= :id"); $stmt->execute(array( + ':old_dest' => $old_dest_sane, ':new_dest' => $new_dest, ':active' => $active, ':id' => $id @@ -439,7 +422,7 @@ function recipient_map($_action, $_data = null, $attr = null) { } $_SESSION['return'] = array( 'type' => 'success', - 'msg' => 'Recipient map entry edited' + 'msg' => sprintf($lang['success']['recipient_map_entry_saved'], htmlspecialchars($old_dest)) ); break; case 'details': @@ -507,7 +490,7 @@ function recipient_map($_action, $_data = null, $attr = null) { } $_SESSION['return'] = array( 'type' => 'success', - 'msg' => 'Deleted Recipient map id/s ' . implode(', ', $ids) + 'msg' => sprintf($lang['success']['recipient_map_entry_deleted'], htmlspecialchars($old_dest)) ); return true; break; diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php index 3afe66a06..c918c378d 100644 --- a/data/web/lang/lang.de.php +++ b/data/web/lang/lang.de.php @@ -553,9 +553,18 @@ $lang['mailbox']['add_bcc_entry'] = "BCC-Eintrag hinzufügen"; $lang['mailbox']['bcc_info'] = "Eine empfängerabhängige Map wird verwendet, wenn die BCC-Map Eintragung auf den Eingang einer E-Mail auf das lokale Ziel reagieren soll. Senderabhängige Maps verfahren nach dem gleichen Prinzip.
Das lokale Ziel wird bei Fehlzustellungen an ein BCC-Ziel nicht informiert."; $lang['mailbox']['address_rewriting'] = 'Adressumschreibung'; + $lang['mailbox']['recipient_maps'] = 'Empfängerumschreibungen'; +$lang['mailbox']['recipient_map'] = 'Empfängerumschreibung'; $lang['mailbox']['recipient_map_info'] = 'Empfängerumschreibung ersetzen den Empfänger einer E-Mail vor dem Versand.'; +$lang['mailbox']['recipient_map_old_info'] = 'Der originale Empfänger muss eine E-Mail-Adresse oder ein Domainname sein.'; +$lang['mailbox']['recipient_map_new_info'] = 'Der neue Empfänger muss eine E-Mail-Adresse sein.'; $lang['mailbox']['recipient_map_old'] = 'Original Empfänger'; $lang['mailbox']['recipient_map_new'] = 'Neuer Empfänger'; $lang['mailbox']['add_recipient_map_entry'] = 'Empfängerumschreibung hinzufügen'; -$lang['mailbox']['add_sender_map_entry'] = 'Senderumschreibung hinzufügen'; +$lang['danger']['invalid_recipient_map_new'] = 'Neuer Empfänger %s ist ungültig'; +$lang['danger']['invalid_recipient_map_old'] = 'Originaler Empfänger %s ist ungültig'; +$lang['danger']['recipient_map_entry_exists'] = 'Eine Empfängerumschreibung für %s existiert bereits'; +$lang['success']['recipient_map_entry_saved'] = 'Empfängerumschreibung für Objekt %s wurde gespeichert'; +$lang['success']['recipient_map_entry_deleted'] = 'Empfängerumschreibung für Objekt %s wurde gelöscht'; + diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php index 6ad8b27e8..aa8c2a97f 100644 --- a/data/web/lang/lang.en.php +++ b/data/web/lang/lang.en.php @@ -560,11 +560,18 @@ $lang['mailbox']['bcc_info'] = "BCC maps are used to silently forward copies of The local destination will not be informed about a failed delivery."; $lang['mailbox']['address_rewriting'] = 'Address rewriting'; $lang['mailbox']['recipient_maps'] = 'Recipient maps'; +$lang['mailbox']['recipient_map'] = 'Recipient map'; $lang['mailbox']['recipient_map_info'] = 'Recipient maps are used to replace the destination address on a message before it is delivered.'; +$lang['mailbox']['recipient_map_old_info'] = 'A recipient maps original destination must be valid email addresses or a domain name.'; +$lang['mailbox']['recipient_map_new_info'] = 'Recipient map destination must be a valid email address.'; $lang['mailbox']['recipient_map_old'] = 'Original recipient'; $lang['mailbox']['recipient_map_new'] = 'New recipient'; +$lang['danger']['invalid_recipient_map_new'] = 'Invalid new recipient specified: %s'; +$lang['danger']['invalid_recipient_map_old'] = 'Invalid original recipient specified: %s'; +$lang['danger']['recipient_map_entry_exists'] = 'A Recipient map entry for %s exists'; +$lang['success']['recipient_map_entry_saved'] = 'Recipient map entry for %s has been saved'; +$lang['success']['recipient_map_entry_deleted'] = 'Recipient map entry for %s has been deleted'; $lang['mailbox']['add_recipient_map_entry'] = 'Add recipient map'; -$lang['mailbox']['add_sender_map_entry'] = 'Add sender map'; $lang['oauth2']['scope_ask_permission'] = 'An application asked for the following permissions'; $lang['oauth2']['profile'] = 'Profile'; diff --git a/data/web/modals/mailbox.php b/data/web/modals/mailbox.php index 51d857a0a..57ca822a9 100644 --- a/data/web/modals/mailbox.php +++ b/data/web/modals/mailbox.php @@ -614,17 +614,19 @@ if (!isset($_SESSION['mailcow_cc_role'])) {