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