dball-mail 2.2.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +459 -0
- data/README.rdoc +582 -0
- data/Rakefile +66 -0
- data/TODO.rdoc +9 -0
- data/lib/VERSION +4 -0
- data/lib/mail/attachments_list.rb +105 -0
- data/lib/mail/body.rb +286 -0
- data/lib/mail/configuration.rb +71 -0
- data/lib/mail/core_extensions/nil.rb +11 -0
- data/lib/mail/core_extensions/string.rb +27 -0
- data/lib/mail/elements/address.rb +306 -0
- data/lib/mail/elements/address_list.rb +74 -0
- data/lib/mail/elements/content_disposition_element.rb +30 -0
- data/lib/mail/elements/content_location_element.rb +25 -0
- data/lib/mail/elements/content_transfer_encoding_element.rb +24 -0
- data/lib/mail/elements/content_type_element.rb +35 -0
- data/lib/mail/elements/date_time_element.rb +26 -0
- data/lib/mail/elements/envelope_from_element.rb +34 -0
- data/lib/mail/elements/message_ids_element.rb +29 -0
- data/lib/mail/elements/mime_version_element.rb +26 -0
- data/lib/mail/elements/phrase_list.rb +21 -0
- data/lib/mail/elements/received_element.rb +30 -0
- data/lib/mail/elements.rb +14 -0
- data/lib/mail/encodings/7bit.rb +31 -0
- data/lib/mail/encodings/8bit.rb +31 -0
- data/lib/mail/encodings/base64.rb +33 -0
- data/lib/mail/encodings/binary.rb +31 -0
- data/lib/mail/encodings/quoted_printable.rb +38 -0
- data/lib/mail/encodings/transfer_encoding.rb +58 -0
- data/lib/mail/encodings.rb +268 -0
- data/lib/mail/envelope.rb +35 -0
- data/lib/mail/field.rb +223 -0
- data/lib/mail/field_list.rb +33 -0
- data/lib/mail/fields/bcc_field.rb +56 -0
- data/lib/mail/fields/cc_field.rb +55 -0
- data/lib/mail/fields/comments_field.rb +41 -0
- data/lib/mail/fields/common/address_container.rb +16 -0
- data/lib/mail/fields/common/common_address.rb +125 -0
- data/lib/mail/fields/common/common_date.rb +42 -0
- data/lib/mail/fields/common/common_field.rb +50 -0
- data/lib/mail/fields/common/common_message_id.rb +44 -0
- data/lib/mail/fields/common/parameter_hash.rb +58 -0
- data/lib/mail/fields/content_description_field.rb +19 -0
- data/lib/mail/fields/content_disposition_field.rb +69 -0
- data/lib/mail/fields/content_id_field.rb +63 -0
- data/lib/mail/fields/content_location_field.rb +42 -0
- data/lib/mail/fields/content_transfer_encoding_field.rb +50 -0
- data/lib/mail/fields/content_type_field.rb +198 -0
- data/lib/mail/fields/date_field.rb +55 -0
- data/lib/mail/fields/from_field.rb +55 -0
- data/lib/mail/fields/in_reply_to_field.rb +55 -0
- data/lib/mail/fields/keywords_field.rb +44 -0
- data/lib/mail/fields/message_id_field.rb +83 -0
- data/lib/mail/fields/mime_version_field.rb +53 -0
- data/lib/mail/fields/optional_field.rb +13 -0
- data/lib/mail/fields/received_field.rb +67 -0
- data/lib/mail/fields/references_field.rb +55 -0
- data/lib/mail/fields/reply_to_field.rb +55 -0
- data/lib/mail/fields/resent_bcc_field.rb +55 -0
- data/lib/mail/fields/resent_cc_field.rb +55 -0
- data/lib/mail/fields/resent_date_field.rb +35 -0
- data/lib/mail/fields/resent_from_field.rb +55 -0
- data/lib/mail/fields/resent_message_id_field.rb +34 -0
- data/lib/mail/fields/resent_sender_field.rb +62 -0
- data/lib/mail/fields/resent_to_field.rb +55 -0
- data/lib/mail/fields/return_path_field.rb +64 -0
- data/lib/mail/fields/sender_field.rb +67 -0
- data/lib/mail/fields/structured_field.rb +51 -0
- data/lib/mail/fields/subject_field.rb +16 -0
- data/lib/mail/fields/to_field.rb +55 -0
- data/lib/mail/fields/unstructured_field.rb +179 -0
- data/lib/mail/fields.rb +35 -0
- data/lib/mail/header.rb +264 -0
- data/lib/mail/mail.rb +255 -0
- data/lib/mail/message.rb +1972 -0
- data/lib/mail/network/delivery_methods/file_delivery.rb +40 -0
- data/lib/mail/network/delivery_methods/sendmail.rb +62 -0
- data/lib/mail/network/delivery_methods/smtp.rb +136 -0
- data/lib/mail/network/delivery_methods/test_mailer.rb +40 -0
- data/lib/mail/network/retriever_methods/imap.rb +213 -0
- data/lib/mail/network/retriever_methods/pop3.rb +194 -0
- data/lib/mail/network/retriever_methods/test_retriever.rb +31 -0
- data/lib/mail/network.rb +10 -0
- data/lib/mail/parsers/address_lists.rb +64 -0
- data/lib/mail/parsers/address_lists.treetop +19 -0
- data/lib/mail/parsers/content_disposition.rb +535 -0
- data/lib/mail/parsers/content_disposition.treetop +46 -0
- data/lib/mail/parsers/content_location.rb +139 -0
- data/lib/mail/parsers/content_location.treetop +20 -0
- data/lib/mail/parsers/content_transfer_encoding.rb +162 -0
- data/lib/mail/parsers/content_transfer_encoding.treetop +20 -0
- data/lib/mail/parsers/content_type.rb +967 -0
- data/lib/mail/parsers/content_type.treetop +68 -0
- data/lib/mail/parsers/date_time.rb +114 -0
- data/lib/mail/parsers/date_time.treetop +11 -0
- data/lib/mail/parsers/envelope_from.rb +194 -0
- data/lib/mail/parsers/envelope_from.treetop +32 -0
- data/lib/mail/parsers/message_ids.rb +45 -0
- data/lib/mail/parsers/message_ids.treetop +15 -0
- data/lib/mail/parsers/mime_version.rb +144 -0
- data/lib/mail/parsers/mime_version.treetop +19 -0
- data/lib/mail/parsers/phrase_lists.rb +45 -0
- data/lib/mail/parsers/phrase_lists.treetop +15 -0
- data/lib/mail/parsers/received.rb +71 -0
- data/lib/mail/parsers/received.treetop +11 -0
- data/lib/mail/parsers/rfc2045.rb +464 -0
- data/lib/mail/parsers/rfc2045.treetop +36 -0
- data/lib/mail/parsers/rfc2822.rb +5318 -0
- data/lib/mail/parsers/rfc2822.treetop +410 -0
- data/lib/mail/parsers/rfc2822_obsolete.rb +3757 -0
- data/lib/mail/parsers/rfc2822_obsolete.treetop +241 -0
- data/lib/mail/part.rb +116 -0
- data/lib/mail/parts_list.rb +43 -0
- data/lib/mail/patterns.rb +34 -0
- data/lib/mail/utilities.rb +211 -0
- data/lib/mail/version.rb +24 -0
- data/lib/mail/version_specific/ruby_1_8.rb +97 -0
- data/lib/mail/version_specific/ruby_1_9.rb +87 -0
- data/lib/mail.rb +80 -0
- data/lib/tasks/corpus.rake +125 -0
- data/lib/tasks/treetop.rake +10 -0
- metadata +255 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
|
5
|
+
class TestRetriever
|
6
|
+
cattr_accessor :emails
|
7
|
+
|
8
|
+
def initialize(values)
|
9
|
+
@@emails = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(options = {}, &block)
|
13
|
+
emails = @@emails
|
14
|
+
case count = options[:count]
|
15
|
+
when :all then emails
|
16
|
+
when 1 then emails.first
|
17
|
+
when Fixnum then emails[0, count]
|
18
|
+
else
|
19
|
+
raise 'Invalid count option value'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def all(options = {}, &block)
|
24
|
+
options ||= {}
|
25
|
+
options[:count] = :all
|
26
|
+
find(options, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/mail/network.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Mail
|
2
|
+
autoload :SMTP, 'mail/network/delivery_methods/smtp'
|
3
|
+
autoload :FileDelivery, 'mail/network/delivery_methods/file_delivery'
|
4
|
+
autoload :Sendmail, 'mail/network/delivery_methods/sendmail'
|
5
|
+
autoload :TestMailer, 'mail/network/delivery_methods/test_mailer'
|
6
|
+
|
7
|
+
autoload :POP3, 'mail/network/retriever_methods/pop3'
|
8
|
+
autoload :IMAP, 'mail/network/retriever_methods/imap'
|
9
|
+
autoload :TestRetriever, 'mail/network/retriever_methods/test_retriever'
|
10
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Mail
|
5
|
+
module AddressLists
|
6
|
+
include Treetop::Runtime
|
7
|
+
|
8
|
+
def root
|
9
|
+
@root ||= :primary_address
|
10
|
+
end
|
11
|
+
|
12
|
+
include RFC2822
|
13
|
+
|
14
|
+
module PrimaryAddress0
|
15
|
+
def addresses
|
16
|
+
[first_addr] + other_addr.elements.map { |o| o.addr_value }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module PrimaryAddress1
|
21
|
+
def addresses
|
22
|
+
[first_addr] + other_addr.elements.map { |o| o.addr_value }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def _nt_primary_address
|
27
|
+
start_index = index
|
28
|
+
if node_cache[:primary_address].has_key?(index)
|
29
|
+
cached = node_cache[:primary_address][index]
|
30
|
+
if cached
|
31
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
32
|
+
@index = cached.interval.end
|
33
|
+
end
|
34
|
+
return cached
|
35
|
+
end
|
36
|
+
|
37
|
+
i0 = index
|
38
|
+
r1 = _nt_address_list
|
39
|
+
r1.extend(PrimaryAddress0)
|
40
|
+
if r1
|
41
|
+
r0 = r1
|
42
|
+
else
|
43
|
+
r2 = _nt_obs_addr_list
|
44
|
+
r2.extend(PrimaryAddress1)
|
45
|
+
if r2
|
46
|
+
r0 = r2
|
47
|
+
else
|
48
|
+
@index = i0
|
49
|
+
r0 = nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
node_cache[:primary_address][start_index] = r0
|
54
|
+
|
55
|
+
r0
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class AddressListsParser < Treetop::Runtime::CompiledParser
|
61
|
+
include AddressLists
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mail
|
2
|
+
grammar AddressLists
|
3
|
+
|
4
|
+
include RFC2822
|
5
|
+
|
6
|
+
rule primary_address
|
7
|
+
address_list {
|
8
|
+
def addresses
|
9
|
+
[first_addr] + other_addr.elements.map { |o| o.addr_value }
|
10
|
+
end
|
11
|
+
} / obs_addr_list {
|
12
|
+
def addresses
|
13
|
+
[first_addr] + other_addr.elements.map { |o| o.addr_value }
|
14
|
+
end
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,535 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Mail
|
5
|
+
module ContentDisposition
|
6
|
+
include Treetop::Runtime
|
7
|
+
|
8
|
+
def root
|
9
|
+
@root ||= :content_disposition
|
10
|
+
end
|
11
|
+
|
12
|
+
include RFC2822
|
13
|
+
|
14
|
+
include RFC2045
|
15
|
+
|
16
|
+
module ContentDisposition0
|
17
|
+
def CFWS1
|
18
|
+
elements[0]
|
19
|
+
end
|
20
|
+
|
21
|
+
def parameter
|
22
|
+
elements[2]
|
23
|
+
end
|
24
|
+
|
25
|
+
def CFWS2
|
26
|
+
elements[3]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ContentDisposition1
|
31
|
+
def disposition_type
|
32
|
+
elements[0]
|
33
|
+
end
|
34
|
+
|
35
|
+
def param_hashes
|
36
|
+
elements[1]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module ContentDisposition2
|
41
|
+
def parameters
|
42
|
+
param_hashes.elements.map do |param|
|
43
|
+
param.parameter.param_hash
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def _nt_content_disposition
|
49
|
+
start_index = index
|
50
|
+
if node_cache[:content_disposition].has_key?(index)
|
51
|
+
cached = node_cache[:content_disposition][index]
|
52
|
+
if cached
|
53
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
54
|
+
@index = cached.interval.end
|
55
|
+
end
|
56
|
+
return cached
|
57
|
+
end
|
58
|
+
|
59
|
+
i0, s0 = index, []
|
60
|
+
r1 = _nt_disposition_type
|
61
|
+
s0 << r1
|
62
|
+
if r1
|
63
|
+
s2, i2 = [], index
|
64
|
+
loop do
|
65
|
+
i3, s3 = index, []
|
66
|
+
r4 = _nt_CFWS
|
67
|
+
s3 << r4
|
68
|
+
if r4
|
69
|
+
if has_terminal?(";", false, index)
|
70
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
71
|
+
@index += 1
|
72
|
+
else
|
73
|
+
terminal_parse_failure(";")
|
74
|
+
r5 = nil
|
75
|
+
end
|
76
|
+
s3 << r5
|
77
|
+
if r5
|
78
|
+
r6 = _nt_parameter
|
79
|
+
s3 << r6
|
80
|
+
if r6
|
81
|
+
r7 = _nt_CFWS
|
82
|
+
s3 << r7
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
if s3.last
|
87
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
88
|
+
r3.extend(ContentDisposition0)
|
89
|
+
else
|
90
|
+
@index = i3
|
91
|
+
r3 = nil
|
92
|
+
end
|
93
|
+
if r3
|
94
|
+
s2 << r3
|
95
|
+
else
|
96
|
+
break
|
97
|
+
end
|
98
|
+
end
|
99
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
100
|
+
s0 << r2
|
101
|
+
end
|
102
|
+
if s0.last
|
103
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
104
|
+
r0.extend(ContentDisposition1)
|
105
|
+
r0.extend(ContentDisposition2)
|
106
|
+
else
|
107
|
+
@index = i0
|
108
|
+
r0 = nil
|
109
|
+
end
|
110
|
+
|
111
|
+
node_cache[:content_disposition][start_index] = r0
|
112
|
+
|
113
|
+
r0
|
114
|
+
end
|
115
|
+
|
116
|
+
module DispositionType0
|
117
|
+
end
|
118
|
+
|
119
|
+
module DispositionType1
|
120
|
+
end
|
121
|
+
|
122
|
+
def _nt_disposition_type
|
123
|
+
start_index = index
|
124
|
+
if node_cache[:disposition_type].has_key?(index)
|
125
|
+
cached = node_cache[:disposition_type][index]
|
126
|
+
if cached
|
127
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
128
|
+
@index = cached.interval.end
|
129
|
+
end
|
130
|
+
return cached
|
131
|
+
end
|
132
|
+
|
133
|
+
i0 = index
|
134
|
+
i1, s1 = index, []
|
135
|
+
if has_terminal?('\G[iI]', true, index)
|
136
|
+
r2 = true
|
137
|
+
@index += 1
|
138
|
+
else
|
139
|
+
r2 = nil
|
140
|
+
end
|
141
|
+
s1 << r2
|
142
|
+
if r2
|
143
|
+
if has_terminal?('\G[nN]', true, index)
|
144
|
+
r3 = true
|
145
|
+
@index += 1
|
146
|
+
else
|
147
|
+
r3 = nil
|
148
|
+
end
|
149
|
+
s1 << r3
|
150
|
+
if r3
|
151
|
+
if has_terminal?('\G[lL]', true, index)
|
152
|
+
r4 = true
|
153
|
+
@index += 1
|
154
|
+
else
|
155
|
+
r4 = nil
|
156
|
+
end
|
157
|
+
s1 << r4
|
158
|
+
if r4
|
159
|
+
if has_terminal?('\G[iI]', true, index)
|
160
|
+
r5 = true
|
161
|
+
@index += 1
|
162
|
+
else
|
163
|
+
r5 = nil
|
164
|
+
end
|
165
|
+
s1 << r5
|
166
|
+
if r5
|
167
|
+
if has_terminal?('\G[nN]', true, index)
|
168
|
+
r6 = true
|
169
|
+
@index += 1
|
170
|
+
else
|
171
|
+
r6 = nil
|
172
|
+
end
|
173
|
+
s1 << r6
|
174
|
+
if r6
|
175
|
+
if has_terminal?('\G[eE]', true, index)
|
176
|
+
r7 = true
|
177
|
+
@index += 1
|
178
|
+
else
|
179
|
+
r7 = nil
|
180
|
+
end
|
181
|
+
s1 << r7
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
if s1.last
|
188
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
189
|
+
r1.extend(DispositionType0)
|
190
|
+
else
|
191
|
+
@index = i1
|
192
|
+
r1 = nil
|
193
|
+
end
|
194
|
+
if r1
|
195
|
+
r0 = r1
|
196
|
+
else
|
197
|
+
i8, s8 = index, []
|
198
|
+
if has_terminal?('\G[aA]', true, index)
|
199
|
+
r9 = true
|
200
|
+
@index += 1
|
201
|
+
else
|
202
|
+
r9 = nil
|
203
|
+
end
|
204
|
+
s8 << r9
|
205
|
+
if r9
|
206
|
+
if has_terminal?('\G[tT]', true, index)
|
207
|
+
r10 = true
|
208
|
+
@index += 1
|
209
|
+
else
|
210
|
+
r10 = nil
|
211
|
+
end
|
212
|
+
s8 << r10
|
213
|
+
if r10
|
214
|
+
if has_terminal?('\G[tT]', true, index)
|
215
|
+
r11 = true
|
216
|
+
@index += 1
|
217
|
+
else
|
218
|
+
r11 = nil
|
219
|
+
end
|
220
|
+
s8 << r11
|
221
|
+
if r11
|
222
|
+
if has_terminal?('\G[aA]', true, index)
|
223
|
+
r12 = true
|
224
|
+
@index += 1
|
225
|
+
else
|
226
|
+
r12 = nil
|
227
|
+
end
|
228
|
+
s8 << r12
|
229
|
+
if r12
|
230
|
+
if has_terminal?('\G[cC]', true, index)
|
231
|
+
r13 = true
|
232
|
+
@index += 1
|
233
|
+
else
|
234
|
+
r13 = nil
|
235
|
+
end
|
236
|
+
s8 << r13
|
237
|
+
if r13
|
238
|
+
if has_terminal?('\G[hH]', true, index)
|
239
|
+
r14 = true
|
240
|
+
@index += 1
|
241
|
+
else
|
242
|
+
r14 = nil
|
243
|
+
end
|
244
|
+
s8 << r14
|
245
|
+
if r14
|
246
|
+
if has_terminal?('\G[mM]', true, index)
|
247
|
+
r15 = true
|
248
|
+
@index += 1
|
249
|
+
else
|
250
|
+
r15 = nil
|
251
|
+
end
|
252
|
+
s8 << r15
|
253
|
+
if r15
|
254
|
+
if has_terminal?('\G[eE]', true, index)
|
255
|
+
r16 = true
|
256
|
+
@index += 1
|
257
|
+
else
|
258
|
+
r16 = nil
|
259
|
+
end
|
260
|
+
s8 << r16
|
261
|
+
if r16
|
262
|
+
if has_terminal?('\G[nN]', true, index)
|
263
|
+
r17 = true
|
264
|
+
@index += 1
|
265
|
+
else
|
266
|
+
r17 = nil
|
267
|
+
end
|
268
|
+
s8 << r17
|
269
|
+
if r17
|
270
|
+
if has_terminal?('\G[tT]', true, index)
|
271
|
+
r18 = true
|
272
|
+
@index += 1
|
273
|
+
else
|
274
|
+
r18 = nil
|
275
|
+
end
|
276
|
+
s8 << r18
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
if s8.last
|
287
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
288
|
+
r8.extend(DispositionType1)
|
289
|
+
else
|
290
|
+
@index = i8
|
291
|
+
r8 = nil
|
292
|
+
end
|
293
|
+
if r8
|
294
|
+
r0 = r8
|
295
|
+
else
|
296
|
+
r19 = _nt_extension_token
|
297
|
+
if r19
|
298
|
+
r0 = r19
|
299
|
+
else
|
300
|
+
if has_terminal?('', false, index)
|
301
|
+
r20 = instantiate_node(SyntaxNode,input, index...(index + 0))
|
302
|
+
@index += 0
|
303
|
+
else
|
304
|
+
terminal_parse_failure('')
|
305
|
+
r20 = nil
|
306
|
+
end
|
307
|
+
if r20
|
308
|
+
r0 = r20
|
309
|
+
else
|
310
|
+
@index = i0
|
311
|
+
r0 = nil
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
node_cache[:disposition_type][start_index] = r0
|
318
|
+
|
319
|
+
r0
|
320
|
+
end
|
321
|
+
|
322
|
+
def _nt_extension_token
|
323
|
+
start_index = index
|
324
|
+
if node_cache[:extension_token].has_key?(index)
|
325
|
+
cached = node_cache[:extension_token][index]
|
326
|
+
if cached
|
327
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
328
|
+
@index = cached.interval.end
|
329
|
+
end
|
330
|
+
return cached
|
331
|
+
end
|
332
|
+
|
333
|
+
i0 = index
|
334
|
+
r1 = _nt_ietf_token
|
335
|
+
if r1
|
336
|
+
r0 = r1
|
337
|
+
else
|
338
|
+
r2 = _nt_custom_x_token
|
339
|
+
if r2
|
340
|
+
r0 = r2
|
341
|
+
else
|
342
|
+
@index = i0
|
343
|
+
r0 = nil
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
node_cache[:extension_token][start_index] = r0
|
348
|
+
|
349
|
+
r0
|
350
|
+
end
|
351
|
+
|
352
|
+
module Parameter0
|
353
|
+
def attr
|
354
|
+
elements[1]
|
355
|
+
end
|
356
|
+
|
357
|
+
def val
|
358
|
+
elements[3]
|
359
|
+
end
|
360
|
+
|
361
|
+
end
|
362
|
+
|
363
|
+
module Parameter1
|
364
|
+
def param_hash
|
365
|
+
{attr.text_value => val.text_value}
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
def _nt_parameter
|
370
|
+
start_index = index
|
371
|
+
if node_cache[:parameter].has_key?(index)
|
372
|
+
cached = node_cache[:parameter][index]
|
373
|
+
if cached
|
374
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
375
|
+
@index = cached.interval.end
|
376
|
+
end
|
377
|
+
return cached
|
378
|
+
end
|
379
|
+
|
380
|
+
i0, s0 = index, []
|
381
|
+
r2 = _nt_CFWS
|
382
|
+
if r2
|
383
|
+
r1 = r2
|
384
|
+
else
|
385
|
+
r1 = instantiate_node(SyntaxNode,input, index...index)
|
386
|
+
end
|
387
|
+
s0 << r1
|
388
|
+
if r1
|
389
|
+
r3 = _nt_attribute
|
390
|
+
s0 << r3
|
391
|
+
if r3
|
392
|
+
if has_terminal?("=", false, index)
|
393
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
394
|
+
@index += 1
|
395
|
+
else
|
396
|
+
terminal_parse_failure("=")
|
397
|
+
r4 = nil
|
398
|
+
end
|
399
|
+
s0 << r4
|
400
|
+
if r4
|
401
|
+
r5 = _nt_value
|
402
|
+
s0 << r5
|
403
|
+
if r5
|
404
|
+
r7 = _nt_CFWS
|
405
|
+
if r7
|
406
|
+
r6 = r7
|
407
|
+
else
|
408
|
+
r6 = instantiate_node(SyntaxNode,input, index...index)
|
409
|
+
end
|
410
|
+
s0 << r6
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
415
|
+
if s0.last
|
416
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
417
|
+
r0.extend(Parameter0)
|
418
|
+
r0.extend(Parameter1)
|
419
|
+
else
|
420
|
+
@index = i0
|
421
|
+
r0 = nil
|
422
|
+
end
|
423
|
+
|
424
|
+
node_cache[:parameter][start_index] = r0
|
425
|
+
|
426
|
+
r0
|
427
|
+
end
|
428
|
+
|
429
|
+
def _nt_attribute
|
430
|
+
start_index = index
|
431
|
+
if node_cache[:attribute].has_key?(index)
|
432
|
+
cached = node_cache[:attribute][index]
|
433
|
+
if cached
|
434
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
435
|
+
@index = cached.interval.end
|
436
|
+
end
|
437
|
+
return cached
|
438
|
+
end
|
439
|
+
|
440
|
+
s0, i0 = [], index
|
441
|
+
loop do
|
442
|
+
r1 = _nt_token
|
443
|
+
if r1
|
444
|
+
s0 << r1
|
445
|
+
else
|
446
|
+
break
|
447
|
+
end
|
448
|
+
end
|
449
|
+
if s0.empty?
|
450
|
+
@index = i0
|
451
|
+
r0 = nil
|
452
|
+
else
|
453
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
454
|
+
end
|
455
|
+
|
456
|
+
node_cache[:attribute][start_index] = r0
|
457
|
+
|
458
|
+
r0
|
459
|
+
end
|
460
|
+
|
461
|
+
module Value0
|
462
|
+
def text_value
|
463
|
+
quoted_content.text_value
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
def _nt_value
|
468
|
+
start_index = index
|
469
|
+
if node_cache[:value].has_key?(index)
|
470
|
+
cached = node_cache[:value][index]
|
471
|
+
if cached
|
472
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
473
|
+
@index = cached.interval.end
|
474
|
+
end
|
475
|
+
return cached
|
476
|
+
end
|
477
|
+
|
478
|
+
i0 = index
|
479
|
+
r1 = _nt_quoted_string
|
480
|
+
r1.extend(Value0)
|
481
|
+
if r1
|
482
|
+
r0 = r1
|
483
|
+
else
|
484
|
+
s2, i2 = [], index
|
485
|
+
loop do
|
486
|
+
i3 = index
|
487
|
+
r4 = _nt_token
|
488
|
+
if r4
|
489
|
+
r3 = r4
|
490
|
+
else
|
491
|
+
if has_terminal?('\G[\\x3d]', true, index)
|
492
|
+
r5 = true
|
493
|
+
@index += 1
|
494
|
+
else
|
495
|
+
r5 = nil
|
496
|
+
end
|
497
|
+
if r5
|
498
|
+
r3 = r5
|
499
|
+
else
|
500
|
+
@index = i3
|
501
|
+
r3 = nil
|
502
|
+
end
|
503
|
+
end
|
504
|
+
if r3
|
505
|
+
s2 << r3
|
506
|
+
else
|
507
|
+
break
|
508
|
+
end
|
509
|
+
end
|
510
|
+
if s2.empty?
|
511
|
+
@index = i2
|
512
|
+
r2 = nil
|
513
|
+
else
|
514
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
515
|
+
end
|
516
|
+
if r2
|
517
|
+
r0 = r2
|
518
|
+
else
|
519
|
+
@index = i0
|
520
|
+
r0 = nil
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
node_cache[:value][start_index] = r0
|
525
|
+
|
526
|
+
r0
|
527
|
+
end
|
528
|
+
|
529
|
+
end
|
530
|
+
|
531
|
+
class ContentDispositionParser < Treetop::Runtime::CompiledParser
|
532
|
+
include ContentDisposition
|
533
|
+
end
|
534
|
+
|
535
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Mail
|
2
|
+
grammar ContentDisposition
|
3
|
+
|
4
|
+
include RFC2822
|
5
|
+
include RFC2045
|
6
|
+
|
7
|
+
rule content_disposition
|
8
|
+
disposition_type param_hashes:(CFWS ";" parameter CFWS)* {
|
9
|
+
def parameters
|
10
|
+
param_hashes.elements.map do |param|
|
11
|
+
param.parameter.param_hash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
rule disposition_type
|
18
|
+
[iI] [nN] [lL] [iI] [nN] [eE] / [aA] [tT] [tT] [aA] [cC] [hH] [mM] [eE] [nN] [tT] / extension_token / ''
|
19
|
+
end
|
20
|
+
|
21
|
+
rule extension_token
|
22
|
+
ietf_token / custom_x_token
|
23
|
+
end
|
24
|
+
|
25
|
+
rule parameter
|
26
|
+
CFWS? attr:attribute "=" val:value CFWS? {
|
27
|
+
def param_hash
|
28
|
+
{attr.text_value => val.text_value}
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
rule attribute
|
34
|
+
token+
|
35
|
+
end
|
36
|
+
|
37
|
+
rule value
|
38
|
+
quoted_string {
|
39
|
+
def text_value
|
40
|
+
quoted_content.text_value
|
41
|
+
end
|
42
|
+
} / (token / [\x3d])+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|