diff --git a/ajax/mailcollector.php b/ajax/mailcollector.php index e713e4af831..c2dd30f1d94 100644 --- a/ajax/mailcollector.php +++ b/ajax/mailcollector.php @@ -65,7 +65,9 @@ if (!empty($input['mail_server'])) { $input["host"] = Toolbox::constructMailServerConfig($input); - if (!isset($input['passwd'])) { + // In some case (like oauth imap) provide password is not possible + // So, ask for password only if there is one stored in database + if (!isset($input['passwd']) && !empty($mailcollector->fields['passwd'])) { $exception = new AccessDeniedHttpException(); $exception->setMessageToDisplay(__('Password is required to list mail folders.')); throw $exception; diff --git a/templates/pages/setup/mailcollector/setup_form.html.twig b/templates/pages/setup/mailcollector/setup_form.html.twig index 562777412eb..31315625869 100644 --- a/templates/pages/setup/mailcollector/setup_form.html.twig +++ b/templates/pages/setup/mailcollector/setup_form.html.twig @@ -213,10 +213,13 @@ // Force empty value for server_mailbox data += '&server_mailbox='; - // Ask for password if missing - if ($(this).closest('form').find('input[name=\"passwd\"]').val() == '') { - var passwd = prompt(__('Please enter password to list folders')); - data += '&passwd=' + encodeURIComponent(passwd); + // In some case (like oauth imap) provide password is not possible + // So, ask for password only if there is one stored in database + var passwdField = $(this).closest('form').find('input[name="passwd"]'); + var hasStoredPassword = {{ (item.fields['passwd'] is defined and item.fields['passwd']) ? 'true' : 'false' }}; + if (hasStoredPassword && passwdField.val() == '') { + var passwd = prompt(__('Please enter password to list folders')); + data += '&passwd=' + encodeURIComponent(passwd); } glpi_ajax_dialog({