From a0fbff53776ce6ab0a9128c936b47a347eb07e6b Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sat, 25 Dec 2010 14:26:00 +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 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@900 a1433add-5e2c-0410-b055-b7f2511e0802 --- create-alias.php | 50 ++++++++++++++++++++++++++++++++++---- templates/create-alias.tpl | 3 +-- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/create-alias.php b/create-alias.php index eed5bd1f..f4d2c80d 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,7 +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']); + } } $smarty->assign ('tAddress', $tAddress); diff --git a/templates/create-alias.tpl b/templates/create-alias.tpl index 197f8124..2c993a6a 100644 --- a/templates/create-alias.tpl +++ b/templates/create-alias.tpl @@ -15,8 +15,7 @@ {$PALANG.pCreate_alias_goto}: - - {$pCreate_alias_goto_text} + {$PALANG.pCreate_alias_active}: