mms2r 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +54 -0
  3. data/README.txt +81 -0
  4. data/Rakefile +30 -0
  5. data/conf/mms2r_cingularmedia_transform.yml +6 -0
  6. data/conf/mms2r_sprintmedia_ignore.yml +10 -0
  7. data/conf/mms2r_tmobilemedia_ignore.yml +17 -0
  8. data/conf/mms2r_verizonmedia_ignore.yml +3 -0
  9. data/lib/mms2r.rb +3 -0
  10. data/lib/mms2r/cingular_media.rb +11 -0
  11. data/lib/mms2r/media.rb +345 -0
  12. data/lib/mms2r/mmode_media.rb +13 -0
  13. data/lib/mms2r/sprint_media.rb +50 -0
  14. data/lib/mms2r/tmobile_media.rb +11 -0
  15. data/lib/mms2r/verizon_media.rb +11 -0
  16. data/lib/mms2r/version.rb +12 -0
  17. data/lib/vendor/text/format.rb +1466 -0
  18. data/lib/vendor/tmail.rb +3 -0
  19. data/lib/vendor/tmail/address.rb +242 -0
  20. data/lib/vendor/tmail/attachments.rb +39 -0
  21. data/lib/vendor/tmail/base64.rb +71 -0
  22. data/lib/vendor/tmail/config.rb +69 -0
  23. data/lib/vendor/tmail/encode.rb +467 -0
  24. data/lib/vendor/tmail/facade.rb +552 -0
  25. data/lib/vendor/tmail/header.rb +914 -0
  26. data/lib/vendor/tmail/info.rb +35 -0
  27. data/lib/vendor/tmail/loader.rb +1 -0
  28. data/lib/vendor/tmail/mail.rb +447 -0
  29. data/lib/vendor/tmail/mailbox.rb +433 -0
  30. data/lib/vendor/tmail/mbox.rb +1 -0
  31. data/lib/vendor/tmail/net.rb +280 -0
  32. data/lib/vendor/tmail/obsolete.rb +135 -0
  33. data/lib/vendor/tmail/parser.rb +1522 -0
  34. data/lib/vendor/tmail/port.rb +377 -0
  35. data/lib/vendor/tmail/quoting.rb +131 -0
  36. data/lib/vendor/tmail/scanner.rb +41 -0
  37. data/lib/vendor/tmail/scanner_r.rb +263 -0
  38. data/lib/vendor/tmail/stringio.rb +277 -0
  39. data/lib/vendor/tmail/tmail.rb +1 -0
  40. data/lib/vendor/tmail/utils.rb +238 -0
  41. data/test/files/dot.jpg +0 -0
  42. data/test/files/sprint-image-01.mail +195 -0
  43. data/test/files/sprint-text-01.mail +8 -0
  44. data/test/files/sprint-video-01.mail +195 -0
  45. data/test/files/sprint.mov +0 -0
  46. data/test/files/verizon-image-01.mail +815 -0
  47. data/test/files/verizon-text-01.mail +11 -0
  48. data/test/files/verizon-video-01.mail +336 -0
  49. data/test/test_mms2r_cingular.rb +52 -0
  50. data/test/test_mms2r_media.rb +311 -0
  51. data/test/test_mms2r_mmode.rb +52 -0
  52. data/test/test_mms2r_sprint.rb +154 -0
  53. data/test/test_mms2r_tmobile.rb +169 -0
  54. data/test/test_mms2r_verizon.rb +74 -0
  55. metadata +130 -0
@@ -0,0 +1,552 @@
1
+ #
2
+ # facade.rb
3
+ #
4
+ #--
5
+ # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the
9
+ # "Software"), to deal in the Software without restriction, including
10
+ # without limitation the rights to use, copy, modify, merge, publish,
11
+ # distribute, sublicense, and/or sell copies of the Software, and to
12
+ # permit persons to whom the Software is furnished to do so, subject to
13
+ # the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be
16
+ # included in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ #
26
+ # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
27
+ # with permission of Minero Aoki.
28
+ #++
29
+
30
+ require 'tmail/utils'
31
+
32
+
33
+ module TMail
34
+
35
+ class Mail
36
+
37
+ def header_string( name, default = nil )
38
+ h = @header[name.downcase] or return default
39
+ h.to_s
40
+ end
41
+
42
+ ###
43
+ ### attributes
44
+ ###
45
+
46
+ include TextUtils
47
+
48
+ def set_string_array_attr( key, strs )
49
+ strs.flatten!
50
+ if strs.empty?
51
+ @header.delete key.downcase
52
+ else
53
+ store key, strs.join(', ')
54
+ end
55
+ strs
56
+ end
57
+ private :set_string_array_attr
58
+
59
+ def set_string_attr( key, str )
60
+ if str
61
+ store key, str
62
+ else
63
+ @header.delete key.downcase
64
+ end
65
+ str
66
+ end
67
+ private :set_string_attr
68
+
69
+ def set_addrfield( name, arg )
70
+ if arg
71
+ h = HeaderField.internal_new(name, @config)
72
+ h.addrs.replace [arg].flatten
73
+ @header[name] = h
74
+ else
75
+ @header.delete name
76
+ end
77
+ arg
78
+ end
79
+ private :set_addrfield
80
+
81
+ def addrs2specs( addrs )
82
+ return nil unless addrs
83
+ list = addrs.map {|addr|
84
+ if addr.address_group?
85
+ then addr.map {|a| a.spec }
86
+ else addr.spec
87
+ end
88
+ }.flatten
89
+ return nil if list.empty?
90
+ list
91
+ end
92
+ private :addrs2specs
93
+
94
+
95
+ #
96
+ # date time
97
+ #
98
+
99
+ def date( default = nil )
100
+ if h = @header['date']
101
+ h.date
102
+ else
103
+ default
104
+ end
105
+ end
106
+
107
+ def date=( time )
108
+ if time
109
+ store 'Date', time2str(time)
110
+ else
111
+ @header.delete 'date'
112
+ end
113
+ time
114
+ end
115
+
116
+ def strftime( fmt, default = nil )
117
+ if t = date
118
+ t.strftime(fmt)
119
+ else
120
+ default
121
+ end
122
+ end
123
+
124
+
125
+ #
126
+ # destination
127
+ #
128
+
129
+ def to_addrs( default = nil )
130
+ if h = @header['to']
131
+ h.addrs
132
+ else
133
+ default
134
+ end
135
+ end
136
+
137
+ def cc_addrs( default = nil )
138
+ if h = @header['cc']
139
+ h.addrs
140
+ else
141
+ default
142
+ end
143
+ end
144
+
145
+ def bcc_addrs( default = nil )
146
+ if h = @header['bcc']
147
+ h.addrs
148
+ else
149
+ default
150
+ end
151
+ end
152
+
153
+ def to_addrs=( arg )
154
+ set_addrfield 'to', arg
155
+ end
156
+
157
+ def cc_addrs=( arg )
158
+ set_addrfield 'cc', arg
159
+ end
160
+
161
+ def bcc_addrs=( arg )
162
+ set_addrfield 'bcc', arg
163
+ end
164
+
165
+ def to( default = nil )
166
+ addrs2specs(to_addrs(nil)) || default
167
+ end
168
+
169
+ def cc( default = nil )
170
+ addrs2specs(cc_addrs(nil)) || default
171
+ end
172
+
173
+ def bcc( default = nil )
174
+ addrs2specs(bcc_addrs(nil)) || default
175
+ end
176
+
177
+ def to=( *strs )
178
+ set_string_array_attr 'To', strs
179
+ end
180
+
181
+ def cc=( *strs )
182
+ set_string_array_attr 'Cc', strs
183
+ end
184
+
185
+ def bcc=( *strs )
186
+ set_string_array_attr 'Bcc', strs
187
+ end
188
+
189
+
190
+ #
191
+ # originator
192
+ #
193
+
194
+ def from_addrs( default = nil )
195
+ if h = @header['from']
196
+ h.addrs
197
+ else
198
+ default
199
+ end
200
+ end
201
+
202
+ def from_addrs=( arg )
203
+ set_addrfield 'from', arg
204
+ end
205
+
206
+ def from( default = nil )
207
+ addrs2specs(from_addrs(nil)) || default
208
+ end
209
+
210
+ def from=( *strs )
211
+ set_string_array_attr 'From', strs
212
+ end
213
+
214
+ def friendly_from( default = nil )
215
+ h = @header['from']
216
+ a, = h.addrs
217
+ return default unless a
218
+ return a.phrase if a.phrase
219
+ return h.comments.join(' ') unless h.comments.empty?
220
+ a.spec
221
+ end
222
+
223
+
224
+ def reply_to_addrs( default = nil )
225
+ if h = @header['reply-to']
226
+ h.addrs
227
+ else
228
+ default
229
+ end
230
+ end
231
+
232
+ def reply_to_addrs=( arg )
233
+ set_addrfield 'reply-to', arg
234
+ end
235
+
236
+ def reply_to( default = nil )
237
+ addrs2specs(reply_to_addrs(nil)) || default
238
+ end
239
+
240
+ def reply_to=( *strs )
241
+ set_string_array_attr 'Reply-To', strs
242
+ end
243
+
244
+
245
+ def sender_addr( default = nil )
246
+ f = @header['sender'] or return default
247
+ f.addr or return default
248
+ end
249
+
250
+ def sender_addr=( addr )
251
+ if addr
252
+ h = HeaderField.internal_new('sender', @config)
253
+ h.addr = addr
254
+ @header['sender'] = h
255
+ else
256
+ @header.delete 'sender'
257
+ end
258
+ addr
259
+ end
260
+
261
+ def sender( default )
262
+ f = @header['sender'] or return default
263
+ a = f.addr or return default
264
+ a.spec
265
+ end
266
+
267
+ def sender=( str )
268
+ set_string_attr 'Sender', str
269
+ end
270
+
271
+
272
+ #
273
+ # subject
274
+ #
275
+
276
+ def subject( default = nil )
277
+ if h = @header['subject']
278
+ h.body
279
+ else
280
+ default
281
+ end
282
+ end
283
+ alias quoted_subject subject
284
+
285
+ def subject=( str )
286
+ set_string_attr 'Subject', str
287
+ end
288
+
289
+
290
+ #
291
+ # identity & threading
292
+ #
293
+
294
+ def message_id( default = nil )
295
+ if h = @header['message-id']
296
+ h.id || default
297
+ else
298
+ default
299
+ end
300
+ end
301
+
302
+ def message_id=( str )
303
+ set_string_attr 'Message-Id', str
304
+ end
305
+
306
+ def in_reply_to( default = nil )
307
+ if h = @header['in-reply-to']
308
+ h.ids
309
+ else
310
+ default
311
+ end
312
+ end
313
+
314
+ def in_reply_to=( *idstrs )
315
+ set_string_array_attr 'In-Reply-To', idstrs
316
+ end
317
+
318
+ def references( default = nil )
319
+ if h = @header['references']
320
+ h.refs
321
+ else
322
+ default
323
+ end
324
+ end
325
+
326
+ def references=( *strs )
327
+ set_string_array_attr 'References', strs
328
+ end
329
+
330
+
331
+ #
332
+ # MIME headers
333
+ #
334
+
335
+ def mime_version( default = nil )
336
+ if h = @header['mime-version']
337
+ h.version || default
338
+ else
339
+ default
340
+ end
341
+ end
342
+
343
+ def mime_version=( m, opt = nil )
344
+ if opt
345
+ if h = @header['mime-version']
346
+ h.major = m
347
+ h.minor = opt
348
+ else
349
+ store 'Mime-Version', "#{m}.#{opt}"
350
+ end
351
+ else
352
+ store 'Mime-Version', m
353
+ end
354
+ m
355
+ end
356
+
357
+
358
+ def content_type( default = nil )
359
+ if h = @header['content-type']
360
+ h.content_type || default
361
+ else
362
+ default
363
+ end
364
+ end
365
+
366
+ def main_type( default = nil )
367
+ if h = @header['content-type']
368
+ h.main_type || default
369
+ else
370
+ default
371
+ end
372
+ end
373
+
374
+ def sub_type( default = nil )
375
+ if h = @header['content-type']
376
+ h.sub_type || default
377
+ else
378
+ default
379
+ end
380
+ end
381
+
382
+ def set_content_type( str, sub = nil, param = nil )
383
+ if sub
384
+ main, sub = str, sub
385
+ else
386
+ main, sub = str.split(%r</>, 2)
387
+ raise ArgumentError, "sub type missing: #{str.inspect}" unless sub
388
+ end
389
+ if h = @header['content-type']
390
+ h.main_type = main
391
+ h.sub_type = sub
392
+ h.params.clear
393
+ else
394
+ store 'Content-Type', "#{main}/#{sub}"
395
+ end
396
+ @header['content-type'].params.replace param if param
397
+
398
+ str
399
+ end
400
+
401
+ alias content_type= set_content_type
402
+
403
+ def type_param( name, default = nil )
404
+ if h = @header['content-type']
405
+ h[name] || default
406
+ else
407
+ default
408
+ end
409
+ end
410
+
411
+ def charset( default = nil )
412
+ if h = @header['content-type']
413
+ h['charset'] or default
414
+ else
415
+ default
416
+ end
417
+ end
418
+
419
+ def charset=( str )
420
+ if str
421
+ if h = @header[ 'content-type' ]
422
+ h['charset'] = str
423
+ else
424
+ store 'Content-Type', "text/plain; charset=#{str}"
425
+ end
426
+ end
427
+ str
428
+ end
429
+
430
+
431
+ def transfer_encoding( default = nil )
432
+ if h = @header['content-transfer-encoding']
433
+ h.encoding || default
434
+ else
435
+ default
436
+ end
437
+ end
438
+
439
+ def transfer_encoding=( str )
440
+ set_string_attr 'Content-Transfer-Encoding', str
441
+ end
442
+
443
+ alias encoding transfer_encoding
444
+ alias encoding= transfer_encoding=
445
+ alias content_transfer_encoding transfer_encoding
446
+ alias content_transfer_encoding= transfer_encoding=
447
+
448
+
449
+ def disposition( default = nil )
450
+ if h = @header['content-disposition']
451
+ h.disposition || default
452
+ else
453
+ default
454
+ end
455
+ end
456
+
457
+ alias content_disposition disposition
458
+
459
+ def set_disposition( str, params = nil )
460
+ if h = @header['content-disposition']
461
+ h.disposition = str
462
+ h.params.clear
463
+ else
464
+ store('Content-Disposition', str)
465
+ h = @header['content-disposition']
466
+ end
467
+ h.params.replace params if params
468
+ end
469
+
470
+ alias disposition= set_disposition
471
+ alias set_content_disposition set_disposition
472
+ alias content_disposition= set_disposition
473
+
474
+ def disposition_param( name, default = nil )
475
+ if h = @header['content-disposition']
476
+ h[name] || default
477
+ else
478
+ default
479
+ end
480
+ end
481
+
482
+ ###
483
+ ### utils
484
+ ###
485
+
486
+ def create_reply
487
+ mail = TMail::Mail.parse('')
488
+ mail.subject = 'Re: ' + subject('').sub(/\A(?:\[[^\]]+\])?(?:\s*Re:)*\s*/i, '')
489
+ mail.to_addrs = reply_addresses([])
490
+ mail.in_reply_to = [message_id(nil)].compact
491
+ mail.references = references([]) + [message_id(nil)].compact
492
+ mail.mime_version = '1.0'
493
+ mail
494
+ end
495
+
496
+
497
+ def base64_encode
498
+ store 'Content-Transfer-Encoding', 'Base64'
499
+ self.body = Base64.folding_encode(self.body)
500
+ end
501
+
502
+ def base64_decode
503
+ if /base64/i === self.transfer_encoding('')
504
+ store 'Content-Transfer-Encoding', '8bit'
505
+ self.body = Base64.decode(self.body, @config.strict_base64decode?)
506
+ end
507
+ end
508
+
509
+
510
+ def destinations( default = nil )
511
+ ret = []
512
+ %w( to cc bcc ).each do |nm|
513
+ if h = @header[nm]
514
+ h.addrs.each {|i| ret.push i.address }
515
+ end
516
+ end
517
+ ret.empty? ? default : ret
518
+ end
519
+
520
+ def each_destination( &block )
521
+ destinations([]).each do |i|
522
+ if Address === i
523
+ yield i
524
+ else
525
+ i.each(&block)
526
+ end
527
+ end
528
+ end
529
+
530
+ alias each_dest each_destination
531
+
532
+
533
+ def reply_addresses( default = nil )
534
+ reply_to_addrs(nil) or from_addrs(nil) or default
535
+ end
536
+
537
+ def error_reply_addresses( default = nil )
538
+ if s = sender(nil)
539
+ [s]
540
+ else
541
+ from_addrs(default)
542
+ end
543
+ end
544
+
545
+
546
+ def multipart?
547
+ main_type('').downcase == 'multipart'
548
+ end
549
+
550
+ end # class Mail
551
+
552
+ end # module TMail