From 90766b88cfc2e79bc606c06d0ef1596f6589e38a Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sat, 25 Dec 2010 14:11:16 +0000 Subject: [PATCH] create-alias: support multiple alias targets - support multiple alias targets, patch by anexius@SF, http://sourceforge.net/projects/postfixadmin/forums/forum/676076/topic/4004442 The patch fixes https://sourceforge.net/tracker/?func=detail&aid=2706290&group_id=191583&atid=937964 additional small fixes: - replace spaces only at the start and end of a line, not in the middle of an (BTW: invalid) mail address - allow multiple error messages (separated by
- prevent input data loss on validation errors (I'll port this to trunk.) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/branches/postfixadmin-2.3@898 a1433add-5e2c-0410-b055-b7f2511e0802 --- create-alias.php | 49 ++++++++++++++++++++++++++++++++++---- templates/create-alias.php | 3 +-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/create-alias.php b/create-alias.php index 632da73f..24e72ecb 100644 --- a/create-alias.php +++ b/create-alias.php @@ -75,9 +75,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $fDomain = escape_string ($_POST['fDomain']); } - if(!preg_match ('/@/',$fGoto)) { - $fGoto = $fGoto . "@" . escape_string ($_POST['fDomain']); - } +# TODO: Doesn't work with multiple aliases - fix or discard... +# if(!preg_match ('/@/',$fGoto)) { +# $fGoto = $fGoto . "@" . escape_string ($_POST['fDomain']); +# } if(!(authentication_has_role('global-admin') || check_owner ($SESSID_USERNAME, $fDomain) )) @@ -105,7 +106,42 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1']; } - if (empty($fGoto) || !check_email ($fGoto)) { + // Begin check alias email + $goto = preg_replace ('/\\\r\\\n/', ',', $fGoto); + $goto = preg_replace ('/\r\n/', ',', $goto); + $goto = preg_replace ('/,[\s]+/i', ',', $goto); + $goto = preg_replace ('/[\s]+,/i', ',', $goto); + $goto = preg_replace ('/,*$|^,*/', '', $goto); + $goto = preg_replace ('/,,*/', ',', $goto); + + if (empty ($goto) && !authentication_has_role('global-admin')) { + $error = 1; + $tGoto = $_POST['fGoto']; + $tMessage = $PALANG['pEdit_alias_goto_text_error1']; + } + + $new_aliases = array(); + if ($error != 1) { + $new_aliases = explode(',', $goto); + } + $new_aliases = array_unique($new_aliases); + + foreach($new_aliases as $address) { + if (in_array($address, $CONF['default_aliases'])) continue; + if (empty($address)) continue; # TODO: should never happen - remove after 2.2 release + if (!check_email($address)) { + $error = 1; + $tGoto = $goto; + if (!empty($tMessage)) $tMessage .= "
"; + $tMessage .= $PALANG['pEdit_alias_goto_text_error2'] . "$address"; + } + } + + $goto = implode(',', $new_aliases); + $fGoto = escape_string($goto); + // End check alias mail + + if (empty($fGoto)) { $error = 1; $tAddress = escape_string ($_POST['fAddress']); $tGoto = $fGoto; @@ -150,6 +186,11 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $tDomain = $fDomain; $tMessage = $PALANG['pCreate_alias_result_success'] . "
($fAddress -> $fGoto)
\n"; } + } else { # on error + $tAddress = htmlentities($_POST['fAddress']); + $tGoto = htmlentities($_POST['fGoto']); + $tDomain = htmlentities($_POST['fDomain']); + } } diff --git a/templates/create-alias.php b/templates/create-alias.php index d2f32632..f57f4e35 100644 --- a/templates/create-alias.php +++ b/templates/create-alias.php @@ -30,8 +30,7 @@ - - +