Parse rfc6532 addresses - #3130
Conversation
e673a0c to
2a4b7ca
Compare
This changes the handling of some noncompliant IMAP clients, which James would not tolerate before.
Application-layer code often assumes that addresses can be compared using String.equalsIgnoreCase(), and some also uses regular expressions or substring matching on addresses. This commit provides addresses to upper-layer code in their UTF8 form, so that kind of code continues to work. This might also have security implications: If upper-layer code can be confused about whether two addresses are the same, that sounds as if an attacker could exploit the confusion. This change should block the possibility.
RFC 6532 says we SHOULD do this and JAMES is generally very careful, so I did this as well.
…etc. This should not make a difference, but a sufficiently inventive attacker might combine it with something to confuse some code...
Once the server advertises UTF8=ACCEPT, angus-mail enables it and then takes its supportsUtf8() branch in IMAPProtocol.search(), which passes a null charset down to Argument.writeString(String) and encodes the search strings with ASCIIUtility.getBytes() -- one truncated byte per char. "天天向上" reaches the server as 29 29 11 0A, so the criterion is destroyed client-side before it hits the wire and no server-side decoding can recover it. Same in angus-mail 2.0.5, and there is no property to keep the client from enabling the capability. Send the RFC 6855 wire form ourselves instead: UTF-8 octets in literals, plus a quoted-string variant. These fail against consumeLiteral()'s former US-ASCII decoding, so they cover the gap they were written for.
2a4b7ca to
1e8e1e4
Compare
|
( |
|
Please address your comments @Arsnael |
|
@arnt no objection with that one? Also may I ask for a ICLA ? That's a major contribution, as per ASF rule we would need IP clearance. https://www.apache.org/licenses/contributor-agreements.html Thanks by advance |
|
I started the day with opening tabs for my open PRs, which are many and the James PR is big ;) The only reason I could write the james patches was that several colleagues were travelling so I had unexpected peace. Not done with the PR catching-upping, today's my first pass since June. Still have a few tabs to read and close, and James is one. I'll send the corporate CLA to the legal team at work; it should not be a problem (apart from the GPG invocations, which I am afraid the legal team will leave to me). I need lunch now, will review this after lunch. |
| @@ -84,24 +101,59 @@ void receivedMessagesShouldContainDeliveredToHeaders() throws Exception { | |||
|
|
|||
| @Test | |||
| void receivedMessagesShouldContainDeliveredToHeadersI8N() throws Exception { | |||
| * mime4j then falls back to us-ascii. Only the RFC 3798 form honours the | ||
| * declared charset. | ||
| */ | ||
| private static String reportCharset(Entity entity) { |
There was a problem hiding this comment.
Just a comment. The code is correct, I think.
There a chance that an RFC will appear sometime in 2027/8 that deprecates message/global and says to use message/rfc822 for everything. Ditto text/globalheaders or whatever it was.
I think generating message/global is good, for now, but on the parse side I might lean towards accepting UTF8 in message/rfc822 already. Not 100% sure. I might be strict there too, it depends on the code.
There was a problem hiding this comment.
Thanks for the notice. We will follow upcoming RFCs when published I presume.
There was a problem hiding this comment.
Yes.
I think my brain has found an opinion: at this point it's best to always follow RFC 6533 when generating, and mostly when parsing (unless that's too complicated and requires too much code).
| } | ||
|
|
||
| @Test | ||
| void asciiEmailWithSmtpUtf8ShouldBeReceived() throws Exception { |
There was a problem hiding this comment.
Simply that we can use ascii addresses with SMTPUTF8
Maybe not the most useful of a test but defnitly harmless.
| // Left alone for the ASCII envelopes that make up the bulk of the | ||
| // traffic, so they neither change behaviour nor trip Angus' "allowutf8 | ||
| // set but server doesn't advertise SMTPUTF8" log line. The pool clears | ||
| // the property again when the session is passivated. |
There was a problem hiding this comment.
Good point.
Looking at all this, I wonder why the tests passed.
| * | ||
| * UTF-8 is handled at {@link TestIMAPClient}'s own boundary instead: see | ||
| * {@link TestIMAPClient#asOctets(String)} and {@link TestIMAPClient#asText(String)}. | ||
| */ |
There was a problem hiding this comment.
I suppose it has to be like that. IMAP must read octets and decode to chars in a context-sensitive manner. While I find it difficult to name the octets "ISO-8859-1", given the legacy I suppose it makes sense.
There was a problem hiding this comment.
Well, working around our own test dependencies o_o
|
Lovely work. I really am puzzled that the test suite was green after my work, before yours @chibenwa Thanks! |
|
You are very welcome! |
No description provided.