Permalink
Browse files

Header encoding should be US-ASCII, not the default external encoding

  • Loading branch information...
1 parent ece27b6 commit e20f93af966d24017ecccbfd035c12afc12c802e @jeremy jeremy committed Jan 27, 2013
Showing with 8 additions and 2 deletions.
  1. +1 −0 CHANGELOG.rdoc
  2. +1 −0 lib/mail/header.rb
  3. +6 −2 spec/mail/header_spec.rb
View
@@ -12,6 +12,7 @@ Performance:
* Close pull request 488 - Speed up field construction & comparison (bpot)
Bugs:
+* Header encoding should be US-ASCII, not the default external encoding (jeremy)
* Address elements should return decoded display names by default (jeremy)
* Fix up tests that depend on utf-8 external encoding; read fixtures as binary (jeremy)
* Capture stderr from Sendmail and Exim deliveries (jeremy)
View
@@ -201,6 +201,7 @@ def charset=(val)
def encoded
buffer = ''
+ buffer.force_encoding('us-ascii') if buffer.respond_to?(:force_encoding)
fields.each do |field|
buffer << field.encoded
end
View
@@ -545,9 +545,13 @@
describe "encoding" do
it "should output a parsed version of itself to US-ASCII on encoded and tidy up and sort correctly" do
- header = Mail::Header.new("To: Mikel\r\n\sLindsaar <mikel@test.lindsaar.net>\r\nFrom: bob\r\n\s<bob@test.lindsaar.net>\r\nSubject: This is\r\n a long\r\n\s \t \t \t badly formatted \r\n \t\t \t field")
+ encoded = Mail::Header.new("To: Mikel\r\n\sLindsaar <mikel@test.lindsaar.net>\r\nFrom: bob\r\n\s<bob@test.lindsaar.net>\r\nSubject: This is\r\n a long\r\n\s \t \t \t badly formatted \r\n \t\t \t field").encoded
result = "From: bob <bob@test.lindsaar.net>\r\nTo: Mikel Lindsaar <mikel@test.lindsaar.net>\r\nSubject: This is a long badly formatted field\r\n"
- header.encoded.should eq result
+ if result.respond_to?(:encode!)
+ result.encode!(Encoding::US_ASCII)
+ encoded.encoding.should eq Encoding::US_ASCII if encoded.respond_to?(:encoding)
+ end
+ encoded.should eq result
end
end

0 comments on commit e20f93a

Please sign in to comment.