diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index cbdda32c4..5b8c45538 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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) diff --git a/lib/mail/constants.rb b/lib/mail/constants.rb index 14a4334f8..b63459cae 100644 --- a/lib/mail/constants.rb +++ b/lib/mail/constants.rb @@ -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 = ' ' diff --git a/spec/mail/encodings_spec.rb b/spec/mail/encodings_spec.rb index fdb8c4d5d..2210b36da 100644 --- a/spec/mail/encodings_spec.rb +++ b/spec/mail/encodings_spec.rb @@ -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"