Fixed #38 - added folder option.

This commit is contained in:
Martin Edenhofer 2013-01-05 00:14:08 +01:00
parent 6f03f17a7a
commit d438f3947c
3 changed files with 26 additions and 6 deletions

View file

@ -371,14 +371,20 @@ class App.ChannelEmailInboundEdit extends App.ControllerModal
render: (data = {}) -> render: (data = {}) ->
if !data['options']
data['options'] = {}
data['options']['ssl'] = true
data['active'] = true
configure_attributes = [ configure_attributes = [
{ name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { IMAP: 'IMAP', POP3: 'POP3' } , class: 'span4', default: data['adapter'] }, { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { IMAP: 'IMAP', POP3: 'POP3' } , class: 'span4', default: data['adapter'] },
{ name: 'host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['host']) }, { name: 'host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['host']) },
{ name: 'user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['user']) }, { name: 'user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['user']) },
{ name: 'password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['password']) }, { name: 'password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['password']) },
{ name: 'ssl', display: 'SSL', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' } , class: 'span4', default: (data['options']&&data['options']['ssl']) }, { name: 'ssl', display: 'SSL', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' }, translate: true, class: 'span4', default: (data['options']&&data['options']['ssl']) },
{ name: 'folder', display: 'Folder', tag: 'input', type: 'text', limit: 120, null: true, class: 'span4', autocapitalize: false, default: (data['options']&&data['options']['folder']) },
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: @edit_form, nulloption: false, relation: 'Group', class: 'span4', default: data['group_id'] }, { name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: @edit_form, nulloption: false, relation: 'Group', class: 'span4', default: data['group_id'] },
{ name: 'active', display: 'Active', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' } , class: 'span4', default: data['active'] }, { name: 'active', display: 'Active', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' } , translate: true, class: 'span4', default: data['active'] },
] ]
if @object if @object
@html App.view('generic/admin/edit')( @html App.view('generic/admin/edit')(
@ -416,6 +422,7 @@ class App.ChannelEmailInboundEdit extends App.ControllerModal
user: params['user'], user: params['user'],
password: params['password'], password: params['password'],
ssl: params['ssl'], ssl: params['ssl'],
folder: params['folder'],
}, },
active: params['active'], active: params['active'],
) )

View file

@ -24,7 +24,11 @@ class Channel::IMAP < Channel::EmailParser
end end
imap.login( channel[:options][:user], channel[:options][:password] ) imap.login( channel[:options][:user], channel[:options][:password] )
end end
if channel[:options][:folder].empty?
imap.select('INBOX') imap.select('INBOX')
else
imap.select( channel[:options][:folder] )
end
count = 0 count = 0
count_all = imap.search(['ALL']).count count_all = imap.search(['ALL']).count
imap.search(['ALL']).each do |message_id| imap.search(['ALL']).each do |message_id|

View file

@ -4,10 +4,19 @@ class Channel::POP3 < Channel::EmailParser
include UserInfo include UserInfo
def fetch (channel) def fetch (channel)
puts "fetching pop3 (#{channel[:options][:host]}/#{channel[:options][:user]})" ssl = false
port = 110
if channel[:options][:ssl].to_s == 'true'
ssl = true
port = 995
end
pop = Net::POP3.new( channel[:options][:host], 995 ) puts "fetching pop3 (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})"
pop = Net::POP3.new( channel[:options][:host], port )
if ssl
pop.enable_ssl pop.enable_ssl
end
pop.start( channel[:options][:user], channel[:options][:password] ) pop.start( channel[:options][:user], channel[:options][:password] )
count = 0 count = 0
count_all = pop.mails.size count_all = pop.mails.size