mms2r 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/.gemtest +0 -0
  2. data/Gemfile +11 -11
  3. data/Gemfile.lock +28 -24
  4. data/History.txt +7 -0
  5. data/Manifest.txt +5 -4
  6. data/README.txt +8 -5
  7. data/conf/1nbox.net.yml +4 -4
  8. data/conf/aliases.yml +1 -1
  9. data/conf/mediamessaging.o2.co.uk.yml +1 -1
  10. data/conf/messaging.nextel.com.yml +8 -8
  11. data/conf/mms.3ireland.ie.yml +8 -8
  12. data/conf/mms.ae.yml +1 -1
  13. data/conf/mms.alltel.com.yml +2 -2
  14. data/conf/mms.att.net.yml +9 -9
  15. data/conf/mms.dobson.net.yml +3 -3
  16. data/conf/mms.luxgsm.lu.yml +8 -8
  17. data/conf/mms.mobileiam.ma.yml +6 -6
  18. data/conf/mms.mtn.co.za.yml +4 -4
  19. data/conf/mms.myhelio.com.yml +7 -7
  20. data/conf/mms.netcom.no.yml +2 -2
  21. data/conf/mms.o2online.de.yml +6 -6
  22. data/conf/mms.three.co.uk.yml +9 -9
  23. data/conf/mms.uscc.net.mail +6 -6
  24. data/conf/mms.vodacom4me.co.za.yml +4 -4
  25. data/conf/mms2r_media.yml +20 -20
  26. data/conf/mobile.indosat.net.id.yml +4 -4
  27. data/conf/msg.telus.com.yml +2 -2
  28. data/conf/orangemms.net.yml +7 -7
  29. data/conf/pm.sprint.com.yml +8 -8
  30. data/conf/pxt.vodafone.net.nz.yml +3 -3
  31. data/conf/rci.rogers.com.yml +7 -7
  32. data/conf/sms.sasktel.com.yml +9 -9
  33. data/conf/tmomail.net.yml +22 -22
  34. data/conf/txt.bell.ca.yml +2 -2
  35. data/conf/unicel.com.yml +3 -3
  36. data/conf/vmpix.com.yml +7 -7
  37. data/conf/vzwpix.com.yml +6 -6
  38. data/conf/waw.plspictures.com.yml +8 -9
  39. data/dev_tools/anonymizer.rb +1 -1
  40. data/lib/{mail_ext.rb → ext/mail.rb} +0 -0
  41. data/lib/ext/object.rb +11 -0
  42. data/lib/mms2r.rb +10 -20
  43. data/lib/mms2r/media.rb +33 -29
  44. data/mms2r.gemspec +23 -43
  45. data/test/fixtures/ad_new.txt +5 -0
  46. data/test/fixtures/dici_un_mois_georgie.txt +1 -0
  47. data/test/hax.rb +8 -0
  48. data/test/test_1nbox_net.rb +2 -2
  49. data/test/test_bell_canada.rb +1 -1
  50. data/test/test_bellsouth_net.rb +2 -2
  51. data/test/test_helper.rb +5 -9
  52. data/test/test_mediamessaging_o2_co_uk.rb +1 -1
  53. data/test/test_messaging_nextel_com.rb +1 -1
  54. data/test/test_messaging_sprintpcs_com.rb +1 -1
  55. data/test/test_mms2r_media.rb +35 -23
  56. data/test/test_mms_3ireland_ie.rb +1 -1
  57. data/test/test_mms_ae.rb +1 -1
  58. data/test/test_mms_alltel_com.rb +1 -1
  59. data/test/test_mms_att_net.rb +2 -2
  60. data/test/test_mms_dobson_net.rb +1 -1
  61. data/test/test_mms_luxgsm_lu.rb +1 -1
  62. data/test/test_mms_mobileiam_ma.rb +1 -1
  63. data/test/test_mms_mtn_co_za.rb +1 -1
  64. data/test/test_mms_mycricket_com.rb +1 -1
  65. data/test/test_mms_myhelio_com.rb +1 -1
  66. data/test/test_mms_netcom_no.rb +1 -1
  67. data/test/test_mms_o2online_de.rb +1 -1
  68. data/test/test_mms_three_co_uk.rb +1 -1
  69. data/test/test_mms_uscc_net.rb +1 -1
  70. data/test/test_mms_vodacom4me_co_za.rb +1 -1
  71. data/test/test_mobile_indosat_net_id.rb +1 -1
  72. data/test/test_msg_telus_com.rb +1 -1
  73. data/test/test_orangemms_net.rb +1 -1
  74. data/test/test_pm_sprint_com.rb +1 -1
  75. data/test/test_pxt_vodafone_net_nz.rb +1 -1
  76. data/test/test_rci_rogers_com.rb +1 -1
  77. data/test/test_sms_sasktel_com.rb +1 -1
  78. data/test/test_tmomail_net.rb +4 -4
  79. data/test/test_unicel_com.rb +1 -1
  80. data/test/test_vmpix_com.rb +1 -1
  81. data/test/test_vzwpix_com.rb +3 -7
  82. data/test/test_waw_plspictures_com.rb +1 -1
  83. metadata +91 -118
  84. data/.gitignore +0 -7
  85. data/dev_tools/github.rb +0 -8
  86. data/test/test_github.rb +0 -12
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  ignore:
3
- text/plain:
4
- - /\AThank you for using Picture and Video Messaging by U\.S\. Cellular.*/m
5
- transform:
6
- text/plain:
7
- - - /\A(.+?)\s+Thank you for using Picture and Video Messaging by U\.S\. Cellular.*/m
8
- - "\1"
3
+ text/plain:
4
+ - !ruby/regexp /\AThank you for using Picture and Video Messaging by U\.S\. Cellular.*/m
5
+ transform:
6
+ text/plain:
7
+ - - !ruby/regexp /\A(.+?)\s+Thank you for using Picture and Video Messaging by U\.S\. Cellular.*/m
8
+ - "\\1"
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  ignore:
3
3
  text/html:
4
- - /.*You have an <b>MMS<\/b> message!.*/m
4
+ - !ruby/regexp /.*You have an <b>MMS<\/b> message!.*/m
5
5
  transform:
6
6
  text/plain:
7
- - - /\s*This is an MMS message brought to you by Vodacom\. Click here to view online presentation http:\/\/mms.vodacom4me.co.za\/.*$/
7
+ - - !ruby/regexp /\s*This is an MMS message brought to you by Vodacom\. Click here to view online presentation http:\/\/mms.vodacom4me.co.za\/.*$/
8
8
  - ""
9
9
  number:
10
10
  - from
11
- - /^([^\s]+)\s.*/
12
- - "\1"
11
+ - !ruby/regexp /^([^\s]+)\s.*/
12
+ - "\\1"
13
13
 
@@ -1,26 +1,26 @@
1
1
  ---
2
2
  ignore:
3
3
  text/plain:
4
- - /^\(no subject\)$/i
5
- - /\ASent via BlackBerry (from|by) .*$/im
6
- - /\ASent from my Verizon Wireless BlackBerry$/im
7
- - /\ASent from (my|your) iPhone.?$/im
8
- - /\ASent on the Sprint.* Now Network.*$/im
4
+ - !ruby/regexp /^\(no subject\)$/i
5
+ - !ruby/regexp /\ASent via BlackBerry (from|by) .*$/im
6
+ - !ruby/regexp /\ASent from my Verizon Wireless BlackBerry$/im
7
+ - !ruby/regexp /\ASent from (my|your) iPhone.?$/im
8
+ - !ruby/regexp /\ASent on the Sprint.* Now Network.*$/im
9
9
  multipart/mixed:
10
- - "/^Attachment: /i"
11
- transform:
12
- text/plain:
13
- - - /\A(.*?)Sent via BlackBerry (from|by) .*$/im
14
- - "\1"
15
- - - /\A(.*?)Sent from my Verizon Wireless BlackBerry$/im
16
- - "\1"
17
- - - /\A(.*?)Sent from (my|your) iPhone.?$/im
18
- - "\1"
19
- - - /\A(.*?)\s+image\/jpeg$/im
20
- - "\1"
21
- - - /\A(.*?)Sent on the Sprint.* Now Network.*$/im
22
- - "\1"
23
- device_types:
10
+ - !ruby/regexp "/^Attachment: /i"
11
+ transform:
12
+ text/plain:
13
+ - - !ruby/regexp /\A(.*?)Sent via BlackBerry (from|by) .*$/im
14
+ - "\\1"
15
+ - - !ruby/regexp /\A(.*?)Sent from my Verizon Wireless BlackBerry$/im
16
+ - "\\1"
17
+ - - !ruby/regexp /\A(.*?)Sent from (my|your) iPhone.?$/im
18
+ - "\\1"
19
+ - - !ruby/regexp /\A(.*?)\s+image\/jpeg$/im
20
+ - "\\1"
21
+ - - !ruby/regexp /\A(.*?)Sent on the Sprint.* Now Network.*$/im
22
+ - "\\1"
23
+ device_types:
24
24
  headers:
