-
Notifications
You must be signed in to change notification settings - Fork 29
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
💥⚡ Simplify header-fld-name
parser (backward incompatible)
#216
Conversation
header-fld-name
parserheader-fld-name
parser (backward incompatible)
6077ead
to
ca76d75
Compare
header-fld-name
parser (backward incompatible)header-fld-name
parser (backward incompatible)
header-fld-name
parser (backward incompatible)header-fld-name
parser (backward incompatible)
ca76d75
to
a953f7f
Compare
a953f7f
to
755af6c
Compare
e434500
to
c000439
Compare
c000439
to
f077440
Compare
Note that servers may opt to use a quoted or literal string for atoms that do not require it. I'm not sure if any do that when the client uses the atom form, or if they are simply repeating back what the user sent to them. At any rate, if we always use the parsed version (which is what this PR does) it normalizes the result and can simplify the client code. Then the client can simply use I wasn't sure if I wanted to merge this for v0.5, but #315 convinced me that we should include it. I'm not planning to include a config option, because this particular code can make an outsized impact on parser performance. |
f077440
to
7825c6e
Compare
This speeds up my (earlier) benchmarks by ~15-20% over 0.4.3, and by 22-40% over earlier versions. (FYI: I have not re-run the benchmarks against v0.4.16 or v0.5.0-dev.) NOTE: Previously, Net::IMAP recreated the raw original source string. Now, it returns the decoded astring value. Although this is technically incompatible, it should almost never make a difference: all standard header field names are valid atoms. Where it _does_ make a difference, it should simplify client code, by parsing (normalizing) the result and allowing clients to ignore server inconsistency. This will also allow clients to simply rely on FetchData#header for extracting the result. Without this commit, FetchData#header won't work when servers return quoted or literal strings and the user expected an atom. (https://www.iana.org/assignments/message-headers/message-headers.xhtml)
7825c6e
to
3fe175f
Compare
This speeds up my (newly added) benchmarks by ~15-20% over v0.4.3, and by 22-40% over earlier versions.
NOTE: In every version up to v0.4.3,
Net::IMAP
recreated the raw original source string. After #217, it slices the raw original source string. After this PR, it returns the decoded astring value. Although this is technically incompatible, it should almost never make a difference. See the IANA Message Header Field Names list. All standard header field names are valid IMAP atoms. So I think this incompatibility should almost never occur.Valid RFC-5322 field names will never require string literals. But they technically may include atom-special characters and thus need to be quoted. Note that RFC-6532 (I18N headers) explicitly does not change the RFC-5322 field name syntax.
RFC-5322 syntax:
Which is matched by the following Regexp:
Although it shouldn't, if a server unnecessarily uses a quoted string (or a literal) for any standard message headers, this PR simplifies accessing the result by normalizing the field name back to its atom form.
The real incompatibility occurs when fetching non-standard but syntactically valid RFC-5322 field names, containing atom specials, which need to be quoted. But the workaround is simple.
For example, with the following non-standard (but syntactically valid) field names:
The current version of
Net::IMAP#fetch
doesn't quote any attrs, so in order to fetch these we'd need to manually quote them:All of the above is unchanged by this PR. The incompatibility is when retrieving the results from the
FetchData
:However, I also prepared a version that is backward-compatible, with a smaller performance boost:
header-fld-name
parser (backward compatible) #217