Skip to content

Commit

Permalink
feat(mailcollector): review UI setup form
Browse files Browse the repository at this point in the history
  • Loading branch information
flegastelois committed Nov 28, 2024
1 parent aa13a4c commit 167d376
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 59 deletions.
13 changes: 12 additions & 1 deletion templates/pages/setup/authentication/mail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,21 @@
{% import 'components/form/fields_macros.html.twig' as fields %}

{% block more_fields %}
{{ fields.textField('host', item.fields['host'], __('Email domain Name (users email will be login@domain)')) }}
{{ fields.nullField() }}

{{ fields.smallTitle(__('Server configuration')) }}
{% set connect_opts = call('Toolbox::parseMailServerConnectString', [item.fields['connect_string']]) %}
{{ include('pages/setup/mailcollector/server_config_fields.html.twig', {
'connect_opts': connect_opts,
'host': item.fields['connect_string']
}) }}

{{ fields.smallTitle(__('Email options')) }}
{{ fields.textField(
'host',
item.fields['host'],
__('Email domain name'), {
helper: __('Users email will be login@domainname')
}
) }}
{% endblock %}
44 changes: 23 additions & 21 deletions templates/pages/setup/mailcollector/server_config_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@
{% import 'components/form/fields_macros.html.twig' as fields %}
{% import 'components/form/basic_inputs_macros.html.twig' as inputs %}

{{ fields.textField('mail_server', connect_opts['address'], __('Server')) }}
{{ fields.textField(
'mail_server',
connect_opts['address'],
__('Server')
) }}

{{ fields.textField(
'server_port',
connect_opts['port'],
__('Port (optional)'), {
helper: __(
'Typical ports: IMAP (143), IMAPS (993), POP (110), POPS (995)'
)
}
) }}

{% set protocols = {} %}
{% for k, protocol in call('Toolbox::getMailServerProtocols') %}
Expand Down Expand Up @@ -100,26 +114,14 @@
}) }}
</div>
{% endset %}
{{ fields.nullField() }}
{{ fields.htmlField('', connection_options_fields, __('Connection options')) }}
{{ fields.nullField() }}
{{ fields.htmlField(
'',
connection_options_fields,
__('Connection options')
) }}
{{ inputs.hidden('imap_string', host) }}

{% if connect_opts['type'] != 'pop' %}
{% set get_imap_folder_btn %}
<div class="btn btn-outline-secondary get-imap-folder cursor-pointer">
<i class="fa fa-list"></i>
</div>
{% endset %}
{{ fields.textField('server_mailbox', connect_opts['mailbox'], __('Incoming mail folder (optional, often INBOX)'), {
add_field_html: get_imap_folder_btn,
input_class: 'col-xxl-7 d-flex'
}) }}
{% endif %}

{{ fields.textField('server_port', connect_opts['port'], __('Port (optional)')) }}
{% if host is not empty %}
{{ fields.htmlField('', host, __('Connection string'), {
add_field_class: 'fw-bold'
}) }}
{{ fields.htmlField('', host, __('Connection string'), {
add_field_class: 'fw-bold'
}) }}
{% endif %}
166 changes: 129 additions & 37 deletions templates/pages/setup/mailcollector/setup_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,65 +48,157 @@
}) %}

