Defect #16185

mail_handler.rb ignored email messages return 422

Added by Francois Conil over 8 years ago. Updated almost 4 years ago.

Status:Needs feedbackStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Email receiving
Target version:-
Resolution: Affected version:2.4.2

Description

We are currently using fetchmail to process incoming mail queues similar to the situation described at #2490

When mail_handler.rb process an out of office or similar auto-submitted message, it returns false
This in turn generates an error 422, which make rdm-mailhandler.rb returns an error code 77 to fetchmail.
Fetchmail keeps reprocessing the email instead of skipping it because of this particular error message.

Is mail_handler.rb behaviour when it comes to ignored emails by design or should we return "true" when a message is successfully ignored?

History

#1 Updated by Toshi MARUYAMA over 8 years ago

  • Description updated (diff)

#2 Updated by Jean-Philippe Lang over 8 years ago

  • Status changed from New to Needs feedback

As mentionned in #4368 (see note 2), 77 exit code generally results in emails being bounced immediately with an error description but that doesn't seem to be true in your case. Maybe we could make the exit code configurable for when mail_handler.rb receives a 422 response?

#3 Updated by Jean-Philippe Lang over 8 years ago

  • Assignee set to Jean-Philippe Lang

#4 Updated by Francois Conil over 8 years ago

Hi Jean-Philippe,

Maybe being able to configure what to do with "auto generated" emails?

It would be very easy for me to just make it return "true", but maybe giving people the choice of skipping such emails silently would work? If I'm correct, in terms of MTA, that would be similar to a drop as opposed to a bounce.

Fran├žois

#5 Updated by Go MAEDA almost 4 years ago

I am experiencing the same problem.

Currently, MailHandler#receive ignores auto-generated emails. Ignoring such emails is not a problem. But it returns false when it ignored auto-generated emails, and MailHandlerController#index responds "422 Unprocessable Entity" to rdm-mailhandler.rb which was invoked by an MTA such as Postfix and Sendmail. Then, rdm-mailhandler.rb returns EX_TEMPFAIL to the MTA if it gets "422 Unprocessable Entity" response.

As a result, the MTA continues to retry delivery for a few days and it will send an error notification to the original sender at last.

To avoid that, I think MailHandlerController#index should return "200 OK" instead of "422 Unprocessable Entity" when Redmine ignored an auto-generated email.


app/controllers/mail_handler_controller.rb:
MailHandlerController#index returns "422 Unprocessable Entity" when Redmine ignored an auto-generated email.

  # Submits an incoming email to MailHandler
  def index
    options = params.dup
    email = options.delete(:email)
    if MailHandler.receive(email, options)
      head :created
    else
      head :unprocessable_entity
    end
  end

extra/mail_handler/rdm-mailhandler.rb:
rdm-mailhandler.rb returns EX_TEMPFAIL to the MTA if MailHandlerController#index returned "422 Unprocessable Entity".

    begin
      response = Net::HTTPS.post_form(URI.parse(uri), data, headers, :no_check_certificate => no_check_certificate, :certificate_bundle => certificate_bundle)
    rescue SystemCallError, IOError => e # connection refused, etc.
      warn "An error occurred while contacting your Redmine server: #{e.message}" 
      return 75 # temporary failure
    end

Also available in: Atom PDF