25
25
  x-mailer:
26
26
  :iphone: !ruby/regexp /iPhone Mail/i
@@ -29,7 +29,7 @@ device_types:
29
29
  :iphone: !ruby/regexp /iPhone Mail/i
30
30
  x-rim-org-msg-ref-id:
31
31
  :blackberry: !ruby/regexp /.+/
32
- # TODO do something about the assortment of camera models that have
32
+ # TODO do something about the assortment of camera models that have
33
33
  # been seen:
34
34
  # 1.3 Megapixel, 2.0 Megapixel, BlackBerry, CU920, G'z One TYPE-S,
35
35
  # Hermes, iPhone, LG8700, LSI_S5K4AAFA, Micron MT9M113 1.3MP YUV,
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  ignore:
3
3
  text/plain:
4
- - /\A\.\z/im
4
+ - !ruby/regexp /\A\.\z/im
5
5
  - .
6
6
  text/html:
7
- - /I-Memova - Email Praktis. Cara Taktis. Powered by IM2./i
7
+ - !ruby/regexp /I-Memova - Email Praktis. Cara Taktis. Powered by IM2./i
8
8
  image/jpeg:
9
9
  - cp__newBanner.jpg
10
10
  number:
11
11
  - return-path
12
- - /^([^@]+)@.*/
13
- - "\1"
12
+ - !ruby/regexp /^([^@]+)@.*/
13
+ - "\\1"
14
14
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  ignore:
3
3
  text/plain:
4
- - /This is an MMS message. Please go to http/m
4
+ - !ruby/regexp /This is an MMS message. Please go to http/m
5
5
  text/html:
6
- - /You've received a Message from a TELUS phone./m
6
+ - !ruby/regexp /You've received a Message from a TELUS phone./m
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  ignore:
3
3
  application/smil:
4
- - /\A<smil><head><layout><root-layout height=/m
5
- text/plain:
4
+ - !ruby/regexp /\A<smil><head><layout><root-layout height=/m
5
+ text/plain:
6
6
  - banniere.txt
7
- - /\A--\s+This Orange Multi Media Message was sent wirefree from an Orange MMS.*/mi
8
- transform:
9
- text/plain:
10
- - - /^Orange UK MMS$/i
7
+ - !ruby/regexp /\A--\s+This Orange Multi Media Message was sent wirefree from an Orange MMS.*/mi
8
+ transform:
9
+ text/plain:
10
+ - - !ruby/regexp /^Orange UK MMS$/i
11
11
  - ""
12
- - - /^Wiadomo\303\205\302\233\303\204\302\207 multimedialna\.$/i
12
+ - - !ruby/regexp /^Wiadomo.* multimedialna\.$/i
13
13
  - ""
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  ignore:
3
3
  text/html:
4
- - /We're sorry, this page is not available. We apologize for the inconvenience./mi
5
- text/plain:
6
- - /You have new [Picture|Video] Mail!\s+Click Go\/View to see now./mi
7
- transform:
8
- text/plain:
9
- - - /^You have new Picture Mail!$/i
4
+ - !ruby/regexp /We're sorry, this page is not available. We apologize for the inconvenience./mi
5
+ text/plain:
6
+ - !ruby/regexp /You have new [Picture|Video] Mail!\s+Click Go\/View to see now./mi
7
+ transform:
8
+ text/plain:
9
+ - - !ruby/regexp /^You have new Picture Mail!$/i
10
10
  - ""
11
- - - /^New Message$/i
11
+ - - !ruby/regexp /^New Message$/i
12
12
  - ""
13
- - - /^PictureMail$/i
13
+ - - !ruby/regexp /^PictureMail$/i
14
14
  - ""
@@ -1,5 +1,5 @@
1
1
  ---
2
- transform:
3
- text/plain:
4
- - - /^You have a PXT from \d+$/i
2
+ transform:
3
+ text/plain:
4
+ - - !ruby/regexp /^You have a PXT from \d+$/i
5
5
  - ""
@@ -1,18 +1,18 @@
1
1
  ---
2
2
  ignore:
3
3
  image/gif:
4
- - /^.*$/i
4
+ - !ruby/regexp /^.*$/i
5
5
  text/plain:
6
- - /^Uve received a video or picture msg from .*/im
6
+ - !ruby/regexp /^Uve received a video or picture msg from .*/im
7
7
  text/html:
8
- - /Picture from your Rogers Wireless friend/im
8
+ - !ruby/regexp /Picture from your Rogers Wireless friend/im
9
9
 
10
10
  transform:
11
- text/plain:
12
- - - /^You have received a Picture Message from your Rogers Wireless.*/i
11
+ text/plain:
12
+ - - !ruby/regexp /^You have received a Picture Message from your Rogers Wireless.*/i
13
13
  - ""
14
14
 
15
15
  number:
16
16
  - from
17
- - /^([^\/|^@]+).*/
18
- - "\1"
17
+ - !ruby/regexp /^([^\/@]+).*/
18
+ - "\\1"
@@ -1,12 +1,12 @@
1
1
  ---
2
2
  ignore:
3
- text/html:
4
- - /.*/im
5
- text/plain:
6
- - /^You have received a New Message/i
7
- image/gif:
8
- - /.*/im
9
- transform:
10
- text/plain:
11
- - - /^A Picture\/Video Message!$/i
3
+ text/html:
4
+ - !ruby/regexp /.*/im
5
+ text/plain:
6
+ - !ruby/regexp /^You have received a New Message/i
7
+ image/gif:
8
+ - !ruby/regexp /.*/im
9
+ transform:
10
+ text/plain:
11
+ - - !ruby/regexp /^A Picture\/Video Message!$/i
12
12
  - ""
@@ -1,28 +1,28 @@
1
1
  ---
2
2
  ignore:
3
- image/jpeg:
4
- - /^masthead.jpg$/i
5
- - /^logo.jpg$/i
6
- image/gif:
7
- - /^dottedline350.gif$/i
8
- - /^dottedline600.gif$/i
9
- - /^dottedLine_350.gif$/i
10
- - /^dottedLine_600.gif$/i
11
- - /^spacer.gif$/i
12
- - /^video.gif$/i
13
- - /^audio.gif$/i
14
- - /^tmobilelogo.gif$/i
15
- - /^tmobilespace.gif$/i
16
- text/html:
17
- - /<html>\s+<head>\s+<title>T-Mobile<\/title>/m
18
- - /<title>MMS E-Mail<\/title>/m
3
+ image/jpeg:
4
+ - !ruby/regexp /^masthead.jpg$/i
5
+ - !ruby/regexp /^logo.jpg$/i
6
+ image/gif:
7
+ - !ruby/regexp /^dottedline350.gif$/i
8
+ - !ruby/regexp /^dottedline600.gif$/i
9
+ - !ruby/regexp /^dottedLine_350.gif$/i
10
+ - !ruby/regexp /^dottedLine_600.gif$/i
11
+ - !ruby/regexp /^spacer.gif$/i
12
+ - !ruby/regexp /^video.gif$/i
13
+ - !ruby/regexp /^audio.gif$/i
14
+ - !ruby/regexp /^tmobilelogo.gif$/i
15
+ - !ruby/regexp /^tmobilespace.gif$/i
16
+ text/html:
17
+ - !ruby/regexp /<html>\s+<head>\s+<title>T-Mobile<\/title>/m
18
+ - !ruby/regexp /<title>MMS E-Mail<\/title>/m
19
19
 
20
20
  number:
21
21
  - from
22
- - /^"?([^\/|^@]+).*/
23
- - "\1"
22
+ - !ruby/regexp /^"?([^\/@]+).*/
23
+ - "\\1"
24
24
 
25
- transform:
26
- text/plain:
27
- - - /.*\s+Text:\s+(.*?)\s+-+\s.*/im
28
- - "\1"
25
+ transform:
26
+ text/plain:
27
+ - - !ruby/regexp /.*\s+Text:\s+(.*?)\s+-+\s.*/im
28
+ - "\\1"
@@ -1,4 +1,4 @@
1
1
  transform:
2
2
  text/html:
3
- - [/.*(<html)/im, "\1"]
4
-
3
+ - - !ruby/regexp /.*(<html)/im
4
+ - "\\1"
@@ -1,6 +1,6 @@
1
1
  ---
2
- transform:
3
- text/plain:
4
- - - /^Unicel$/i
2
+ transform:
3
+ text/plain:
4
+ - - !ruby/regexp /^Unicel$/i
5
5
  - ""
