Closed zettabyte closed 14 years ago
I think from reading the BNF grammar in RFC 2045 that parameter names (called "attributes" in the RFC) are to be matched in a case-insensitive manner.
http://www.faqs.org/rfcs/rfc2045.html (see Appendix A at the bottom, specifically the "attribute" and "parameter" rules)
If this is so, then perhaps all parameter names should be mapped to lower-case values before being stored and used as hash keys. Just a thought.
Hmm, while I'm waiting for a reply from the mailing list regarding why running the spec tests on my forked and cloned copy fails, I've been looking at writing a fix to the underlying problem here.
I re-verified that in RFC 2045 and RFC 2183 that attributes (the name-part of a parameter of all content-* headers) are to use case-insensitive matching. So, my first-blush simple solution would be ensure that in the field class for each content-* header the keys in the ParameterHash be stored as lower-case strings.
After glancing at the specs for the ContentTypeField class, however, I see there are lots of comparisons of the parameters hash with a literal hash, some of which include upper-case letters. So, my solution would involve touching a lot of test code.
Another alternative is to modify the ParameterHash class itself, specifically the [] method to perform a case-insensitive search. However, I'm not sure what else this might break as I'm not sure how extensively it's used in contexts that might require case-sensitivity (though the comments in the code for the hash seem to indicate it's used for MIME extension headers only).
Comments?
I applied your patches on this, please re-open if still an issue
Example E-Mail: http://gist.github.com/606626
The above referenced email breaks
Mail::Message#has_attachments?
(and a few other things). Specifically, the message is a multipart email with two parts, the second of which is an attachment (starts on line 42) who's header(s) is(are) the source of the problem(s). I'm running gem version2.2.6.1
on ruby1.8.7
. If you save the linked email to a file namedtest.eml
on your system and run the following inirb
:The root cause or the first problem is the same thing that caused Issue #82 (I guess this patch: http://gist.github.com/472661 never got merged in or was removed?). The
Content-Disposition
header of the second message part has a value ofATTACHMENT
(line 45) in all caps which the parser doesn't like (it expects a lower-case-only value). So, the first problem is really a request to reopen issue #82 as it appears to not have the fix merged into gem version 2.2.6.1.However, if I manually merge the fix (http://gist.github.com/472661; I'm assuming this works, the code looks right) or just manually edit the email file and change
ATTACHMENT
toattachment
(line 45) in the email and try again,#has_attachments?
returns false. This is an improvement, but is also untrue.Now the problem is that in the
Content-Type
header thename
parameter is (again) in upper-case (line 43) and thefilename
parameter in theContent-Disposition
header is also in upper-case. (In fact, if you look at all theContent-X
headers for both parts, all parameter names are in upper-case).I can manually query for these parameters:
But trying accessor methods fails since they rely on a lower-case string as the hash key:
From the little bit of code-reading I've been doing, I'm not sure what the best fix is. I do know that, broken though they may be, apparently several "sources" of email out there do up-case these parameter names (my real-world email was an auto-generated one from Wells Fargo). I'm wondering if, for well-known "parameters" code should be added to normalize/downcase the parameter name as they're added to the
@parameters
Hash
(orParameterHash
). I'm not sure if this would best be in the respectiveXxField
orXxElement
class. But, well, there it is.