Added IMAP folder support.

This commit is contained in:
Martin Edenhofer 2016-03-10 14:41:42 +01:00
parent ee991e1423
commit ec1c9a548e
9 changed files with 71 additions and 36 deletions

View file

@ -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)

View file

@ -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('')
@ -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', '')
@ -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')

View file

@ -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', '')

View file

@ -52,6 +52,9 @@
<tr>
<td><%- @T('User') %>
<td><%= channel.options.inbound.options.user %>
<% if channel.options.inbound.options.folder: %>
(<%- @T('Folder') %>: <%= channel.options.inbound.options.folder %>)
<% end %>
<tr>
<td><%- @T('Host') %>
<td><%= channel.options.inbound.options.host %>

View file

@ -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

View file

@ -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

View file

@ -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,6 +24,7 @@ returns on success
ssl: true,
user: 'some@example.com',
password: 'password',
folder: 'some_folder', # optional im imap
},
},
outbound: {
@ -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