6
6
 
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  ignore:
3
3
  text/html:
4
- - /This message is from\s+a Virgin Mobile user. Enjoy./mi
5
- text/plain:
6
- - /^This is an MMS message\.$/i
4
+ - !ruby/regexp /This message is from\s+a Virgin Mobile user. Enjoy./mi
5
+ text/plain:
6
+ - !ruby/regexp /^This is an MMS message\.$/i
7
7
 
8
- transform:
9
- text/plain:
10
- - - /(.*?)-+\s+Sent by Text Messaging from a mobile device.*/im
11
- - "\1"
8
+ transform:
9
+ text/plain:
10
+ - - !ruby/regexp /(.*?)-+\s+Sent by Text Messaging from a mobile device.*/im
11
+ - "\\1"
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  ignore:
3
- text/plain:
4
- - /\AThis message (was|has been) sent using .* from Verizon Wireless!.*/m
5
- transform:
6
- text/plain:
7
- - - /\A(.+?)\s+This message (was|has been) sent using .* from Verizon Wireless!.*/m
8
- - "\1"
3
+ text/plain:
4
+ - !ruby/regexp /\AThis message (was|has been) sent using .* from Verizon Wireless!.*/m
5
+ transform:
6
+ text/plain:
7
+ - - !ruby/regexp /\A(.+?)\s+This message (was|has been) sent using .* from Verizon Wireless!.*/m
8
+ - "\\1"
@@ -1,15 +1,14 @@
1
1
  ---
2
- transform:
3
- text/plain:
4
- - - /^You have received a Multimedia Message$/i
2
+ transform:
3
+ text/plain:
4
+ - - !ruby/regexp /^You have received a Multimedia Message$/i
5
5
  - ""
6
6
  number:
7
7
  - return-path
8
- - /^([^@]+)@.*/
9
- - "\1"
8
+ - !ruby/regexp /^([^@]+)@.*/
9
+ - "\\1"
10
10
  ignore:
11
- text/html:
12
- - /.*/m
11
+ text/html:
12
+ - !ruby/regexp /.*/m
13
13
  text/plain:
14
- - /\AA New Photo\/Video Message.\s+Click Go\/View to see now http/im
15
-
14
+ - !ruby/regexp /\AA New Photo\/Video Message.\s+Click Go\/View to see now http/im
@@ -13,7 +13,7 @@ message = File.read(message_file)
13
13
  message.gsub!(phone_number, '2068675309')
14
14
  message.gsub!(email_address, 'tommy.tutone@example.com')
15
15
 
16
- out = File.open(message_file, "w")
16
+ out = File.open(message_file, "wb")
17
17
  out.puts message
18
18
  out.close
19
19
 
File without changes
@@ -0,0 +1,11 @@
1
+ class Object
2
+
3
+ def blank?
4
+ respond_to?(:empty?) ? empty? : !self
5
+ end
6
+
7
+ def present?
8
+ !blank?
9
+ end
10
+
11
+ end
@@ -39,7 +39,7 @@ module MMS2R
39
39
  ##
40
40
  # MMS2R library version
41
41
 
42
- VERSION = '3.3.1'
42
+ VERSION = '3.4.0'
43
43
 
44
44
  end
45
45
 
@@ -52,23 +52,8 @@ module MMS2R
52
52
 
53
53
  end
54
54
 
55
- unless Object.respond_to?(:blank?)
56
- class Object
57
- def blank?
58
- if respond_to?(:empty?) && respond_to?(:strip)
59
- empty? or strip.empty?
60
- elsif respond_to?(:empty?)
61
- empty?
62
- else
63
- !self
64
- end
65
- end
66
- end
67
- end
68
-
69
- %W{ mail fileutils pathname tmpdir yaml uuidtools iconv exifr }.each do |g|
55
+ %W{ yaml mail fileutils pathname tmpdir yaml digest/sha1 iconv exifr }.each do |g|
70
56
  begin
71
- gem 'mail', '= 2.2.13' if g == 'mail'
72
57
  require g
73
58
  rescue LoadError
74
59
  require 'rubygems'
@@ -76,7 +61,12 @@ end
76
61
  end
77
62
  end
78
63
 
79
- require File.join(File.dirname(__FILE__), 'mail_ext')
80
- require File.join(File.dirname(__FILE__), 'mms2r', 'media')
81
- require File.join(File.dirname(__FILE__), 'mms2r', 'media', 'sprint')
64
+ # HAX to not deal with Psych YAML parser in Ruby >= 1.9
65
+ #YAML::ENGINE.yamler= 'syck' if defined?(YAML::ENGINE)
66
+
67
+ require File.join(File.dirname(__FILE__), 'ext/mail')
68
+ require File.join(File.dirname(__FILE__), 'ext/object')
69
+ require File.join(File.dirname(__FILE__), 'mms2r/media')
70
+ require File.join(File.dirname(__FILE__), 'mms2r/media/sprint')
71
+
82
72
  MMS2R.register('pm.sprint.com', MMS2R::Media::Sprint)
@@ -64,15 +64,15 @@
64
64
  # The root hash itself has two hashes under the keys 'ignore' and 'transform',
65
65
  # and an array under the 'number' key.
66
66
  # Each hash is itself keyed by mime-type. The value pointed to by the mime-type
67
- # key is an array. The ignore arrays are first evaluated as a regular expressions
68
- # and if the evaluation fails as a equality for a string filename. Ignores
69
- # work by filename for the multi-part of the MMS that is being inspected. The
70
- # array pointed to by the 'number' key represents an alternate mail header where
71
- # the sender's number can be found with a regular expression and replacement
72
- # value for a gsub eval.
67
+ # key is an array. The ignore arrays are first inspected as regular expressions
68
+ # else are used as a equality for a string filename. Ignores # work by filename
69
+ # for the multi-part of the MMS that is being inspected. The array pointed to
70
+ # by the 'number' key represents an alternate mail header where the sender's
71
+ # number can be found with a regular expression and replacement value for a
72
+ # gsub.
73
73
  #
74
74
  # The transform arrays are themselves an array of two element arrays. The elements
75
- # are parameters for gsub and will be evaluated from within the ruby code.
75
+ # are regexp parameters for gsub.
76
76
  #
77
77
  # Ignore instructions are honored first then transform instructions. In the sample,
78
78
  # masthead.jpg is ignored as a regular expression, and spacer.gif is ignored as a
@@ -159,7 +159,7 @@ module MMS2R
159
159
  end
160
160
 
161
161
  f = File.expand_path(File.join(self.conf_dir(), "from.yml"))
162
- from = YAML::load_file(f) rescue {}
162
+ from = YAML::load_file(f)
163
163
 
164
164
  ret = case
165
165
  when from.include?(from_domain)
@@ -190,9 +190,10 @@ module MMS2R
190
190
  log("#{self.class} created", :info)
191
191
  @carrier = self.class.domain(mail)
192
192
  @dir_count = 0
193
+ sha = Digest::SHA1.hexdigest("#{@carrier}-#{Time.now.to_i}-#{rand}")
193
194
  @media_dir = File.expand_path(
194
195
  File.join(self.tmp_dir(),
195
- "#{self.safe_message_id(@mail.message_id)}_#{UUIDTools::UUID.random_create}"))
196
+ "#{self.safe_message_id(@mail.message_id)}_#{sha}"))
196
197
  @media = {}
197
198
  @was_processed = false
198
199
  @number = nil
@@ -204,11 +205,11 @@ module MMS2R
204
205
  @default_html = nil
205
206
 
206
207
  f = File.expand_path(File.join(self.conf_dir(), "aliases.yml"))
207
- @aliases = YAML::load_file(f) rescue {}
208
+ @aliases = YAML::load_file(f)
208
209
 
209
210
  conf = "#{@aliases[@carrier] || @carrier}.yml"
210
211
  f = File.expand_path(File.join(self.conf_dir(), conf))
211
- c = YAML::load_file(f) rescue {}
212
+ c = File.exist?(f) ? YAML::load_file(f) : {}
212
213
  @config = self.class.initialize_config(c)
213
214
 
214
215
  processor_module = MMS2R::CARRIERS[@carrier]
@@ -228,7 +229,7 @@ module MMS2R
228
229
  unless @number
229
230
  params = config['number']
230
231
  if params && params.any? && (header = mail.header[params[0]])
231
- @number = header.to_s.gsub(eval(params[1]), params[2])
232
+ @number = header.to_s.gsub(params[1], params[2])
232
233
  end
233
234
  if @number.nil? || @number.blank?
234
235
  @number = mail.from.first.split(/@|\//).first rescue ""
@@ -383,8 +384,8 @@ module MMS2R
383
384
  def ignore_media?(type, part)
384
385
  ignores = config['ignore'][type] || []
385
386
  ignore = ignores.detect{ |test| filename?(part) == test}
386
- ignore ||= ignores.detect{ |test| filename?(part) =~ eval(test) if test.index('/') == 0 }
387
- ignore ||= ignores.detect{ |test| part.body.decoded.strip =~ eval(test) if test.index('/') == 0 }
387
+ ignore ||= ignores.detect{ |test| filename?(part) =~ test if test.is_a?(Regexp) }
388
+ ignore ||= ignores.detect{ |test| part.body.decoded.strip =~ test if test.is_a?(Regexp) }
388
389
  ignore ||= (part.body.decoded.strip.size == 0 ? true : nil)
389
390
  ignore.nil? ? false : true
390
391
  end
@@ -408,7 +409,7 @@ module MMS2R
408
409
  if part.part_type? =~ /^text\// ||
409
410
  part.part_type? == 'application/smil'
410
411
  type, content = transform_text_part(part)
411
- mode = 'w'
412
+ mode = 'wb'
412
413
  else
413
414
  if part.part_type? == 'application/octet-stream'
414
415
  type = type_from_filename(filename?(part))
@@ -431,22 +432,25 @@ module MMS2R
431
432
  # configuration.
432
433
 
433
434
  def transform_text(type, text, original_encoding = 'ISO-8859-1')
434
-
435
435
  return type, text if !config['transform'] || !(transforms = config['transform'][type])
436
436
 
437
- #convert to UTF-8
438
- begin
439
- c = Iconv.new('UTF-8', original_encoding )
440
- utf_t = c.iconv(text)
441
- rescue Exception => e
442
- utf_t = text
437
+ if RUBY_VERSION < "1.9"
438
+ #convert to UTF-8
439
+ begin
440
+ c = Iconv.new('UTF-8', original_encoding )
441
+ utf_t = c.iconv(text)
442
+ rescue Exception => e
443
+ utf_t = text
444
+ end
445
+ else
446
+ utf_t = text.encoding == "ASCII-8BIT" ? text.force_encoding("ISO-8859-1").encode("UTF-8") : text
443
447
  end
444
448
 
445
449
  transforms.each do |transform|
446
450
  next unless transform.size == 2
447
451
  p = transform.first
448
452
  r = transform.last
449
- utf_t = utf_t.gsub(eval(p), r) rescue utf_t
453
+ utf_t = utf_t.gsub(p, r) rescue utf_t
450
454
  end
451
455
 
452
456
  return type, utf_t
@@ -509,13 +513,13 @@ module MMS2R
509
513
  def filename?(part)
510
514
  name = part.filename
511
515
  if (name.nil? || name.empty?)
512
- if part.content_id && part.content_id.strip =~ /^<(.+)>$/
513
- name = $1
516
+ if part.content_id && (matched = /^<(.+)>$/.match(part.content_id))
517
+ name = matched[1]
514
518
  else
515
519
  name = "#{Time.now.to_f}.#{self.default_ext(part.part_type?)}"
516
520
  end
517
521
  end
518
- # XXX fwiw, janky look for dot extension 1 to 4 chars long
522
+ # FIXME FWIW, janky look for dot extension 1 to 4 chars long
519
523
  name = (name =~ /\..{1,4}$/ ? name : "#{name}.#{self.default_ext(part.part_type?)}").strip
520
524
 
521
525
  # handle excessively large filenames
@@ -649,7 +653,7 @@ module MMS2R
649
653
 
650
654
  def self.initialize_config(c)
651
655
  f = File.expand_path(File.join(self.conf_dir(), "mms2r_media.yml"))
652
- conf = YAML::load_file(f) rescue {}
656
+ conf = YAML::load_file(f)
653
657
  conf['ignore'] ||= {} unless conf['ignore']
654
658
  conf['transform'] = {} unless conf['transform']
655
659
  conf['number'] = [] unless conf['number']
@@ -753,8 +757,8 @@ module MMS2R
753
757
  if File.size(path) > size
754
758
  size = File.size(path)
755
759
  file = File.new(path)
756
- media.each do |type,files|
757
- mime_type = type if files.detect{ |_path| _path == path }
760
+ media.each do |type,_files|
761
+ mime_type = type if _files.detect{ |_path| _path == path }
758
762
  end
759
763
  end
760
764
  end