diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.coffee index 1a4f950c2..6b6660ddd 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.coffee @@ -38,7 +38,7 @@ class App.ControllerForm extends App.Controller @form showAlert: (message) => - @form.find('.alert').removeClass('hide').html( App.i18n.translateContent(message) ) + @form.find('.alert').removeClass('hide').html(App.i18n.translateContent(message)) hideAlert: => @form.find('.alert').addClass('hide').html() @@ -356,7 +356,7 @@ class App.ControllerForm extends App.Controller hit = false for refAttribute, refValue of attribute.shown_if if params[refAttribute] - if _.isArray( refValue ) + if _.isArray(refValue) for item in refValue if params[refAttribute].toString() is item.toString() hit = true diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee index 6aee2251e..b2ce9cb68 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee @@ -702,10 +702,10 @@ class App.WizardModal extends App.Controller @$(".setup.wizard.#{name} input, .setup.wizard.#{name} select").first().focus() showAlert: (screen, message) => - @$(".#{screen}").find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) ) + @$(".#{screen}").find('.alert').first().removeClass('hide').text(App.i18n.translatePlain(message)) hideAlert: (screen) => - @$(".#{screen}").find('.alert').addClass('hide') + @$(".#{screen}").find('.alert').first().addClass('hide') disable: (e) => @formDisable(e) diff --git a/app/assets/javascripts/app/controllers/_channel/email.coffee b/app/assets/javascripts/app/controllers/_channel/email.coffee index 81d605303..738865326 100644 --- a/app/assets/javascripts/app/controllers/_channel/email.coffee +++ b/app/assets/javascripts/app/controllers/_channel/email.coffee @@ -499,6 +499,7 @@ class App.ChannelEmailAccountWizard extends App.WizardModal { name: 'email', display: 'Email', tag: 'input', type: 'email', limit: 120, null: false, placeholder: 'support@example.com', autocapitalize: false, autocomplete: 'off' }, { name: 'password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true }, { name: 'group_id', display: 'Destination Group', tag: 'select', null: false, relation: 'Group', nulloption: true }, + { name: 'folder', display: 'Folder', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false }, ] new App.ControllerForm( el: @$('.base-settings'), @@ -528,13 +529,25 @@ class App.ChannelEmailAccountWizard extends App.WizardModal { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autocomplete: 'off', }, { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, autocomplete: 'new-password', single: true }, + { name: 'options::folder', display: 'Folder', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false }, ] + + showHideFolder = (params, attribute, attributes, classname, form, ui) -> + return if !params + if params.adapter is 'imap' + ui.show('options::folder') + return + ui.hide('options::folder') + new App.ControllerForm( el: @$('.base-inbound-settings'), model: configure_attributes: configureAttributesInbound className: '' params: @account.inbound + handlers: [ + showHideFolder + ] ) toggleOutboundAdapter: => @@ -544,6 +557,7 @@ class App.ChannelEmailAccountWizard extends App.WizardModal if @account['meta'] channel_used['options']['user'] = @account['meta']['email'] channel_used['options']['password'] = @account['meta']['password'] + channel_used['options']['folder'] = @account['meta']['folder'] # show used backend @$('.base-outbound-settings').html('') @@ -574,14 +588,14 @@ class App.ChannelEmailAccountWizard extends App.WizardModal params.channel_id = @channel.id @disable(e) - @$('.js-probe .js-email').text( params.email ) + @$('.js-probe .js-email').text(params.email) @showSlide('js-probe') @ajax( id: 'email_probe' type: 'POST' url: @apiPath + '/channels/email_probe' - data: JSON.stringify( params ) + data: JSON.stringify(params) processData: true success: (data, status, xhr) => if data.result is 'ok' @@ -589,8 +603,8 @@ class App.ChannelEmailAccountWizard extends App.WizardModal for key, value of data.setting @account[key] = value - if !@channel && data.content_messages && data.content_messages > 0 - message = App.i18n.translateContent('We have already found %s emails in your mailbox. Zammad will move it all from your mailbox into Zammad.', data.content_messages) + if data.content_messages && data.content_messages > 0 + message = App.i18n.translateContent('We have already found %s email(s) in your mailbox. Zammad will move it all from your mailbox into Zammad.', data.content_messages) @$('.js-inbound-acknowledge .js-message').html(message) @$('.js-inbound-acknowledge .js-back').attr('data-slide', 'js-intro') @$('.js-inbound-acknowledge .js-next').attr('data-slide', '') @@ -604,12 +618,12 @@ class App.ChannelEmailAccountWizard extends App.WizardModal else if data.result is 'duplicate' @showSlide('js-intro') - @showAlert('js-intro', 'Account already exists!' ) + @showAlert('js-intro', 'Account already exists!') else @showSlide('js-inbound') - @showAlert('js-inbound', 'Unable to detect your server settings. Manual configuration needed.' ) - @$('.js-inbound [name="options::user"]').val( @account['meta']['email'] ) - @$('.js-inbound [name="options::password"]').val( @account['meta']['password'] ) + @showAlert('js-inbound', 'Unable to detect your server settings. Manual configuration needed.') + @$('.js-inbound [name="options::user"]').val(@account['meta']['email']) + @$('.js-inbound [name="options::password"]').val(@account['meta']['password']) @enable(e) fail: => @@ -635,7 +649,7 @@ class App.ChannelEmailAccountWizard extends App.WizardModal id: 'email_inbound' type: 'POST' url: @apiPath + '/channels/email_inbound' - data: JSON.stringify( params ) + data: JSON.stringify(params) processData: true success: (data, status, xhr) => if data.result is 'ok' @@ -643,8 +657,8 @@ class App.ChannelEmailAccountWizard extends App.WizardModal # remember account settings @account.inbound = params - if !@channel && data.content_messages && data.content_messages > 0 - message = App.i18n.translateContent('We have already found %s emails in your mailbox. Zammad will move it all from your mailbox into Zammad.', data.content_messages) + if data.content_messages && data.content_messages > 0 + message = App.i18n.translateContent('We have already found %s email(s) in your mailbox. Zammad will move it all from your mailbox into Zammad.', data.content_messages) @$('.js-inbound-acknowledge .js-message').html(message) @$('.js-inbound-acknowledge .js-back').attr('data-slide', 'js-inbound') @$('.js-inbound-acknowledge .js-next').unbind('click.verify') @@ -655,21 +669,21 @@ class App.ChannelEmailAccountWizard extends App.WizardModal # fill user / password based on inbound settings if !@channel if @account['inbound']['options'] - @$('.js-outbound [name="options::host"]').val( @account['inbound']['options']['host'] ) - @$('.js-outbound [name="options::user"]').val( @account['inbound']['options']['user'] ) - @$('.js-outbound [name="options::password"]').val( @account['inbound']['options']['password'] ) + @$('.js-outbound [name="options::host"]').val(@account['inbound']['options']['host']) + @$('.js-outbound [name="options::user"]').val(@account['inbound']['options']['user']) + @$('.js-outbound [name="options::password"]').val(@account['inbound']['options']['password']) else - @$('.js-outbound [name="options::user"]').val( @account['meta']['email'] ) - @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] ) + @$('.js-outbound [name="options::user"]').val(@account['meta']['email']) + @$('.js-outbound [name="options::password"]').val(@account['meta']['password']) else @showSlide('js-inbound') - @showAlert('js-inbound', data.message_human || data.message ) + @showAlert('js-inbound', data.message_human || data.message) @showInvalidField('js-inbound', data.invalid_field) @enable(e) fail: => @showSlide('js-inbound') - @showAlert('js-inbound', data.message_human || data.message ) + @showAlert('js-inbound', data.message_human || data.message) @showInvalidField('js-inbound', data.invalid_field) @enable(e) ) @@ -682,7 +696,7 @@ class App.ChannelEmailAccountWizard extends App.WizardModal params['email'] = @account['meta']['email'] if !params['email'] && @channel - email_addresses = App.EmailAddress.search( filter: { channel_id: @channel.id } ) + email_addresses = App.EmailAddress.search(filter: { channel_id: @channel.id }) if email_addresses && email_addresses[0] params['email'] = email_addresses[0].email @@ -709,12 +723,12 @@ class App.ChannelEmailAccountWizard extends App.WizardModal @verify(@account) else @showSlide('js-outbound') - @showAlert('js-outbound', data.message_human || data.message ) + @showAlert('js-outbound', data.message_human || data.message) @showInvalidField('js-outbound', data.invalid_field) @enable(e) fail: => @showSlide('js-outbound') - @showAlert('js-outbound', data.message_human || data.message ) + @showAlert('js-outbound', data.message_human || data.message) @showInvalidField('js-outbound', data.invalid_field) @enable(e) ) @@ -732,7 +746,7 @@ class App.ChannelEmailAccountWizard extends App.WizardModal account.group_id = @channel.group_id if !account.email && @channel - email_addresses = App.EmailAddress.search( filter: { channel_id: @channel.id } ) + email_addresses = App.EmailAddress.search(filter: { channel_id: @channel.id }) if email_addresses && email_addresses[0] account.email = email_addresses[0].email @@ -740,7 +754,7 @@ class App.ChannelEmailAccountWizard extends App.WizardModal id: 'email_verify' type: 'POST' url: @apiPath + '/channels/email_verify' - data: JSON.stringify( account ) + data: JSON.stringify(account) processData: true success: (data, status, xhr) => if data.result is 'ok' @@ -748,11 +762,11 @@ class App.ChannelEmailAccountWizard extends App.WizardModal else if data.source is 'inbound' || data.source is 'outbound' @showSlide("js-#{data.source}") - @showAlert("js-#{data.source}", data.message_human || data.message ) + @showAlert("js-#{data.source}", data.message_human || data.message) @showInvalidField("js-#{data.source}", data.invalid_field) else if count is 2 - @showAlert('js-verify', data.message_human || data.message ) + @showAlert('js-verify', data.message_human || data.message) @delay( => @showSlide('js-intro') @@ -882,12 +896,12 @@ class App.ChannelEmailNotificationWizard extends App.WizardModal @el.remove() else @showSlide('js-outbound') - @showAlert('js-outbound', data.message_human || data.message ) + @showAlert('js-outbound', data.message_human || data.message) @showInvalidField('js-outbound', data.invalid_field) @enable(e) fail: => @showSlide('js-outbound') - @showAlert('js-outbound', data.message_human || data.message ) + @showAlert('js-outbound', data.message_human || data.message) @showInvalidField('js-outbound', data.invalid_field) @enable(e) ) diff --git a/app/assets/javascripts/app/controllers/getting_started.coffee b/app/assets/javascripts/app/controllers/getting_started.coffee index 8b698523a..f9541a037 100644 --- a/app/assets/javascripts/app/controllers/getting_started.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.coffee @@ -731,7 +731,7 @@ class ChannelEmail extends App.WizardFullScreen @account[key] = value if data.content_messages && data.content_messages > 0 - message = App.i18n.translateContent('We have already found %s emails in your mailbox. Zammad will move it all from your mailbox into Zammad.', data.content_messages) + message = App.i18n.translateContent('We have already found %s email(s) in your mailbox. Zammad will move it all from your mailbox into Zammad.', data.content_messages) @$('.js-inbound-acknowledge .js-message').html(message) @$('.js-inbound-acknowledge .js-back').attr('data-slide', 'js-intro') @$('.js-inbound-acknowledge .js-next').attr('data-slide', '') diff --git a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco index 9cecb874b..b962bd953 100644 --- a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco +++ b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco @@ -52,6 +52,9 @@ <%- @T('User') %> <%= channel.options.inbound.options.user %> + <% if channel.options.inbound.options.folder: %> + (<%- @T('Folder') %>: <%= channel.options.inbound.options.folder %>) + <% end %> <%- @T('Host') %> <%= channel.options.inbound.options.host %> diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index e64be0c33..4d575ffab 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -149,6 +149,7 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten result = EmailHelper::Probe.full( email: params[:email], password: params[:password], + folder: params[:folder], ) # verify if user+host already exists diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index 644222336..65324f27b 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -65,7 +65,7 @@ returns end Timeout.timeout(timeout) do - @imap = Net::IMAP.new( options[:host], port, ssl, nil, false ) + @imap = Net::IMAP.new(options[:host], port, ssl, nil, false) end # try LOGIN, if not - try plain @@ -90,7 +90,7 @@ returns # check mode only if check_type == 'check' Rails.logger.info 'check only mode, fetch no emails' - content_max_check = 5 + content_max_check = 2 content_messages = 0 # check messages diff --git a/app/models/channel/driver/pop3.rb b/app/models/channel/driver/pop3.rb index ac64365fa..ff50e2998 100644 --- a/app/models/channel/driver/pop3.rb +++ b/app/models/channel/driver/pop3.rb @@ -54,7 +54,7 @@ returns Rails.logger.info "fetching pop3 (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl})" - @pop = Net::POP3.new( options[:host], port ) + @pop = Net::POP3.new(options[:host], port) #@pop.set_debug_output $stderr # on check, reduce open_timeout to have faster probing diff --git a/lib/email_helper/probe.rb b/lib/email_helper/probe.rb index 00da2856a..23e4bf711 100644 --- a/lib/email_helper/probe.rb +++ b/lib/email_helper/probe.rb @@ -8,6 +8,7 @@ get result of probe result = EmailHelper::Probe.full( email: 'znuny@example.com', password: 'somepassword', + folder: 'some_folder', # optional im imap ) returns on success @@ -23,7 +24,8 @@ returns on success ssl: true, user: 'some@example.com', password: 'password', - }, + folder: 'some_folder', # optional im imap + }, }, outbound: { adapter: 'smtp', @@ -71,6 +73,11 @@ returns on fail next if domain_to_check !~ /#{settings[:domain]}/i + # add folder to config if needed + if !params[:folder].empty? && settings[:inbound] && settings[:inbound][:options] + settings[:inbound][:options][:folder] = params[:folder] + end + # probe inbound Rails.logger.debug "INBOUND PROBE PROVIDER: #{settings[:inbound].inspect}" result_inbound = EmailHelper::Probe.inbound(settings[:inbound]) @@ -103,6 +110,12 @@ returns on fail } success = false inbound_map.each {|config| + + # add folder to config if needed + if !params[:folder].empty? && config[:options] + config[:options][:folder] = params[:folder] + end + Rails.logger.debug "INBOUND PROBE GUESS: #{config.inspect}" result_inbound = EmailHelper::Probe.inbound(config) Rails.logger.debug "INBOUND RESULT GUESS: #{result_inbound.inspect}" @@ -165,6 +178,7 @@ get result of inbound probe ssl: true, user: 'some@example.com', password: 'password', + folder: 'some_folder', # optional } ) @@ -184,6 +198,7 @@ returns on fail ssl: true, user: 'some@example.com', password: 'password', + folder: 'some_folder', # optional im imap }, message: 'error message from used lib', message_human: 'translated error message, readable for humans', @@ -365,6 +380,8 @@ returns on fail 'No route to host' => { host: true }, 'execution expired' => { host: true }, 'Connection refused' => { host: true }, + 'Mailbox doesn\'t exist' => { folder: true }, + 'Folder doesn\'t exist' => { folder: true }, } end