Fixes issue #2754: Unparseable IMAP responses block email import from inbox
Some users experienced an error while fetching emails over IMAP (see GitHub issue below for complete traceback). This error was caused by certain unparseable character sequences in the responses Zammad received from users' configured IMAP servers. The Zammad dev team was not able to reproduce this issue when fetching identical emails from its own servers. Details remain unclear, but we have tracebacks from two distinct occurrences of this issue, and the problematic strings followed the same format: * "\"Jetzt" * "\"RE:" This commit rescues the error in question, records details to the application log, and allows IMAP fetch to proceed to the next message.
This commit is contained in:
parent
7225899cf9
commit
0459023514
1 changed files with 14 additions and 1 deletions
|
@ -208,6 +208,7 @@ example
|
||||||
count_max = 5000
|
count_max = 5000
|
||||||
too_large_messages = []
|
too_large_messages = []
|
||||||
active_check_interval = 20
|
active_check_interval = 20
|
||||||
|
result = 'ok'
|
||||||
notice = ''
|
notice = ''
|
||||||
message_ids.each do |message_id|
|
message_ids.each do |message_id|
|
||||||
count += 1
|
count += 1
|
||||||
|
@ -222,6 +223,18 @@ example
|
||||||
message_meta = nil
|
message_meta = nil
|
||||||
timeout(FETCH_METADATA_TIMEOUT) do
|
timeout(FETCH_METADATA_TIMEOUT) do
|
||||||
message_meta = @imap.fetch(message_id, ['RFC822.SIZE', 'ENVELOPE', 'FLAGS', 'INTERNALDATE', 'RFC822.HEADER'])[0]
|
message_meta = @imap.fetch(message_id, ['RFC822.SIZE', 'ENVELOPE', 'FLAGS', 'INTERNALDATE', 'RFC822.HEADER'])[0]
|
||||||
|
rescue Net::IMAP::ResponseParseError => e
|
||||||
|
raise if !e.message.match?(/unknown token/)
|
||||||
|
|
||||||
|
result = 'error'
|
||||||
|
notice += <<~NOTICE
|
||||||
|
One of your incoming emails could not be imported (#{e.message}).
|
||||||
|
Please remove it from your inbox directly
|
||||||
|
to prevent Zammad from trying to import it again.
|
||||||
|
NOTICE
|
||||||
|
Rails.logger.error "Net::IMAP failed to parse message #{message_id}: #{e.message} (#{e.class})"
|
||||||
|
Rails.logger.error '(See https://github.com/zammad/zammad/issues/2754 for more details)'
|
||||||
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
# ignore verify messages
|
# ignore verify messages
|
||||||
|
@ -300,7 +313,7 @@ example
|
||||||
|
|
||||||
Rails.logger.info 'done'
|
Rails.logger.info 'done'
|
||||||
{
|
{
|
||||||
result: 'ok',
|
result: result,
|
||||||
fetched: count_fetched,
|
fetched: count_fetched,
|
||||||
notice: notice,
|
notice: notice,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue