mikel/mail — Issue #292: Deleting a custom header removes all custom headers
Author: holetse
Created: 2011-10-12 00:26:32+00:00
State: open

Using the message[header] = nil method for removing a custom header removes ALL custom headers on that message. See below for an IRB session demonstrating the issue.

ruby-1.9.2-p180 :001 > require 'mail'
=> true
ruby-1.9.2-p180 :002 > m = Mail::Message.new
=> #
ruby-1.9.2-p180 :003 > m[:test] = '123'
=> "123"
ruby-1.9.2-p180 :004 > m[:foo] = '456'
=> "456"
ruby-1.9.2-p180 :005 > m.header
=> test: 123
foo: 456

ruby-1.9.2-p180 :006 > m[:foo] = nil
=> nil
ruby-1.9.2-p180 :007 > m.header
=>
ruby-1.9.2-p180 :008 >

The last m.header call should return 'test: 123' but it returns nothing instead.

However, deleting the field object from the header fields list DOES work:

ruby-1.9.2-p180 :001 > require 'mail'
=> true
ruby-1.9.2-p180 :002 > m = Mail::Message.new
=> #
ruby-1.9.2-p180 :003 > m[:test] = '123'
=> "123"
ruby-1.9.2-p180 :004 > m[:foo] = '456'
=> "456"
ruby-1.9.2-p180 :005 > m.header
=> test: 123
foo: 456

ruby-1.9.2-p180 :006 > m.header.fields.delete_if {|field| field.name == 'foo'}
=> [123]
ruby-1.9.2-p180 :007 > m.header
=> test: 123

ruby-1.9.2-p180 :008 >