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

Incorrectly decodes subject that is encoded in UTF-8 #852

Closed
niandy opened this issue Feb 3, 2015 · 2 comments
Closed

Incorrectly decodes subject that is encoded in UTF-8 #852

niandy opened this issue Feb 3, 2015 · 2 comments

Comments

@niandy
Copy link

niandy commented Feb 3, 2015

I use mail 2.5.4 with redmine and I found out that Encodings.value_decode() in encodings.rb sometimes returns incorrect values for subject when it is encoded in UTF-8. It happens when the subject contains 2 strings like this
=?UTF-8?B?0J/RgNC+0YjRgyDRgNCw0LfQvtCx0YDQsNGC0YzRgdGPINC4IA==?=
=?UTF-8?B?0L/RgNC40L3Rj9GC0Ywg0YHRgNC+0YfQvdGL0LUg0LzQtdGA0YssINCyIA==?=

When value_decode calls collapse_adjacent_encodings it will turn the strings into
one
=?UTF-8?B?0J/RgNC+0YjRgyDRgNCw0LfQvtCx0YDQsNGC0YzRgdGPINC4IA==
0L/RgNC40L3Rj9GC0Ywg0YHRgNC+0YfQvdGL0LUg0LzQtdGA0YssINCyIA==?=

However str.unpack('m') will only decode the first of initial strings. I mean that

puts 
"0J/RgNC+0YjRgyDRgNCw0LfQvtCx0YDQsNGC0YzRgdGPINC4IA==".unpack('m').first.force_encoding('utf-8')

and

puts "0J/RgNC+0YjRgyDRgNCw0LfQvtCx0YDQsNGC0YzRgdGPINC4IA==0L/RgNC40L3Rj9GC0Ywg0YHRgNC+0YfQvdGL0LUg0LzQtdGA0YssINCyIA==".unpack('m').first.force_encoding('utf-8')

will return the same result. I believe it's because the decode from base64 function will always stop when it gets '=' or '==' symbols in base64 string. So, I think, collapsing adjacent encodings is not a proper thing to do at all. Cause you still have to decode every string separately.

@jeremy
Copy link
Collaborator

jeremy commented Sep 30, 2015

Fixed on master.

@jeremy jeremy closed this as completed Sep 30, 2015
@eileencodes
Copy link

In case anyone is curious the commit that fixed this was b832faf

@tjpnz tjpnz mentioned this issue Sep 22, 2017
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

3 participants