mail icon indicating copy to clipboard operation
mail copied to clipboard

Fix address with Q-encoded display name containing double quotes

Open rafbm opened this issue 10 years ago • 6 comments

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.

rafbm avatar Dec 04 '14 21:12 rafbm

@grosser any concerns?

bf4 avatar Dec 14 '14 03:12 bf4

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 avatar Dec 14 '14 03:12 grosser

@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.

rafbm avatar Dec 14 '14 04:12 rafbm

I like that version more ... are there enough tests that you are comfortable with that change ?

grosser avatar Dec 14 '14 04:12 grosser

Sorry for the delay!

Yes I am confident enough with the specs I just added for comments inside Q-encoded display names.

rafbm avatar Feb 05 '15 19:02 rafbm

Mmh not sure why specs fail on Travis. All green on my machine. Can someone have a look?

rafbm avatar Feb 05 '15 20:02 rafbm