Skip to content

Commit 40f6d69

Browse files
Fix #2752: Domain recipient for address rewrite
1 parent dc5a281 commit 40f6d69

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

data/web/inc/functions.address_rewriting.inc.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,13 @@ function recipient_map($_action, $_data = null, $attr = null) {
285285
);
286286
return false;
287287
}
288-
if (!filter_var($new_dest, FILTER_VALIDATE_EMAIL)) {
288+
if (is_valid_domain_name($new_dest)) {
289+
$new_dest_sane = '@' . idn_to_ascii($new_dest, 0, INTL_IDNA_VARIANT_UTS46);
290+
}
291+
elseif (filter_var($new_dest, FILTER_VALIDATE_EMAIL)) {
292+
$new_dest_sane = $new_dest;
293+
}
294+
else {
289295
$_SESSION['return'][] = array(
290296
'type' => 'danger',
291297
'log' => array(__FUNCTION__, $_action, $_data, $_attr),
@@ -308,7 +314,7 @@ function recipient_map($_action, $_data = null, $attr = null) {
308314
(:old_dest, :new_dest, :active)");
309315
$stmt->execute(array(
310316
':old_dest' => $old_dest_sane,
311-
':new_dest' => $new_dest,
317+
':new_dest' => $new_dest_sane,
312318
':active' => $active
313319
));
314320
$_SESSION['return'][] = array(
@@ -351,7 +357,13 @@ function recipient_map($_action, $_data = null, $attr = null) {
351357
);
352358
continue;
353359
}
354-
if (!filter_var($new_dest, FILTER_VALIDATE_EMAIL)) {
360+
if (is_valid_domain_name($new_dest)) {
361+
$new_dest_sane = '@' . idn_to_ascii($new_dest, 0, INTL_IDNA_VARIANT_UTS46);
362+
}
363+
elseif (filter_var($new_dest, FILTER_VALIDATE_EMAIL)) {
364+
$new_dest_sane = $new_dest;
365+
}
366+
else {
355367
$_SESSION['return'][] = array(
356368
'type' => 'danger',
357369
'log' => array(__FUNCTION__, $_action, $_data, $_attr),
@@ -378,7 +390,7 @@ function recipient_map($_action, $_data = null, $attr = null) {
378390
WHERE `id`= :id");
379391
$stmt->execute(array(
380392
':old_dest' => $old_dest_sane,
381-
':new_dest' => $new_dest,
393+
':new_dest' => $new_dest_sane,
382394
':active' => $active,
383395
':id' => $id
384396
));

0 commit comments

Comments
 (0)