Follow up #2321 - In certain cases the timeout for IMAP actions isn't sufficient (e. g. expunge for 20k E-Mails takes longer than 1 minute).
This commit is contained in:
parent
cd65dcdb40
commit
5bfe56b476
1 changed files with 17 additions and 17 deletions
|
@ -94,23 +94,23 @@ example
|
||||||
Rails.logger.info "fetching imap (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl},starttls=#{starttls},folder=#{folder},keep_on_server=#{keep_on_server})"
|
Rails.logger.info "fetching imap (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl},starttls=#{starttls},folder=#{folder},keep_on_server=#{keep_on_server})"
|
||||||
|
|
||||||
# on check, reduce open_timeout to have faster probing
|
# on check, reduce open_timeout to have faster probing
|
||||||
@timeout = 45
|
check_type_timeout = 45
|
||||||
if check_type == 'check'
|
if check_type == 'check'
|
||||||
@timeout = 6
|
check_type_timeout = 6
|
||||||
end
|
end
|
||||||
|
|
||||||
timeout do
|
timeout(check_type_timeout) do
|
||||||
@imap = ::Net::IMAP.new(options[:host], port, ssl, nil, false)
|
@imap = ::Net::IMAP.new(options[:host], port, ssl, nil, false)
|
||||||
if starttls
|
if starttls
|
||||||
@imap.starttls()
|
@imap.starttls()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
timeout do
|
timeout(check_type_timeout) do
|
||||||
@imap.login(options[:user], options[:password])
|
@imap.login(options[:user], options[:password])
|
||||||
end
|
end
|
||||||
|
|
||||||
timeout do
|
timeout(check_type_timeout) do
|
||||||
# select folder
|
# select folder
|
||||||
@imap.select(folder)
|
@imap.select(folder)
|
||||||
end
|
end
|
||||||
|
@ -122,7 +122,7 @@ example
|
||||||
end
|
end
|
||||||
|
|
||||||
message_ids = nil
|
message_ids = nil
|
||||||
timeout do
|
timeout(6.minutes) do
|
||||||
begin
|
begin
|
||||||
message_ids = @imap.sort(['DATE'], filter, 'US-ASCII')
|
message_ids = @imap.sort(['DATE'], filter, 'US-ASCII')
|
||||||
rescue
|
rescue
|
||||||
|
@ -140,7 +140,7 @@ example
|
||||||
message_ids.each do |message_id|
|
message_ids.each do |message_id|
|
||||||
|
|
||||||
message_meta = nil
|
message_meta = nil
|
||||||
timeout do
|
timeout(1.minute) do
|
||||||
message_meta = @imap.fetch(message_id, ['RFC822.HEADER'])[0].attr
|
message_meta = @imap.fetch(message_id, ['RFC822.HEADER'])[0].attr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ example
|
||||||
message_ids.each do |message_id|
|
message_ids.each do |message_id|
|
||||||
|
|
||||||
message_meta = nil
|
message_meta = nil
|
||||||
timeout do
|
timeout(1.minute) do
|
||||||
message_meta = @imap.fetch(message_id, ['ENVELOPE'])[0].attr
|
message_meta = @imap.fetch(message_id, ['ENVELOPE'])[0].attr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ example
|
||||||
next if subject !~ /#{verify_string}/
|
next if subject !~ /#{verify_string}/
|
||||||
|
|
||||||
Rails.logger.info " - verify email #{verify_string} found"
|
Rails.logger.info " - verify email #{verify_string} found"
|
||||||
timeout do
|
timeout(600) do
|
||||||
@imap.store(message_id, '+FLAGS', [:Deleted])
|
@imap.store(message_id, '+FLAGS', [:Deleted])
|
||||||
@imap.expunge()
|
@imap.expunge()
|
||||||
end
|
end
|
||||||
|
@ -206,7 +206,7 @@ example
|
||||||
Rails.logger.info " - message #{count}/#{count_all}"
|
Rails.logger.info " - message #{count}/#{count_all}"
|
||||||
|
|
||||||
message_meta = nil
|
message_meta = nil
|
||||||
timeout do
|
timeout(1.minute) do
|
||||||
message_meta = @imap.fetch(message_id, ['RFC822.SIZE', 'ENVELOPE', 'FLAGS', 'INTERNALDATE'])[0]
|
message_meta = @imap.fetch(message_id, ['RFC822.SIZE', 'ENVELOPE', 'FLAGS', 'INTERNALDATE'])[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -225,14 +225,14 @@ example
|
||||||
|
|
||||||
# delete email from server after article was created
|
# delete email from server after article was created
|
||||||
msg = nil
|
msg = nil
|
||||||
timeout do
|
timeout(1.minute) do
|
||||||
msg = @imap.fetch(message_id, 'RFC822')[0].attr['RFC822']
|
msg = @imap.fetch(message_id, 'RFC822')[0].attr['RFC822']
|
||||||
end
|
end
|
||||||
next if !msg
|
next if !msg
|
||||||
|
|
||||||
process(channel, msg, false)
|
process(channel, msg, false)
|
||||||
|
|
||||||
timeout do
|
timeout(1.minute) do
|
||||||
if !keep_on_server
|
if !keep_on_server
|
||||||
@imap.store(message_id, '+FLAGS', [:Deleted])
|
@imap.store(message_id, '+FLAGS', [:Deleted])
|
||||||
else
|
else
|
||||||
|
@ -243,7 +243,7 @@ example
|
||||||
end
|
end
|
||||||
|
|
||||||
if !keep_on_server
|
if !keep_on_server
|
||||||
timeout do
|
timeout(10.minutes) do
|
||||||
@imap.expunge()
|
@imap.expunge()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -262,7 +262,7 @@ example
|
||||||
def disconnect
|
def disconnect
|
||||||
return if !@imap
|
return if !@imap
|
||||||
|
|
||||||
timeout do
|
timeout(1.minute) do
|
||||||
@imap.disconnect()
|
@imap.disconnect()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -303,7 +303,7 @@ returns
|
||||||
return false if ticket.preferences[:channel_id] != channel[:id]
|
return false if ticket.preferences[:channel_id] != channel[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
timeout do
|
timeout(1.minute) do
|
||||||
@imap.store(message_id, '+FLAGS', [:Seen])
|
@imap.store(message_id, '+FLAGS', [:Seen])
|
||||||
end
|
end
|
||||||
Rails.logger.info " - ignore message #{count}/#{count_all} - because message message id already imported"
|
Rails.logger.info " - ignore message #{count}/#{count_all} - because message message id already imported"
|
||||||
|
@ -328,8 +328,8 @@ returns
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def timeout
|
def timeout(seconds)
|
||||||
Timeout.timeout(@timeout) do
|
Timeout.timeout(seconds) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue