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 <br />
- 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
postfixadmin-2.3
Christian Boltz 14 years ago
parent 0c6f5c6d8c
commit 90766b88cf

@ -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 .= "<br />";
$tMessage .= $PALANG['pEdit_alias_goto_text_error2'] . "$address</span>";
}
}
$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'] . "<br />($fAddress -> $fGoto)<br />\n";
}
} else { # on error
$tAddress = htmlentities($_POST['fAddress']);
$tGoto = htmlentities($_POST['fGoto']);
$tDomain = htmlentities($_POST['fDomain']);
}
}

@ -30,8 +30,7 @@
</tr>
<tr>
<td><?php print $PALANG['pCreate_alias_goto'] . ":"; ?></td>
<td><input class="flat" type="text" name="fGoto" value="<?php print $tGoto; ?>" /></td>
<td><?php print $pCreate_alias_goto_text; ?></td>
<td colspan="2"><textarea class="flat" rows="10" cols="60" name="fGoto"><?php print $tGoto; ?></textarea></td>
</tr>
<tr>
<td><?php print $PALANG['pCreate_alias_active'] . ":"; ?></td>

Loading…
Cancel
Save