Defect #44765
openEmails are lost when rdm-mailhandler.rb fails to contact Redmine because of an error such as a DNS failure or a timeout
Description
The attached patch fixes a problem in extra/mail_handler/rdm-mailhandler.rb where incoming emails are lost when the script fails to contact Redmine, for example because of a DNS failure or a timeout.
When the connection to Redmine is refused, the script ends with exit status 75 (EX_TEMPFAIL). The MTA then keeps the email in its queue and delivers it again later.
However, the script does not handle many other errors in this way, because it rescues only SystemCallError and IOError:
begin
response = Net::HTTPS.post_form(...)
rescue SystemCallError, IOError => e # connection refused, etc.
warn "An error occurred while contacting your Redmine server: #{e.message}"
return 75 # temporary failure
end
For example, the following errors are not rescued, so the script ends with exit status 1:
SocketError: the host name of the Redmine server cannot be resolvedOpenSSL::SSL::SSLError: a TLS error occurs, for example because the server certificate has expiredNet::OpenTimeoutandNet::ReadTimeout: Redmine does not respond within 60 secondsNet::HTTPBadResponse: the response is malformed
MTAs treat exit status 1 as a permanent failure and return the email to the sender (a bounce), so the email never reaches Redmine. However, none of these errors is caused by the email itself, and the email can be delivered after the problem is solved.
The patch rescues all errors that are raised while the script sends the email to Redmine, and returns exit status 75 for them in the same way as for a refused connection. Adding the classes above to the rescue clause is not enough, because these errors come from several libraries (socket, OpenSSL, and Net::HTTP) and have no common superclass other than StandardError, so such a list can easily miss some of them.
Files
No data to display