{% block form_fields %}
{% if item.fields['errors'] %}
<div class="alert alert-danger">{{ __('%1$s: %2$s')|format(_n('Error', 'Errors', get_plural_number()), item.fields['errors']) }}</div>
{% endif %}
{{ fields.textField('name', item.fields['name'], __('Name'), {
helper: __('If the name is a valid email address, it will be automatically added to blacklisted senders.')
}) }}
{{ fields.nullField() }}
{{ fields.dropdownYesNo('is_active', item.fields['is_active'], __('Active')) }}
{{ fields.textField('login', item.fields['login'], __('Login')) }}
{{ fields.passwordField('passwd', '', __('Password'), {
clearable: not item.isNewItem,
'additional_attributes': {
'autocomplete': 'new-password',
{% if item.fields['errors'] %}
<div class="alert alert-danger">
{{ __('%1$s: %2$s')|format(
_n('Error', 'Errors', get_plural_number()),
item.fields['errors']
) }}
</div>
{% endif %}

{{ fields.textField(
'name',
item.fields['name'],
__('Name'), {
helper: __('If the name is a valid email address, it will be automatically added to blacklisted senders.')
}
}) }}
) }}

{{ fields.textareaField(
'comment',
item.fields['comment'],
__('Comments')
) }}

{{ fields.dropdownYesNo(
'is_active',
item.fields['is_active'],
__('Active')
) }}

{% set connect_opts = call('Toolbox::parseMailServerConnectString', [item.fields['host']]) %}
{{ fields.nullField() }}

{{ fields.smallTitle(__('Server configuration')) }}

{% set host = item.fields['host'] %}
{% set connect_opts = call(
'Toolbox::parseMailServerConnectString',
[host]
) %}

{{ include('pages/setup/mailcollector/server_config_fields.html.twig', {
'connect_opts': connect_opts,
'host': item.fields['host']
'host': host
}) }}

{{ fields.smallTitle(__('Authentication')) }}

{{ fields.textField(
'login',
item.fields['login'],
__('Login')
) }}

{{ fields.nullField() }}

{{ fields.passwordField(
'passwd',
'',
__('Password'), {
clearable: not item.isNewItem,
'additional_attributes': {
'autocomplete': 'new-password',
}
}
) }}

{% if connect_opts['type'] != 'pop' %}
{{ fields.smallTitle(__('Folders setup')) }}
{% set get_imap_folder_btn %}
<div class="btn btn-outline-secondary get-imap-folder cursor-pointer">
<i class="fa fa-list"></i>
</div>
{% endset %}
{{ fields.textField('accepted_folder', item.fields['accepted'], __('Accepted mail archive folder (optional)'), {
add_field_html: get_imap_folder_btn,
input_class: 'col-xxl-7 d-flex'
}) }}
{{ fields.textField('refused_folder', item.fields['refused'], __('Refused mail archive folder (optional)'), {
add_field_html: get_imap_folder_btn,
input_class: 'col-xxl-7 d-flex'
}) }}
{{ fields.textField(
'server_mailbox',
connect_opts['mailbox'],
__('Incoming mail folder (optional, often INBOX)'), {
add_field_html: get_imap_folder_btn,
input_class: 'col-xxl-7 d-flex'
}
) }}
{{ fields.nullField() }}
{{ fields.textField(
'accepted',
item.fields['accepted'],
__('Accepted mail archive folder (optional)'), {
add_field_html: get_imap_folder_btn,
input_class: 'col-xxl-7 d-flex'
}
) }}
{{ fields.textField(
'refused',
item.fields['refused'],
__('Refused mail archive folder (optional)'), {
add_field_html: get_imap_folder_btn,
input_class: 'col-xxl-7 d-flex'
}
) }}
{% endif %}

{{ fields.smallTitle(__('Collection options')) }}
{% set max_filesize_dropdown %}
{% do call('MailCollector::showMaxFilesize', ['filesize_max', item.fields['filesize_max']]) %}
{% endset %}
{{ fields.htmlField('', max_filesize_dropdown, __('Maximum size of each file imported by the mails receiver'), field_options) }}
{{ fields.dropdownYesNo('use_mail_date', item.fields['use_mail_date'], __('Use mail date, instead of collect one')) }}
{{ fields.dropdownArrayField('requester_field', item.fields['requester_field'], {
(constant('MailCollector::REQUESTER_FIELD_FROM')): __('No'),
(constant('MailCollector::REQUESTER_FIELD_REPLY_TO')): __('Yes'),
}, __('Use Reply-To as requester (when available)')) }}
{{ fields.dropdownYesNo('add_to_to_observer', item.fields['add_to_to_observer'], __('Add TO users as observer')) }}
{{ fields.dropdownYesNo('add_cc_to_observer', item.fields['add_cc_to_observer'], __('Add CC users as observer')) }}
{{ fields.dropdownYesNo('collect_only_unread', item.fields['collect_only_unread'], __('Collect only unread mail')) }}
{{ fields.htmlField(
'',
max_filesize_dropdown,
__('Maximum size of each file imported by the mails receiver'),
field_options
) }}
{{ fields.dropdownYesNo(
'use_mail_date',
item.fields['use_mail_date'],
__('Use mail date, instead of collect one')
) }}
{{ fields.dropdownArrayField(
'requester_field',
item.fields['requester_field'], {
(constant('MailCollector::REQUESTER_FIELD_FROM')): __('No'),
(constant('MailCollector::REQUESTER_FIELD_REPLY_TO')): __('Yes'),
},
__('Use Reply-To as requester (when available)')
) }}
{{ fields.dropdownYesNo(
'add_to_to_observer',
item.fields['add_to_to_observer'],
__('Add TO users as observer')
) }}
{{ fields.dropdownYesNo(
'add_cc_to_observer',
item.fields['add_cc_to_observer'],
__('Add CC users as observer')
) }}
{{ fields.dropdownYesNo(
'collect_only_unread',
item.fields['collect_only_unread'],
__('Collect only unread mail')
) }}

{% set create_user_helper %}
{% if not config('is_users_auto_add') %}
{{ __('If you use this option, and this collector is likely to receive requests from users authenticating via LDAP, we advise you to activate the option "Automatically add users from an external authentication source", in the Authentication settings in order to avoid the generation of duplicate users.') }}
{% endif %}
{% endset %}
{{ fields.dropdownYesNo('create_user_from_email', item.fields['create_user_from_email'], __('Automatically create user from email'), {
helper: create_user_helper|trim|default(null)
}) }}
{{ fields.textareaField('comment', item.fields['comment'], __('Comments')) }}

{{ fields.dropdownYesNo(
'create_user_from_email',
item.fields['create_user_from_email'],
__('Automatically create user from email'), {
helper: create_user_helper|trim|default(null)
}
) }}

{% if connect_opts['type'] != 'pop' %}
<script>
Expand Down

0 comments on commit 167d376

Please sign in to comment.