croaky / recipient_interceptor

Intercept recipients when delivering email with the Mail gem.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty header

wgc-bf opened this issue · comments

After upgrading to rails 3.2.13, we get this error:

Net::SMTPFatalError (554 Transaction failed: Empty header names are illegal.):

Which we tracked down to recipient_interceptor. The issue is that it is adding an extra new line to the original header, which already ended with a new line character.
The extra empty line has been converted to a ':' which is illegal.

The offending code is found in recipient_interceptor.rb:

  def add_custom_headers(message)
    {
      'X-Intercepted-To' => message.to || [],
      'X-Intercepted-Cc' => message.cc || [],
      'X-Intercepted-Bcc' => message.bcc || []
    }.each do |header, addresses|
      addresses.each do |address|
        message.header = "#{message.header}\n#{header}: #{address}"
      end
    end
  end

We found the following fixed the issue (at least on our systems):

  def add_custom_headers(message)
    {
      'X-Intercepted-To' => message.to || [],
      'X-Intercepted-Cc' => message.cc || [],
      'X-Intercepted-Bcc' => message.bcc || []
    }.each do |header, addresses|
      addresses.each do |address|
        message.header = "#{message.header.to_s.chomp}\n#{header}: #{address}"
      end
    end
  end

Thanks for the report. This should be fixed in 6bdbca6 and is in newly released version 0.1.2.