Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting custom header deletes all custom headers #8

Open
pepawel opened this issue Mar 4, 2011 · 0 comments
Open

Deleting custom header deletes all custom headers #8

pepawel opened this issue Mar 4, 2011 · 0 comments

Comments

@pepawel
Copy link

pepawel commented Mar 4, 2011

Hi,

In the following example notice how 'custom2' header is deleted while deleting 'custom1':

>> m=Mail.new :custom1 => 'test1', :custom2 => 'test2'
=> \#<Mail::Message:-621216768, Multipart: false, Headers: <custom1: test1>, <custom2: test2>>

>> m[:custom2]
=> #<Mail::Field:0xb5f1ecc0 @field=#<Mail::OptionalField:0xb5f1e504 @length=nil, @name="custom2", @tree=nil, @element=nil, @errors=[], @value="test2", @charset="UTF8">>

>> m[:custom1] = nil
=> nil

>> m[:custom2]
=> nil

The problem is caused by Mail::Field#<=> method. This method treats all custom fields as equal.

Quick monkey patch:

class Mail::Field
  def <=>( other )
    self_order = FIELD_ORDER.rindex(self.name.to_s.downcase) || 100
    other_order = FIELD_ORDER.rindex(other.name.to_s.downcase) || 100
    if self_order == 100 && self_order == other_order
      self.name.to_s.downcase <=> other.name.to_s.downcase
    else
      self_order <=> other_order
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant