mail
mail copied to clipboard
Fix address with Q-encoded display name containing double quotes
I added a spec for parsing the following address:
=?ISO-8859-1?Q?"Jan_Kr=FCtisch"?= <[email protected]>
Before the fix, display name was parsed as Jan_Kr=FCtisch
because when a quoted string was found (ie. "Jan_Kr=FCtisch"
), it was used as the display name and the surrounding characters were ignored.
After the fix, display name is properly encoded as Jan Krütisch
. Code-wise, the qstr
variable is now used as the display name instead of phrase
only if qstr
is equal to phrase
minus the quotes.
I would have liked to avoid creating the %("#{qstr}")
string, but I did not see another way. Other than that performance/memory should not be affected.
@grosser any concerns?
hmm old logic sounds broken, more logic does not feel very clean either ... but at least we have a test ... so choosing between the two evils I'd pick the new code ... :+1:
@grosser You are totally right that this is likely not the most appropriate fix. I just did a quick test not using the qstr
variable at all, just using the phrase
variable, stripping leading and trailing "
, all tests still pass:
when :angle_addr_s
if phrase_e
phrase = s[phrase_s..phrase_e].strip
if phrase[0] == '"' && phrase[-1] == '"'
phrase = phrase[1..-2]
end
address.display_name = phrase
phrase_e = phrase_s = nil
end
This questions the relevance of parsing quoted string as a token.
I like that version more ... are there enough tests that you are comfortable with that change ?
Sorry for the delay!
Yes I am confident enough with the specs I just added for comments inside Q-encoded display names.
Mmh not sure why specs fail on Travis. All green on my machine. Can someone have a look?