[Web] Add feature for null mail

master
andryyy 2017-09-15 09:05:51 +02:00
parent edacce0329
commit dd3bd82838
8 changed files with 102 additions and 56 deletions

View File

@ -31,7 +31,10 @@ if (isset($_SESSION['mailcow_cc_role'])) {
<div class="form-group">
<label class="control-label col-sm-2" for="goto"><?=$lang['edit']['target_address'];?></label>
<div class="col-sm-10">
<textarea class="form-control" autocapitalize="none" autocorrect="off" rows="10" id="goto" name="goto"><?=htmlspecialchars($result['goto']) ?></textarea>
<textarea id="textarea_alias_goto" class="form-control" autocapitalize="none" autocorrect="off" rows="10" id="goto" name="goto" required><?= ($result['goto'] != "null@localhost") ? htmlspecialchars($result['goto']) : null; ?></textarea>
<div class="checkbox">
<label><input id="goto_null" type="checkbox" value="1" name="goto_null" <?= ($result['goto'] == "null@localhost") ? "checked" : null; ?>> <?=$lang['add']['goto_null'];?></label>
</div>
</div>
</div>
<div class="form-group">

View File

@ -324,6 +324,7 @@ function mailbox($_action, $_type, $_data = null) {
$addresses = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['address']));
$gotos = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['goto']));
$active = intval($_data['active']);
$goto_null = intval($_data['goto_null']);
if (empty($addresses[0])) {
$_SESSION['return'] = array(
'type' => 'danger',
@ -331,42 +332,47 @@ function mailbox($_action, $_type, $_data = null) {
);
return false;
}
if (empty($gotos[0])) {
if (empty($gotos[0]) && $goto_null == 0) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['goto_empty'])
);
return false;
}
foreach ($gotos as &$goto) {
if (empty($goto)) {
continue;
}
$goto_domain = idn_to_ascii(substr(strstr($goto, '@'), 1));
$goto_local_part = strstr($goto, '@', true);
$goto = $goto_local_part.'@'.$goto_domain;
$stmt = $pdo->prepare("SELECT `username` FROM `mailbox`
WHERE `kind` REGEXP 'location|thing|group'
AND `username`= :goto");
$stmt->execute(array(':goto' => $goto));
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
if ($num_results != 0) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['goto_invalid'])
);
return false;
}
if (!filter_var($goto, FILTER_VALIDATE_EMAIL) === true) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['goto_invalid'])
);
return false;
}
if ($goto_null == "1") {
$goto = "null@localhost";
}
else {
foreach ($gotos as &$goto) {
if (empty($goto)) {
continue;
}
$goto_domain = idn_to_ascii(substr(strstr($goto, '@'), 1));
$goto_local_part = strstr($goto, '@', true);
$goto = $goto_local_part.'@'.$goto_domain;
$stmt = $pdo->prepare("SELECT `username` FROM `mailbox`
WHERE `kind` REGEXP 'location|thing|group'
AND `username`= :goto");
$stmt->execute(array(':goto' => $goto));
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
if ($num_results != 0) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['goto_invalid'])
);
return false;
}
if (!filter_var($goto, FILTER_VALIDATE_EMAIL) === true) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['goto_invalid'])
);
return false;
}
}
$gotos = array_filter($gotos);
$goto = implode(",", $gotos);
}
$gotos = array_filter($gotos);
$goto = implode(",", $gotos);
foreach ($addresses as $address) {
if (empty($address)) {
continue;
@ -1385,6 +1391,7 @@ function mailbox($_action, $_type, $_data = null) {
$is_now = mailbox('get', 'alias_details', $address);
if (!empty($is_now)) {
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int'];
$goto_null = (isset($_data['goto_null'])) ? intval($_data['goto_null']) : $is_now['goto_null'];
$goto = (!empty($_data['goto'])) ? $_data['goto'] : $is_now['goto'];
}
else {
@ -1394,30 +1401,33 @@ function mailbox($_action, $_type, $_data = null) {
);
return false;
}
$gotos = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['goto']));
foreach ($gotos as &$goto) {
if (empty($goto)) {
continue;
}
if (!filter_var($goto, FILTER_VALIDATE_EMAIL)) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' =>sprintf($lang['danger']['goto_invalid'])
);
return false;
}
if ($goto == $address) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['alias_goto_identical'])
);
return false;
}
if ($goto_null == "1") {
$goto = "null@localhost";
}
else {
$gotos = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['goto']));
foreach ($gotos as &$goto) {
if (empty($goto)) {
continue;
}
if (!filter_var($goto, FILTER_VALIDATE_EMAIL)) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' =>sprintf($lang['danger']['goto_invalid'])
);
return false;
}
if ($goto == $address) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['alias_goto_identical'])
);
return false;
}
}
$gotos = array_filter($gotos);
$goto = implode(",", $gotos);
}
$gotos = array_filter($gotos);
$goto = implode(",", $gotos);
$domain = idn_to_ascii(substr(strstr($address, '@'), 1));
$local_part = strstr($address, '@', true);
if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {

View File

@ -67,7 +67,7 @@ $(document).ready(function() {
var req_empty = false;
$(this).closest("form").find('select, textarea, input').each(function() {
if ($(this).prop('required')) {
if (!$(this).val()) {
if (!$(this).val() && $(this).prop('disabled') === false) {
req_empty = true;
$(this).addClass('inputMissingAttr');
} else {
@ -126,7 +126,7 @@ $(document).ready(function() {
var req_empty = false;
$(this).closest("form").find('select, textarea, input').each(function() {
if ($(this).prop('required')) {
if (!$(this).val()) {
if (!$(this).val() && $(this).prop('disabled') === false) {
req_empty = true;
$(this).addClass('inputMissingAttr');
} else {

View File

@ -1,3 +1,17 @@
$(document).ready(function() {
if ($("#goto_null").is(":checked")) {
$('#textarea_alias_goto').prop('disabled', true);
}
$("#goto_null").click(function( event ) {
if ($("#goto_null").is(":checked")) {
$('#textarea_alias_goto').prop('disabled', true);
}
else {
$("#textarea_alias_goto").removeAttr('disabled');
}
});
});
jQuery(function($){
// http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
function validateEmail(email) {

View File

@ -30,6 +30,15 @@ $(document).ready(function() {
$('#password2').val(random_passwd);
});
$("#goto_null").click(function( event ) {
if ($("#goto_null").is(":checked")) {
$('#textarea_alias_goto').prop('disabled', true);
}
else {
$("#textarea_alias_goto").removeAttr('disabled');
}
});
// Log modal
$('#logModal').on('show.bs.modal', function(e) {
var logText = $(e.relatedTarget).data('log-text');
@ -283,6 +292,9 @@ jQuery(function($){
if (item.is_catch_all == 1) {
item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
}
if (item.goto == "null@localhost") {
item.goto = '⤷ <span style="font-size:12px" class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
}
if (item.in_primary_domain !== "") {
item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
}

View File

@ -331,6 +331,7 @@ $lang['edit']['dont_check_sender_acl'] = 'Absender für Domain %s u. Alias-Dom.
$lang['edit']['multiple_bookings'] = 'Mehrfaches Buchen';
$lang['edit']['kind'] = 'Art';
$lang['edit']['resource'] = 'Ressource';
$lang['edit']['goto_null'] = 'Nachrichten sofort verwerfen';
$lang['add']['syncjob'] = 'Sync-Job erstellen';
$lang['add']['syncjob_hint'] = 'Passwörter werden unverschlüsselt abgelegt!';
@ -385,6 +386,7 @@ $lang['add']['password'] = 'Passwort';
$lang['add']['password_repeat'] = 'Passwort (Wiederholung)';
$lang['add']['previous'] = 'Vorherige Seite';
$lang['add']['restart_sogo_hint'] = 'Der SOGo Container muss nach dem Hinzufügen einer neuen Domain neugestartet werden!';
$lang['add']['goto_null'] = 'Nachrichten sofort verwerfen';
$lang['login']['title'] = 'Anmeldung';
$lang['login']['administration'] = 'Administration';

View File

@ -336,6 +336,7 @@ $lang['edit']['dont_check_sender_acl'] = "Disable sender check for domain %s + a
$lang['edit']['multiple_bookings'] = 'Multiple bookings';
$lang['edit']['kind'] = 'Kind';
$lang['edit']['resource'] = 'Resource';
$lang['edit']['goto_null'] = 'Silently discard mail';
$lang['add']['syncjob'] = 'Add sync job';
$lang['add']['syncjob_hint'] = 'Be aware that passwords need to be saved plain-text!';
@ -390,6 +391,7 @@ $lang['add']['password'] = 'Password';
$lang['add']['password_repeat'] = 'Confirmation password (repeat)';
$lang['add']['previous'] = 'Previous page';
$lang['add']['restart_sogo_hint'] = 'You will need to restart the SOGo service container after adding a new domain!';
$lang['add']['goto_null'] = 'Silently discard mail';
$lang['login']['title'] = 'Login';
$lang['login']['administration'] = 'Administration';

View File

@ -234,7 +234,10 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
<div class="form-group">
<label class="control-label col-sm-2" for="goto"><?=$lang['add']['target_address'];?></label>
<div class="col-sm-10">
<textarea autocorrect="off" autocapitalize="none" class="form-control" rows="5" id="goto" name="goto" required></textarea>
<textarea id="textarea_alias_goto" autocorrect="off" autocapitalize="none" class="form-control" rows="5" id="goto" name="goto" required></textarea>
<div class="checkbox">
<label><input id="goto_null" type="checkbox" value="1" name="goto_null"> <?=$lang['add']['goto_null'];?></label>
</div>
<p><?=$lang['add']['target_address_info'];?></p>
</div>
</div>