Created
July 8, 2010 11:11
-
-
Save libc/467892 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/lib/mail/elements/content_type_element.rb b/lib/mail/elements/content_type_element.rb | |
| index 4bed7b7..83e8d8b 100644 | |
| --- a/lib/mail/elements/content_type_element.rb | |
| +++ b/lib/mail/elements/content_type_element.rb | |
| @@ -7,8 +7,8 @@ module Mail | |
| def initialize( string ) | |
| parser = Mail::ContentTypeParser.new | |
| if tree = parser.parse(cleaned(string)) | |
| - @main_type = tree.main_type.text_value | |
| - @sub_type = tree.sub_type.text_value | |
| + @main_type = tree.main_type.text_value.downcase | |
| + @sub_type = tree.sub_type.text_value.downcase | |
| @parameters = tree.parameters | |
| else | |
| raise Mail::Field::ParseError, "ContentTypeElement can not parse |#{string}|\nReason was: #{parser.failure_reason}\n" | |
| diff --git a/lib/mail/parsers/content_type.rb b/lib/mail/parsers/content_type.rb | |
| index 0660640..44a4b8f 100644 | |
| --- a/lib/mail/parsers/content_type.rb | |
| +++ b/lib/mail/parsers/content_type.rb | |
| @@ -166,6 +166,21 @@ module Mail | |
| r0 | |
| end | |
| + module DiscreteType0 | |
| + end | |
| + | |
| + module DiscreteType1 | |
| + end | |
| + | |
| + module DiscreteType2 | |
| + end | |
| + | |
| + module DiscreteType3 | |
| + end | |
| + | |
| + module DiscreteType4 | |
| + end | |
| + | |
| def _nt_discrete_type | |
| start_index = index | |
| if node_cache[:discrete_type].has_key?(index) | |
| @@ -178,59 +193,324 @@ module Mail | |
| end | |
| i0 = index | |
| - if has_terminal?("text", false, index) | |
| - r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) | |
| - @index += 4 | |
| + i1, s1 = index, [] | |
| + if has_terminal?('\G[tT]', true, index) | |
| + r2 = true | |
| + @index += 1 | |
| else | |
| - terminal_parse_failure("text") | |
| + r2 = nil | |
| + end | |
| + s1 << r2 | |
| + if r2 | |
| + if has_terminal?('\G[eE]', true, index) | |
| + r3 = true | |
| + @index += 1 | |
| + else | |
| + r3 = nil | |
| + end | |
| + s1 << r3 | |
| + if r3 | |
| + if has_terminal?('\G[xX]', true, index) | |
| + r4 = true | |
| + @index += 1 | |
| + else | |
| + r4 = nil | |
| + end | |
| + s1 << r4 | |
| + if r4 | |
| + if has_terminal?('\G[tT]', true, index) | |
| + r5 = true | |
| + @index += 1 | |
| + else | |
| + r5 = nil | |
| + end | |
| + s1 << r5 | |
| + end | |
| + end | |
| + end | |
| + if s1.last | |
| + r1 = instantiate_node(SyntaxNode,input, i1...index, s1) | |
| + r1.extend(DiscreteType0) | |
| + else | |
| + @index = i1 | |
| r1 = nil | |
| end | |
| if r1 | |
| r0 = r1 | |
| else | |
| - if has_terminal?("image", false, index) | |
| - r2 = instantiate_node(SyntaxNode,input, index...(index + 5)) | |
| - @index += 5 | |
| + i6, s6 = index, [] | |
| + if has_terminal?('\G[iI]', true, index) | |
| + r7 = true | |
| + @index += 1 | |
| else | |
| - terminal_parse_failure("image") | |
| - r2 = nil | |
| + r7 = nil | |
| end | |
| - if r2 | |
| - r0 = r2 | |
| + s6 << r7 | |
| + if r7 | |
| + if has_terminal?('\G[mM]', true, index) | |
| + r8 = true | |
| + @index += 1 | |
| + else | |
| + r8 = nil | |
| + end | |
| + s6 << r8 | |
| + if r8 | |
| + if has_terminal?('\G[aA]', true, index) | |
| + r9 = true | |
| + @index += 1 | |
| + else | |
| + r9 = nil | |
| + end | |
| + s6 << r9 | |
| + if r9 | |
| + if has_terminal?('\G[gG]', true, index) | |
| + r10 = true | |
| + @index += 1 | |
| + else | |
| + r10 = nil | |
| + end | |
| + s6 << r10 | |
| + if r10 | |
| + if has_terminal?('\G[eE]', true, index) | |
| + r11 = true | |
| + @index += 1 | |
| + else | |
| + r11 = nil | |
| + end | |
| + s6 << r11 | |
| + end | |
| + end | |
| + end | |
| + end | |
| + if s6.last | |
| + r6 = instantiate_node(SyntaxNode,input, i6...index, s6) | |
| + r6.extend(DiscreteType1) | |
| else | |
| - if has_terminal?("audio", false, index) | |
| - r3 = instantiate_node(SyntaxNode,input, index...(index + 5)) | |
| - @index += 5 | |
| + @index = i6 | |
| + r6 = nil | |
| + end | |
| + if r6 | |
| + r0 = r6 | |
| + else | |
| + i12, s12 = index, [] | |
| + if has_terminal?('\G[aA]', true, index) | |
| + r13 = true | |
| + @index += 1 | |
| else | |
| - terminal_parse_failure("audio") | |
| - r3 = nil | |
| + r13 = nil | |
| end | |
| - if r3 | |
| - r0 = r3 | |
| + s12 << r13 | |
| + if r13 | |
| + if has_terminal?('\G[uU]', true, index) | |
| + r14 = true | |
| + @index += 1 | |
| + else | |
| + r14 = nil | |
| + end | |
| + s12 << r14 | |
| + if r14 | |
| + if has_terminal?('\G[dD]', true, index) | |
| + r15 = true | |
| + @index += 1 | |
| + else | |
| + r15 = nil | |
| + end | |
| + s12 << r15 | |
| + if r15 | |
| + if has_terminal?('\G[iI]', true, index) | |
| + r16 = true | |
| + @index += 1 | |
| + else | |
| + r16 = nil | |
| + end | |
| + s12 << r16 | |
| + if r16 | |
| + if has_terminal?('\G[oO]', true, index) | |
| + r17 = true | |
| + @index += 1 | |
| + else | |
| + r17 = nil | |
| + end | |
| + s12 << r17 | |
| + end | |
| + end | |
| + end | |
| + end | |
| + if s12.last | |
| + r12 = instantiate_node(SyntaxNode,input, i12...index, s12) | |
| + r12.extend(DiscreteType2) | |
| + else | |
| + @index = i12 | |
| + r12 = nil | |
| + end | |
| + if r12 | |
| + r0 = r12 | |
| else | |
| - if has_terminal?("video", false, index) | |
| - r4 = instantiate_node(SyntaxNode,input, index...(index + 5)) | |
| - @index += 5 | |
| + i18, s18 = index, [] | |
| + if has_terminal?('\G[vV]', true, index) | |
| + r19 = true | |
| + @index += 1 | |
| else | |
| - terminal_parse_failure("video") | |
| - r4 = nil | |
| + r19 = nil | |
| end | |
| - if r4 | |
| - r0 = r4 | |
| + s18 << r19 | |
| + if r19 | |
| + if has_terminal?('\G[iI]', true, index) | |
| + r20 = true | |
| + @index += 1 | |
| + else | |
| + r20 = nil | |
| + end | |
| + s18 << r20 | |
| + if r20 | |
| + if has_terminal?('\G[dD]', true, index) | |
| + r21 = true | |
| + @index += 1 | |
| + else | |
| + r21 = nil | |
| + end | |
| + s18 << r21 | |
| + if r21 | |
| + if has_terminal?('\G[eE]', true, index) | |
| + r22 = true | |
| + @index += 1 | |
| + else | |
| + r22 = nil | |
| + end | |
| + s18 << r22 | |
| + if r22 | |
| + if has_terminal?('\G[oO]', true, index) | |
| + r23 = true | |
| + @index += 1 | |
| + else | |
| + r23 = nil | |
| + end | |
| + s18 << r23 | |
| + end | |
| + end | |
| + end | |
| + end | |
| + if s18.last | |
| + r18 = instantiate_node(SyntaxNode,input, i18...index, s18) | |
| + r18.extend(DiscreteType3) | |
| else | |
| - if has_terminal?("application", false, index) | |
| - r5 = instantiate_node(SyntaxNode,input, index...(index + 11)) | |
| - @index += 11 | |
| + @index = i18 | |
| + r18 = nil | |
| + end | |
| + if r18 | |
| + r0 = r18 | |
| + else | |
| + i24, s24 = index, [] | |
| + if has_terminal?('\G[aA]', true, index) | |
| + r25 = true | |
| + @index += 1 | |
| else | |
| - terminal_parse_failure("application") | |
| - r5 = nil | |
| + r25 = nil | |
| end | |
| - if r5 | |
| - r0 = r5 | |
| + s24 << r25 | |
| + if r25 | |
| + if has_terminal?('\G[pP]', true, index) | |
| + r26 = true | |
| + @index += 1 | |
| + else | |
| + r26 = nil | |
| + end | |
| + s24 << r26 | |
| + if r26 | |
| + if has_terminal?('\G[pP]', true, index) | |
| + r27 = true | |
| + @index += 1 | |
| + else | |
| + r27 = nil | |
| + end | |
| + s24 << r27 | |
| + if r27 | |
| + if has_terminal?('\G[lL]', true, index) | |
| + r28 = true | |
| + @index += 1 | |
| + else | |
| + r28 = nil | |
| + end | |
| + s24 << r28 | |
| + if r28 | |
| + if has_terminal?('\G[iI]', true, index) | |
| + r29 = true | |
| + @index += 1 | |
| + else | |
| + r29 = nil | |
| + end | |
| + s24 << r29 | |
| + if r29 | |
| + if has_terminal?('\G[cC]', true, index) | |
| + r30 = true | |
| + @index += 1 | |
| + else | |
| + r30 = nil | |
| + end | |
| + s24 << r30 | |
| + if r30 | |
| + if has_terminal?('\G[aA]', true, index) | |
| + r31 = true | |
| + @index += 1 | |
| + else | |
| + r31 = nil | |
| + end | |
| + s24 << r31 | |
| + if r31 | |
| + if has_terminal?('\G[tT]', true, index) | |
| + r32 = true | |
| + @index += 1 | |
| + else | |
| + r32 = nil | |
| + end | |
| + s24 << r32 | |
| + if r32 | |
| + if has_terminal?('\G[iI]', true, index) | |
| + r33 = true | |
| + @index += 1 | |
| + else | |
| + r33 = nil | |
| + end | |
| + s24 << r33 | |
| + if r33 | |
| + if has_terminal?('\G[oO]', true, index) | |
| + r34 = true | |
| + @index += 1 | |
| + else | |
| + r34 = nil | |
| + end | |
| + s24 << r34 | |
| + if r34 | |
| + if has_terminal?('\G[nN]', true, index) | |
| + r35 = true | |
| + @index += 1 | |
| + else | |
| + r35 = nil | |
| + end | |
| + s24 << r35 | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + if s24.last | |
| + r24 = instantiate_node(SyntaxNode,input, i24...index, s24) | |
| + r24.extend(DiscreteType4) | |
| + else | |
| + @index = i24 | |
| + r24 = nil | |
| + end | |
| + if r24 | |
| + r0 = r24 | |
| else | |
| - r6 = _nt_extension_token | |
| - if r6 | |
| - r0 = r6 | |
| + r36 = _nt_extension_token | |
| + if r36 | |
| + r0 = r36 | |
| else | |
| @index = i0 | |
| r0 = nil | |
| @@ -246,6 +526,12 @@ module Mail | |
| r0 | |
| end | |
| + module CompositeType0 | |
| + end | |
| + | |
| + module CompositeType1 | |
| + end | |
| + | |
| def _nt_composite_type | |
| start_index = index | |
| if node_cache[:composite_type].has_key?(index) | |
| @@ -258,29 +544,171 @@ module Mail | |
| end | |
| i0 = index | |
| - if has_terminal?("message", false, index) | |
| - r1 = instantiate_node(SyntaxNode,input, index...(index + 7)) | |
| - @index += 7 | |
| + i1, s1 = index, [] | |
| + if has_terminal?('\G[mM]', true, index) | |
| + r2 = true | |
| + @index += 1 | |
| + else | |
| + r2 = nil | |
| + end | |
| + s1 << r2 | |
| + if r2 | |
| + if has_terminal?('\G[eE]', true, index) | |
| + r3 = true | |
| + @index += 1 | |
| + else | |
| + r3 = nil | |
| + end | |
| + s1 << r3 | |
| + if r3 | |
| + if has_terminal?('\G[sS]', true, index) | |
| + r4 = true | |
| + @index += 1 | |
| + else | |
| + r4 = nil | |
| + end | |
| + s1 << r4 | |
| + if r4 | |
| + if has_terminal?('\G[sS]', true, index) | |
| + r5 = true | |
| + @index += 1 | |
| + else | |
| + r5 = nil | |
| + end | |
| + s1 << r5 | |
| + if r5 | |
| + if has_terminal?('\G[aA]', true, index) | |
| + r6 = true | |
| + @index += 1 | |
| + else | |
| + r6 = nil | |
| + end | |
| + s1 << r6 | |
| + if r6 | |
| + if has_terminal?('\G[gG]', true, index) | |
| + r7 = true | |
| + @index += 1 | |
| + else | |
| + r7 = nil | |
| + end | |
| + s1 << r7 | |
| + if r7 | |
| + if has_terminal?('\G[eE]', true, index) | |
| + r8 = true | |
| + @index += 1 | |
| + else | |
| + r8 = nil | |
| + end | |
| + s1 << r8 | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + if s1.last | |
| + r1 = instantiate_node(SyntaxNode,input, i1...index, s1) | |
| + r1.extend(CompositeType0) | |
| else | |
| - terminal_parse_failure("message") | |
| + @index = i1 | |
| r1 = nil | |
| end | |
| if r1 | |
| r0 = r1 | |
| else | |
| - if has_terminal?("multipart", false, index) | |
| - r2 = instantiate_node(SyntaxNode,input, index...(index + 9)) | |
| - @index += 9 | |
| + i9, s9 = index, [] | |
| + if has_terminal?('\G[mM]', true, index) | |
| + r10 = true | |
| + @index += 1 | |
| else | |
| - terminal_parse_failure("multipart") | |
| - r2 = nil | |
| + r10 = nil | |
| end | |
| - if r2 | |
| - r0 = r2 | |
| + s9 << r10 | |
| + if r10 | |
| + if has_terminal?('\G[uU]', true, index) | |
| + r11 = true | |
| + @index += 1 | |
| + else | |
| + r11 = nil | |
| + end | |
| + s9 << r11 | |
| + if r11 | |
| + if has_terminal?('\G[lL]', true, index) | |
| + r12 = true | |
| + @index += 1 | |
| + else | |
| + r12 = nil | |
| + end | |
| + s9 << r12 | |
| + if r12 | |
| + if has_terminal?('\G[tT]', true, index) | |
| + r13 = true | |
| + @index += 1 | |
| + else | |
| + r13 = nil | |
| + end | |
| + s9 << r13 | |
| + if r13 | |
| + if has_terminal?('\G[iI]', true, index) | |
| + r14 = true | |
| + @index += 1 | |
| + else | |
| + r14 = nil | |
| + end | |
| + s9 << r14 | |
| + if r14 | |
| + if has_terminal?('\G[pP]', true, index) | |
| + r15 = true | |
| + @index += 1 | |
| + else | |
| + r15 = nil | |
| + end | |
| + s9 << r15 | |
| + if r15 | |
| + if has_terminal?('\G[aA]', true, index) | |
| + r16 = true | |
| + @index += 1 | |
| + else | |
| + r16 = nil | |
| + end | |
| + s9 << r16 | |
| + if r16 | |
| + if has_terminal?('\G[rR]', true, index) | |
| + r17 = true | |
| + @index += 1 | |
| + else | |
| + r17 = nil | |
| + end | |
| + s9 << r17 | |
| + if r17 | |
| + if has_terminal?('\G[tT]', true, index) | |
| + r18 = true | |
| + @index += 1 | |
| + else | |
| + r18 = nil | |
| + end | |
| + s9 << r18 | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + if s9.last | |
| + r9 = instantiate_node(SyntaxNode,input, i9...index, s9) | |
| + r9.extend(CompositeType1) | |
| else | |
| - r3 = _nt_extension_token | |
| - if r3 | |
| - r0 = r3 | |
| + @index = i9 | |
| + r9 = nil | |
| + end | |
| + if r9 | |
| + r0 = r9 | |
| + else | |
| + r19 = _nt_extension_token | |
| + if r19 | |
| + r0 = r19 | |
| else | |
| @index = i0 | |
| r0 = nil | |
| diff --git a/lib/mail/parsers/content_type.treetop b/lib/mail/parsers/content_type.treetop | |
| index e511425..7f3cbf5 100644 | |
| --- a/lib/mail/parsers/content_type.treetop | |
| +++ b/lib/mail/parsers/content_type.treetop | |
| @@ -19,11 +19,11 @@ module Mail | |
| end | |
| rule discrete_type | |
| - "text" / "image" / "audio" / "video" / "application" / extension_token | |
| + [tT] [eE] [xX] [tT] / [iI] [mM] [aA] [gG] [eE] / [aA] [uU] [dD] [iI] [oO] / [vV] [iI] [dD] [eE] [oO] / [aA] [pP] [pP] [lL] [iI] [cC] [aA] [tT] [iI] [oO] [nN] / extension_token | |
| end | |
| rule composite_type | |
| - "message" / "multipart" / extension_token | |
| + [mM] [eE] [sS] [sS] [aA] [gG] [eE] / [mM] [uU] [lL] [tT] [iI] [pP] [aA] [rR] [tT] / extension_token | |
| end | |
| rule extension_token | |
| diff --git a/spec/mail/fields/content_type_field_spec.rb b/spec/mail/fields/content_type_field_spec.rb | |
| index 9ee8c0c..8c1360a 100644 | |
| --- a/spec/mail/fields/content_type_field_spec.rb | |
| +++ b/spec/mail/fields/content_type_field_spec.rb | |
| @@ -536,7 +536,15 @@ describe Mail::ContentTypeField do | |
| c.sub_type.should == 'related' | |
| c.parameters.should == {'boundary' => '1_4626B816_9F1690', 'Type' => 'application/smil', 'Start' => '<mms.smil.txt>'} | |
| end | |
| - | |
| + | |
| + it "should handle 'IMAGE/JPEG; name=\"IM 006.jpg\"'" do | |
| + string = %q{IMAGE/JPEG; name="IM 006.jpg"} | |
| + c = Mail::ContentTypeField.new(string) | |
| + c.content_type.should == 'image/jpeg' | |
| + c.main_type.should == 'image' | |
| + c.sub_type.should == 'jpeg' | |
| + c.parameters.should == {'name' => "IM 006.jpg"} | |
| + end | |
| end | |
| describe "finding a filename" do |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment