]> source.dussan.org Git - redmine.git/commitdiff
Don't abort processing of emails when an email triggers a parsing exception (#16122).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 21 Mar 2014 03:04:43 +0000 (03:04 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 21 Mar 2014 03:04:43 +0000 (03:04 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12995 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
lib/redmine/imap.rb
lib/redmine/pop3.rb

index da2c5c4e5a27369b56eb25987188d7a0bb8b2525..e2dba0e41dfa035ece6353225a5dbc86837dd598 100644 (file)
@@ -46,6 +46,14 @@ class MailHandler < ActionMailer::Base
     super(email)
   end
 
+  # Receives an email and rescues any exception
+  def self.safe_receive(*args)
+    receive(*args)
+  rescue => e
+    logger.error "An unexpected error occurred when receiving email: #{e.message}" if logger
+    return false
+  end
+
   # Extracts MailHandler options from environment variables
   # Use when receiving emails with rake tasks
   def self.extract_options_from_env(env)
index e164ba8acf1c5c39a22861f53ed244d1becf1599..dc4334c2d54b02e3095808ebba55ab1d124bce52 100644 (file)
@@ -32,7 +32,7 @@ module Redmine
         imap.uid_search(['NOT', 'SEEN']).each do |uid|
           msg = imap.uid_fetch(uid,'RFC822')[0].attr['RFC822']
           logger.debug "Receiving message #{uid}" if logger && logger.debug?
-          if MailHandler.receive(msg, options)
+          if MailHandler.safe_receive(msg, options)
             logger.debug "Message #{uid} successfully received" if logger && logger.debug?
             if imap_options[:move_on_success]
               imap.uid_copy(uid, imap_options[:move_on_success])
index 3ceeeb4a0264a91d26d8ff854bf35953102637a7..fcedb5003bacf6b8daf25a830d942258bce9b50d 100644 (file)
@@ -36,7 +36,7 @@ module Redmine
             pop_session.each_mail do |msg|
               message = msg.pop
               message_id = (message =~ /^Message-I[dD]: (.*)/ ? $1 : '').strip
-              if MailHandler.receive(message, options)
+              if MailHandler.safe_receive(message, options)
                 msg.delete
                 logger.debug "--> Message #{message_id} processed and deleted from the server" if logger && logger.debug?
               else