Skip to content

Commit

Permalink
Fix that encoded fields ending in a question mark were treated as inv…
Browse files Browse the repository at this point in the history
…alid and not decoded, returning the raw encoded field
  • Loading branch information
jeremy committed Mar 14, 2021
1 parent c076f99 commit 51c05e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Bugs:
* Fix duplicate dots at beginning of lines. (c960657)
* Don't alter attachment filenames when Content-Type parsing fails. (nbianca)
* Fix decoding fields ending in question marks. (jeremy)


== Version 2.7.1 (2018-10-13)
Expand Down
4 changes: 2 additions & 2 deletions lib/mail/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module Constants
ATOM_UNSAFE = /[#{Regexp.quote aspecial}#{control}#{sp}]/n
PHRASE_UNSAFE = /[#{Regexp.quote aspecial}#{control}]/n
TOKEN_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{sp}]/n
ENCODED_VALUE = /\=\?([^?]+)\?([QB])\?[^?]*?\?\=/mi
FULL_ENCODED_VALUE = /(\=\?[^?]+\?[QB]\?[^?]*?\?\=)/mi
ENCODED_VALUE = /\=\?([^?]+)\?([QB])\?[^?]*?\?+\=/mi
FULL_ENCODED_VALUE = /(\=\?[^?]+\?[QB]\?[^?]*?\?+\=)/mi

EMPTY = ''
SPACE = ' '
Expand Down
4 changes: 4 additions & 0 deletions spec/mail/encodings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@
expect(Mail::Encodings.value_decode("=?utf-8?Q?a a?=")).to eq "a a"
end

it "should decode a string ending with an unencoded question mark" do
expect(Mail::Encodings.value_decode("=?UTF-8?Q?=C3=A5???=")).to eq "å??"
end

it "should treat unrecognized charsets as binary" do
if RUBY_VERSION >= "1.9"
expect(Mail::Encodings.value_decode("=?ISO-FOOO?Q?Morten_R=F8verdatt=E9r?=")).to eq "Morten R�verdatt�r"
Expand Down

0 comments on commit 51c05e0

Please sign in to comment.