mms2r 1.1.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +32 -2
- data/Manifest.txt +41 -79
- data/README.txt +50 -51
- data/Rakefile +3 -2
- data/conf/aliases.yml +8 -0
- data/conf/message.alltel.com.yml +14 -0
- data/conf/messaging.nextel.com.yml +10 -0
- data/conf/mms.att.net.yml +9 -0
- data/conf/mms.dobson.net.yml +4 -0
- data/conf/mms.luxgsm.lu.yml +8 -0
- data/conf/mms.myhelio.com.yml +12 -0
- data/conf/mms.netcom.no.yml +4 -0
- data/conf/mms.o2online.de.yml +8 -0
- data/conf/mms.three.co.uk.yml +15 -0
- data/conf/mms2r_media.yml +6 -0
- data/conf/orangemms.net.yml +13 -0
- data/conf/pm.sprint.com.yml +10 -0
- data/conf/pxt.vodafone.net.nz.yml +5 -0
- data/conf/tmomail.net.yml +16 -0
- data/conf/vzwpix.com.yml +8 -0
- data/dev_tools/anonymizer.rb +20 -0
- data/lib/mms2r.rb +19 -45
- data/lib/mms2r/media.rb +288 -300
- data/lib/mms2r/media/sprint.rb +189 -0
- data/test/fixtures/att-text-01.mail +27 -0
- data/test/fixtures/helio-image-01.mail +8 -8
- data/test/fixtures/helio-message-01.mail +327 -0
- data/test/fixtures/luxgsm-image-01.mail +388 -0
- data/test/fixtures/netcom-image-01.mail +556 -0
- data/test/fixtures/o2-de-image-01.mail +314 -0
- data/test/fixtures/orange-uk-image-01.mail +71 -0
- data/test/fixtures/pxt-image-01.mail +118 -0
- data/test/fixtures/sprint-broken-image-01.mail +1 -1
- data/test/fixtures/sprint-image-01.mail +211 -195
- data/test/fixtures/sprint-purged-image-01.mail +1 -1
- data/test/fixtures/sprint-two-images-01.mail +231 -198
- data/test/fixtures/sprint-video-01.mail +210 -195
- data/test/fixtures/three-uk-image-01.mail +1202 -0
- data/test/test_helper.rb +39 -0
- data/test/{test_mms2r_alltel_media.rb → test_message_alltel_com.rb} +13 -17
- data/test/{test_mms2r_nextel_media.rb → test_messaging_nextel_com.rb} +12 -19
- data/test/{test_mms2r_sprint_pcs_media.rb → test_messaging_sprintpcs_com.rb} +9 -10
- data/test/test_mms2r_media.rb +474 -316
- data/test/test_mms_att_net.rb +92 -0
- data/test/test_mms_dobson_net.rb +41 -0
- data/test/test_mms_luxgsm_lu.rb +50 -0
- data/test/test_mms_myhelio_com.rb +60 -0
- data/test/test_mms_netcom_no.rb +52 -0
- data/test/test_mms_o2online_de.rb +53 -0
- data/test/test_mms_three_co_uk.rb +42 -0
- data/test/test_orangemms_net.rb +100 -0
- data/test/test_pm_sprint_com.rb +201 -0
- data/test/test_pxt_vodafone_net_nz.rb +37 -0
- data/test/{test_mms2r_t_mobile_media.rb → test_tmomail_net.rb} +8 -19
- data/test/{test_mms2r_verizon_media.rb → test_vzwpix_com.rb} +34 -27
- data/vendor/plugins/mms2r/lib/autotest/mms2r.rb +16 -11
- metadata +128 -157
- data/conf/mms2r_alltel_media_ignore.yml +0 -13
- data/conf/mms2r_att_media_subject.yml +0 -3
- data/conf/mms2r_cingular_me_media_subject.yml +0 -3
- data/conf/mms2r_cingular_me_media_transform.yml +0 -7
- data/conf/mms2r_dobson_media_ignore.yml +0 -4
- data/conf/mms2r_helio_media_ignore.yml +0 -6
- data/conf/mms2r_media_ignore.yml +0 -5
- data/conf/mms2r_media_subject.yml +0 -3
- data/conf/mms2r_my_cingular_media_subject.yml +0 -3
- data/conf/mms2r_nextel_media_ignore.yml +0 -11
- data/conf/mms2r_orange_france_media_ignore.yml +0 -6
- data/conf/mms2r_orange_poland_media_subject.yml +0 -3
- data/conf/mms2r_sprint_media_ignore.yml +0 -7
- data/conf/mms2r_sprint_media_subject.yml +0 -3
- data/conf/mms2r_t_mobile_media_ignore.yml +0 -16
- data/conf/mms2r_verizon_media_ignore.yml +0 -4
- data/conf/mms2r_verizon_media_transform.yml +0 -5
- data/lib/mms2r/alltel_media.rb +0 -10
- data/lib/mms2r/att_media.rb +0 -13
- data/lib/mms2r/cingular_me_media.rb +0 -23
- data/lib/mms2r/dobson_media.rb +0 -13
- data/lib/mms2r/helio_media.rb +0 -20
- data/lib/mms2r/m_mode_media.rb +0 -13
- data/lib/mms2r/my_cingular_media.rb +0 -15
- data/lib/mms2r/nextel_media.rb +0 -17
- data/lib/mms2r/orange_france_media.rb +0 -10
- data/lib/mms2r/orange_poland_media.rb +0 -10
- data/lib/mms2r/sprint_media.rb +0 -182
- data/lib/mms2r/sprint_pcs_media.rb +0 -16
- data/lib/mms2r/t_mobile_media.rb +0 -21
- data/lib/mms2r/verizon_media.rb +0 -19
- data/lib/mms2r/vtext_media.rb +0 -16
- data/lib/vendor/text/format.rb +0 -1466
- data/lib/vendor/tmail.rb +0 -3
- data/lib/vendor/tmail/address.rb +0 -242
- data/lib/vendor/tmail/attachments.rb +0 -39
- data/lib/vendor/tmail/base64.rb +0 -71
- data/lib/vendor/tmail/config.rb +0 -69
- data/lib/vendor/tmail/encode.rb +0 -467
- data/lib/vendor/tmail/facade.rb +0 -552
- data/lib/vendor/tmail/header.rb +0 -914
- data/lib/vendor/tmail/info.rb +0 -35
- data/lib/vendor/tmail/loader.rb +0 -1
- data/lib/vendor/tmail/mail.rb +0 -447
- data/lib/vendor/tmail/mailbox.rb +0 -433
- data/lib/vendor/tmail/mbox.rb +0 -1
- data/lib/vendor/tmail/net.rb +0 -280
- data/lib/vendor/tmail/obsolete.rb +0 -135
- data/lib/vendor/tmail/parser.rb +0 -1522
- data/lib/vendor/tmail/port.rb +0 -377
- data/lib/vendor/tmail/quoting.rb +0 -131
- data/lib/vendor/tmail/scanner.rb +0 -41
- data/lib/vendor/tmail/scanner_r.rb +0 -263
- data/lib/vendor/tmail/stringio.rb +0 -277
- data/lib/vendor/tmail/tmail.rb +0 -1
- data/lib/vendor/tmail/utils.rb +0 -238
- data/test/fixtures/broken_from_spam.mail +0 -80
- data/test/fixtures/hello_world_empty_text.mail +0 -7
- data/test/fixtures/hello_world_mail_multipart.mail +0 -24
- data/test/fixtures/hello_world_mail_plain_no_content_type.mail +0 -7
- data/test/fixtures/hello_world_mail_plain_with_content_type.mail +0 -8
- data/test/fixtures/simple-with-two-images-two-texts.mail +0 -49
- data/test/fixtures/simple_image.mail +0 -19
- data/test/fixtures/simple_multipart_alternative.mail +0 -42
- data/test/test_mms2r_att_media.rb +0 -54
- data/test/test_mms2r_cingular_me_media.rb +0 -51
- data/test/test_mms2r_dobson_media.rb +0 -46
- data/test/test_mms2r_helio_media.rb +0 -49
- data/test/test_mms2r_m_mode_media.rb +0 -36
- data/test/test_mms2r_my_cingular_media.rb +0 -31
- data/test/test_mms2r_orange_france_media.rb +0 -53
- data/test/test_mms2r_orange_poland_media.rb +0 -42
- data/test/test_mms2r_sprint_media.rb +0 -269
- data/test/test_mms2r_vtext_media.rb +0 -28
@@ -0,0 +1,12 @@
|
|
1
|
+
---
|
2
|
+
ignore:
|
3
|
+
image/gif:
|
4
|
+
- top.gif
|
5
|
+
- bottom.gif
|
6
|
+
- middle_img.gif
|
7
|
+
text/html:
|
8
|
+
- /<html>\s+<head>\s+<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=iso-8859-1\">\s+<title>MMS Email<\/title>/im
|
9
|
+
transform:
|
10
|
+
text/plain:
|
11
|
+
- - /Note:\s{1,2}.*?\s+message:\s{1,2}(.+)$/m
|
12
|
+
- "\1"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
transform:
|
3
|
+
text/plain:
|
4
|
+
- - /^You have received a new message$/i
|
5
|
+
- ""
|
6
|
+
ignore:
|
7
|
+
image/jpeg:
|
8
|
+
- images/reb.jpg
|
9
|
+
- images/tpm.jpg
|
10
|
+
image/gif:
|
11
|
+
- images/vf9.gif
|
12
|
+
text/html:
|
13
|
+
- /<html><head>.*<title>MMS Message<\/title>/im
|
14
|
+
text/plain:
|
15
|
+
- /You have received an MMS message. To see the message correctly, you will need to view this message\s+in a graphical email application./im
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
ignore:
|
3
|
+
application/smil:
|
4
|
+
- /\A<smil><head><layout><root-layout height=/m
|
5
|
+
text/plain:
|
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
|
11
|
+
- ""
|
12
|
+
- - /^Wiadomość multimedialna.\s*$/i
|
13
|
+
- ""
|
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
ignore:
|
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
|
10
|
+
- ""
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
ignore:
|
3
|
+
image/jpeg:
|
4
|
+
- /^masthead.jpg$/i
|
5
|
+
image/gif:
|
6
|
+
- /^dottedline350.gif$/i
|
7
|
+
- /^dottedline600.gif$/i
|
8
|
+
- /^dottedLine_350.gif$/i
|
9
|
+
- /^dottedLine_600.gif$/i
|
10
|
+
- /^spacer.gif$/i
|
11
|
+
- /^video.gif$/i
|
12
|
+
- /^audio.gif$/i
|
13
|
+
- /^tmobilelogo.gif$/i
|
14
|
+
- /^tmobilespace.gif$/i
|
15
|
+
text/html:
|
16
|
+
- /<html>\s+<head>\s+<title>T-Mobile<\/title>/m
|
data/conf/vzwpix.com.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
if ARGV.size != 3
|
4
|
+
puts "Usage: anonymizer.rb message_file phone_number email_address"
|
5
|
+
exit(1)
|
6
|
+
end
|
7
|
+
|
8
|
+
message_file = ARGV[0]
|
9
|
+
phone_number = ARGV[1]
|
10
|
+
email_address = ARGV[2]
|
11
|
+
|
12
|
+
message = File.read(message_file)
|
13
|
+
message.gsub!(phone_number, '5551234')
|
14
|
+
message.gsub!(email_address, 'tommy.tutone@example.com')
|
15
|
+
|
16
|
+
out = File.open(message_file, "w")
|
17
|
+
out.puts message
|
18
|
+
out.close
|
19
|
+
|
20
|
+
|
data/lib/mms2r.rb
CHANGED
@@ -1,56 +1,26 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2007 by Mike Mondragon (mikemondragon@gmail.com)
|
2
|
+
# Copyright (c) 2007, 2008 by Mike Mondragon (mikemondragon@gmail.com)
|
3
3
|
#
|
4
4
|
# Please see the LICENSE file for licensing information.
|
5
5
|
#++
|
6
6
|
|
7
|
-
$:.unshift(File.dirname(__FILE__) + "/vendor/")
|
8
|
-
require 'mms2r/media'
|
9
|
-
require 'mms2r/alltel_media'
|
10
|
-
require 'mms2r/att_media'
|
11
|
-
require 'mms2r/cingular_me_media'
|
12
|
-
require 'mms2r/dobson_media'
|
13
|
-
require 'mms2r/helio_media'
|
14
|
-
require 'mms2r/m_mode_media'
|
15
|
-
require 'mms2r/my_cingular_media'
|
16
|
-
require 'mms2r/nextel_media'
|
17
|
-
require 'mms2r/orange_france_media'
|
18
|
-
require 'mms2r/orange_poland_media'
|
19
|
-
require 'mms2r/sprint_media'
|
20
|
-
require 'mms2r/sprint_pcs_media'
|
21
|
-
require 'mms2r/t_mobile_media'
|
22
|
-
require 'mms2r/verizon_media'
|
23
|
-
require 'mms2r/vtext_media'
|
24
|
-
|
25
7
|
module MMS2R
|
26
8
|
|
27
9
|
##
|
28
|
-
# A hash of
|
29
|
-
# The factory create method uses the hostname portion
|
30
|
-
# of an MMS's From header to select the correct type
|
31
|
-
# of MMS2R::Media product. If a specific media product
|
32
|
-
# is not available MMS2R::Media should be used.
|
10
|
+
# A hash of MMS2R processors keyed by MMS carrier domain.
|
33
11
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
'orange.fr' => MMS2R::OrangeFranceMedia,
|
44
|
-
'mmsemail.orange.pl' => MMS2R::OrangePolandMedia,
|
45
|
-
'pm.sprint.com' => MMS2R::SprintMedia,
|
46
|
-
'messaging.sprintpcs.com' => MMS2R::SprintPcsMedia,
|
47
|
-
'tmomail.net' => MMS2R::TMobileMedia,
|
48
|
-
'vzwpix.com' => MMS2R::VerizonMedia,
|
49
|
-
'vtext.com' => MMS2R::VtextMedia
|
50
|
-
}
|
12
|
+
CARRIERS = {}
|
13
|
+
|
14
|
+
##
|
15
|
+
# Registers a class as a processor for a MMS domain. Should only be
|
16
|
+
# used in special cases such as MMS2R::Media::Sprint for 'pm.sprint.com'
|
17
|
+
|
18
|
+
def self.register(domain, processor_class)
|
19
|
+
MMS2R::CARRIERS[domain] = processor_class
|
20
|
+
end
|
51
21
|
|
52
22
|
##
|
53
|
-
# A hash of file extensions for common
|
23
|
+
# A hash of file extensions for common mime-types
|
54
24
|
|
55
25
|
EXT = {
|
56
26
|
'text/plain' => 'txt',
|
@@ -65,10 +35,14 @@ module MMS2R
|
|
65
35
|
class MMS2R::Media
|
66
36
|
|
67
37
|
##
|
68
|
-
# MMS2R
|
38
|
+
# MMS2R library version
|
69
39
|
|
70
|
-
VERSION = '
|
40
|
+
VERSION = '2.0.0'
|
71
41
|
|
72
|
-
|
42
|
+
end
|
73
43
|
|
74
44
|
end
|
45
|
+
|
46
|
+
require File.join(File.dirname(__FILE__), 'mms2r', 'media')
|
47
|
+
require File.join(File.dirname(__FILE__), 'mms2r', 'media', 'sprint')
|
48
|
+
MMS2R.register('pm.sprint.com', MMS2R::Media::Sprint)
|
data/lib/mms2r/media.rb
CHANGED
@@ -1,56 +1,138 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2007 by Mike Mondragon (mikemondragon@gmail.com)
|
2
|
+
# Copyright (c) 2007, 2008 by Mike Mondragon (mikemondragon@gmail.com)
|
3
3
|
#
|
4
4
|
# Please see the LICENSE file for licensing information
|
5
5
|
#++
|
6
6
|
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'tmail', '>= 1.2.1'
|
9
|
+
require 'tmail/mail'
|
7
10
|
require 'fileutils'
|
8
11
|
require 'pathname'
|
9
12
|
require 'tmpdir'
|
10
13
|
require 'yaml'
|
11
14
|
|
12
15
|
##
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
+
# = Synopsis
|
17
|
+
#
|
18
|
+
# MMS2R is a library to collect media files from MMS messages. MMS messages
|
19
|
+
# are multipart emails and mobile carriers often inject branding into these
|
20
|
+
# messages. MMS2R strips the advertising from an MMS leaving the actual user
|
16
21
|
# generated media.
|
17
22
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
23
|
+
# The Tracker for MMS2R is located at
|
24
|
+
# http://rubyforge.org/tracker/?group_id=3065
|
25
|
+
# Please submit bugs and feature requests using the Tracker.
|
26
|
+
#
|
27
|
+
# If MMS from a carrier not known by MMS2R is encountered please submit a
|
28
|
+
# sample to the author for inclusion in this project.
|
29
|
+
#
|
30
|
+
# == Stand Alone Example
|
31
|
+
#
|
32
|
+
# require 'rubygems'
|
33
|
+
# require 'mms2r'
|
34
|
+
# mail = TMail::Mail.parse(IO.readlines("sample-MMS.file").join)
|
35
|
+
# mms = MMS2R::Media.new(mail)
|
36
|
+
# subject = mms.subject
|
37
|
+
# number = mms.number
|
38
|
+
# file = mms.default_media
|
39
|
+
# mms.purge
|
40
|
+
#
|
41
|
+
# == Rails ActionMailer#receive w/ AttachmentFu Example
|
42
|
+
#
|
43
|
+
# def receive(mail)
|
44
|
+
# mms = MMS2R::Media.new(mail)
|
45
|
+
# picture = Picture.new # picture is an attachemnt_fu model
|
46
|
+
# picture.title = mms.subject
|
47
|
+
# picture.uploaded_data = mms.default_media
|
48
|
+
# picture.save!
|
49
|
+
# mms.purge
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# == More Examples
|
53
|
+
#
|
54
|
+
# See the README.txt file for more examples
|
55
|
+
#
|
56
|
+
# == Built In Configuration
|
57
|
+
#
|
58
|
+
# A custom configuration can be created for processing the MMS from carriers
|
59
|
+
# that are not currently known by MMS2R. In the conf/ directory create a
|
60
|
+
# YAML file named by combining the domain name of the MMS sender plus a .yml
|
61
|
+
# extension. For instance the configuration of senders from AT&T's cellular
|
62
|
+
# service with a Sender pattern of 2065551212@mms.att.net have a configuration
|
63
|
+
# named conf/mms.att.net.yml
|
21
64
|
#
|
22
|
-
# The
|
23
|
-
#
|
24
|
-
# MMS2R::CARRIER_CLASSES Hash, e.g.
|
65
|
+
# The YAML configuration contains a Hash with instructions for determining what
|
66
|
+
# is content generated by the user and what is content inserted by the carrier.
|
25
67
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
68
|
+
# The root hash itself has two hashes under the keys 'ignore' and 'transform'
|
69
|
+
# Each hash is itself keyed by mime-type. The value pointed to by the mime-type
|
70
|
+
# key is an array. The ignore arrays are first evaluated as a regular expressions
|
71
|
+
# and if the evaluation fails as a equality for a string filename. Ignores
|
72
|
+
# work by filename for the multi-part of the MMS that is being inspected.
|
73
|
+
#
|
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.
|
76
|
+
#
|
77
|
+
# Ignore instructions are honored first then transform instructions. In the sample,
|
78
|
+
# masthead.jpg is ignored as a regular expression, and spacer.gif is ignored as a
|
79
|
+
# filename comparison. The transform has a match and a replacement, see the gsub
|
80
|
+
# documentation for more information about match and replace.
|
81
|
+
#
|
82
|
+
# --
|
83
|
+
# ignore:
|
84
|
+
# image/jpeg:
|
85
|
+
# - /^masthead.jpg$/i
|
86
|
+
# image/gif:
|
87
|
+
# - spacer.gif
|
88
|
+
# text/plain:
|
89
|
+
# - /\AThis message was sent using PIX-FLIX Messaging service from .*/m
|
90
|
+
# transform:
|
91
|
+
# text/plain:
|
92
|
+
# - - /\A(.+?)\s+This message was sent using PIX-FLIX Messaging .*/m
|
93
|
+
# - "\1"
|
94
|
+
#
|
95
|
+
# Carriers often provide their services under many different domain names.
|
96
|
+
# The conf/aliases.yml is a YAML file with a hash that maps alternative or
|
97
|
+
# legacy carrier names to the most common name of their service. For example
|
98
|
+
# in terms of MMS2R txt.att.net is an alias for mms.att.net. Therefore when
|
99
|
+
# an MMS with a Sender of txt.att.net is processed MMS2R will use the
|
100
|
+
# mms.att.net configuration to process the message.
|
30
101
|
|
31
102
|
module MMS2R
|
32
103
|
|
33
104
|
class MMS2R::Media
|
105
|
+
|
106
|
+
class << self #:nodoc:
|
107
|
+
# alias new so that we can use ::create to select the media processor and
|
108
|
+
# then initialize the new object
|
109
|
+
alias orig_new new
|
110
|
+
def new(mail, opts=nil)
|
111
|
+
klass = MMS2R::Media.create(mail)
|
112
|
+
klass.orig_new(mail, opts)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
34
116
|
##
|
35
117
|
# TMail object that the media files were derived from.
|
118
|
+
|
36
119
|
attr_reader :mail
|
37
120
|
|
38
121
|
##
|
39
|
-
# media returns the hash of media. The media hash
|
40
|
-
#
|
41
|
-
#
|
42
|
-
|
122
|
+
# media returns the hash of media. The media hash is keyed by mime-type
|
123
|
+
# such as 'text/plain' and the value mapped to the key is an array of
|
124
|
+
# media that are of that type.
|
125
|
+
|
43
126
|
attr_reader :media
|
44
127
|
|
45
128
|
##
|
46
|
-
# Carrier is the domain name of the carrier. If the
|
47
|
-
#
|
129
|
+
# Carrier is the domain name of the carrier. If the carrier is not known
|
130
|
+
# the carrier will be set to 'mms2r.media'
|
48
131
|
|
49
132
|
attr_reader :carrier
|
50
133
|
|
51
134
|
##
|
52
|
-
# Base working dir where media for a unique mms message are
|
53
|
-
# dropped
|
135
|
+
# Base working dir where media for a unique mms message are dropped
|
54
136
|
|
55
137
|
attr_reader :media_dir
|
56
138
|
|
@@ -60,158 +142,132 @@ module MMS2R
|
|
60
142
|
MULTIPARTS_TO_SPLIT = [ 'multipart/related', 'multipart/alternative', 'multipart/mixed' ]
|
61
143
|
|
62
144
|
##
|
63
|
-
# Factory method that creates MMS2R::Media products
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# of the carrier from which the MMS originated.
|
67
|
-
# mail is a TMail object, logger is a Logger and can be
|
68
|
-
# nil.
|
145
|
+
# Factory method that creates MMS2R::Media products based on the domain
|
146
|
+
# name of the carrier from which the MMS originated. mail is a TMail
|
147
|
+
# object.
|
69
148
|
|
70
|
-
def self.create(mail
|
149
|
+
def self.create(mail)
|
71
150
|
d = lambda{['mms2r.media',MMS2R::Media]} #sets a default to detect
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# not to choke on it.
|
76
|
-
match && match[1] && (match[1].downcase == n.downcase)
|
151
|
+
processor = MMS2R::CARRIERS.detect(d) do |n, c|
|
152
|
+
domain = mail.from.first.split('@').last rescue nil
|
153
|
+
domain == n
|
77
154
|
end
|
78
|
-
|
79
|
-
cls.new(mail, cc[0], logger)
|
155
|
+
processor.last
|
80
156
|
end
|
81
157
|
|
82
158
|
##
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
159
|
+
# Initialize a new MMS2R::Media comprised of a mail.
|
160
|
+
#
|
161
|
+
# Specify options to initialize with:
|
162
|
+
# :logger => some_logger for logging
|
163
|
+
# :process => :lazy, for non-greedy processing upon initialization
|
164
|
+
#
|
165
|
+
# #process will have to be called explicitly if the lazy process option
|
166
|
+
# is chosen.
|
86
167
|
|
87
|
-
def initialize(mail,
|
168
|
+
def initialize(mail, opts={})
|
88
169
|
|
89
170
|
@mail = mail
|
90
|
-
@
|
91
|
-
@logger = logger
|
171
|
+
@logger = opts[:logger] rescue nil
|
92
172
|
@logger.info("#{self.class} created") unless @logger.nil?
|
93
|
-
@media = Hash.new
|
94
173
|
@dir_count = 0
|
95
174
|
@media_dir = File.join(self.class.tmp_dir(),
|
96
175
|
self.class.safe_message_id(@mail.message_id))
|
97
|
-
|
176
|
+
|
177
|
+
@carrier = @mail.from.first.split('@').last rescue 'mms2r.media'
|
178
|
+
@media = {}
|
179
|
+
@was_processed = false
|
98
180
|
@number = nil
|
99
181
|
@subject = nil
|
100
182
|
@body = nil
|
101
183
|
@default_media = nil
|
102
184
|
@default_text = nil
|
185
|
+
|
186
|
+
f = File.join(self.class.conf_dir(), "aliases.yml")
|
187
|
+
@aliases = YAML::load_file(f) rescue {}
|
103
188
|
|
104
|
-
|
189
|
+
conf = @aliases[@carrier]
|
190
|
+
conf ||= @carrier
|
191
|
+
conf += ".yml"
|
192
|
+
f = File.join(self.class.conf_dir(), conf)
|
193
|
+
c = YAML::load_file(f) rescue {}
|
194
|
+
@config = self.class.initialize_config(c)
|
195
|
+
|
196
|
+
lazy = (opts[:process] == :lazy) rescue false
|
197
|
+
self.process() unless lazy
|
105
198
|
end
|
106
199
|
|
107
200
|
##
|
108
|
-
# Get the phone number associated with this MMS if it exists.
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
# phone number as the username.
|
201
|
+
# Get the phone number associated with this MMS if it exists. The value
|
202
|
+
# returned is simplistic, it is just the user name of the from address
|
203
|
+
# before the @ symbol. Validation of the number is left to you. Most
|
204
|
+
# carriers are using the real phone number as the username.
|
113
205
|
|
114
206
|
def number
|
115
207
|
# override this method in a child if the number exists elsewhere (like Sprint)
|
116
|
-
@number ||=
|
117
|
-
end
|
118
|
-
|
119
|
-
def get_number # :nodoc:
|
120
|
-
sclz.method_deprecated(:get_number, :number)
|
121
|
-
self.number
|
208
|
+
@number ||= mail.from.first.split('@').first rescue ""
|
122
209
|
end
|
123
210
|
|
124
211
|
##
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# ignored.
|
212
|
+
# Return the Subject for this message, returns "" for default carrier
|
213
|
+
# subject such as 'Multimedia message' for ATT&T carrier.
|
128
214
|
|
129
215
|
def subject
|
130
216
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
yf = File.join(self.class.conf_dir(), "#{f}")
|
141
|
-
a = a + YAML::load_file(yf) if File::exist?(yf)
|
142
|
-
# class default subjects
|
143
|
-
f = clz.yaml_file_name(clz, :subject)
|
144
|
-
yf = File.join(self.class.conf_dir(), "#{f}")
|
145
|
-
a = a + YAML::load_file(yf) if File::exist?(yf)
|
146
|
-
return @subject ||= subject if a.empty?
|
147
|
-
return @subject ||= nil if a.detect{|r| r.match(subject.strip)}
|
148
|
-
return @subject ||= subject
|
149
|
-
end
|
217
|
+
unless @subject
|
218
|
+
subject = mail.subject.strip rescue ""
|
219
|
+
ignores = config['ignore']['text/plain'] rescue nil
|
220
|
+
if ignores && ignores.detect{|s| s == subject}
|
221
|
+
@subject = ""
|
222
|
+
else
|
223
|
+
@subject = transform_text('text/plain', subject).last
|
224
|
+
end
|
225
|
+
end
|
150
226
|
|
151
|
-
|
152
|
-
sclz.method_deprecated(:get_subject, :subject)
|
153
|
-
self.subject
|
227
|
+
@subject
|
154
228
|
end
|
155
|
-
|
229
|
+
|
156
230
|
# Convenience method that returns a string including all the text of the
|
157
|
-
# first text/plain file found.
|
231
|
+
# first text/plain file found. Returns empty string if no body text
|
158
232
|
# is found.
|
159
|
-
def body
|
160
|
-
return @body if @body
|
161
233
|
|
234
|
+
def body
|
162
235
|
text_file = default_text
|
163
|
-
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
return @body ||= IO.readlines(text_file.path).join.strip
|
168
|
-
end
|
169
|
-
|
170
|
-
def get_body # :nodoc:
|
171
|
-
sclz.method_deprecated(:get_body, :body)
|
172
|
-
self.body
|
236
|
+
@body = text_file ? IO.readlines(text_file.path).join.strip : ""
|
237
|
+
@body
|
173
238
|
end
|
174
239
|
|
175
240
|
# Returns a File with the most likely candidate for the user-submitted
|
176
|
-
# media.
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
241
|
+
# media. Given that most MMS messages only have one file attached, this
|
242
|
+
# method will try to return that file. Singleton methods are added to
|
243
|
+
# the File object so it can be used in place of a CGI upload (local_path,
|
244
|
+
# original_filename, size, and content_type) such as in conjunction with
|
245
|
+
# AttachementFu. The largest file found in terms of bytes is returned.
|
181
246
|
#
|
182
247
|
# Returns nil if there are not any video or image Files found.
|
183
248
|
|
184
249
|
def default_media
|
185
|
-
return @default_media ||=
|
186
|
-
end
|
187
|
-
|
188
|
-
def get_media # :nodoc:
|
189
|
-
sclz.method_deprecated(:get_media, :default_media)
|
190
|
-
self.default_media
|
250
|
+
return @default_media ||= attachment(['video', 'image', 'text'])
|
191
251
|
end
|
192
252
|
|
193
253
|
# Returns a File with the most likely candidate that is text, or nil
|
194
|
-
# otherwise.
|
195
|
-
#
|
196
|
-
#
|
254
|
+
# otherwise. It also adds singleton methods to the File object so it can be
|
255
|
+
# used in place of a CGI upload (local_path, original_filename, size, and
|
256
|
+
# content_type) such as in conjunction with AttachmentFu. The largest file
|
257
|
+
# found in terms of bytes is returned.
|
197
258
|
#
|
198
259
|
# Returns nil if there are not any text Files found
|
199
260
|
|
200
261
|
def default_text
|
201
|
-
return @default_text ||=
|
202
|
-
end
|
203
|
-
|
204
|
-
def get_text # :nodoc:
|
205
|
-
sclz.method_deprecated(:get_text, :default_text)
|
206
|
-
self.default_text
|
262
|
+
return @default_text ||= attachment(['text'])
|
207
263
|
end
|
208
264
|
|
209
265
|
##
|
210
266
|
# process is a template method and collects all the media in a MMS.
|
211
|
-
# Override helper methods to this template to clean out advertising
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
267
|
+
# Override helper methods to this template to clean out advertising and/or
|
268
|
+
# ignore media that are advertising. This method should not be overridden
|
269
|
+
# unless there is an extreme special case in processing the media of a MMS
|
270
|
+
# (like Sprint)
|
215
271
|
#
|
216
272
|
# Helper methods for the process template:
|
217
273
|
# * ignore_media? -- true if the media contained in a part should be ignored.
|
@@ -220,8 +276,8 @@ module MMS2R
|
|
220
276
|
# * temp_file -- creates a temporary filepath based on information from the part.
|
221
277
|
#
|
222
278
|
# Block support:
|
223
|
-
#
|
224
|
-
# For example, to process and receive
|
279
|
+
# Call process() with a block to automatically iterate through media.
|
280
|
+
# For example, to process and receive only media of video type:
|
225
281
|
# mms.process do |media_type, file|
|
226
282
|
# results << file if media_type =~ /video/
|
227
283
|
# end
|
@@ -230,40 +286,36 @@ module MMS2R
|
|
230
286
|
# mms2r extracts from an mms message.
|
231
287
|
|
232
288
|
def process() # :yields: media_type, file
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
parts
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
289
|
+
unless @was_processed
|
290
|
+
@logger.info("#{self.class} processing") unless @logger.nil?
|
291
|
+
|
292
|
+
parts = mail.multipart? ? mail.parts : [mail]
|
293
|
+
|
294
|
+
# Double check for multipart/related, if it exists replace it with its
|
295
|
+
# children parts. Do this twice as multipart/alternative can have
|
296
|
+
# children and we want to fold everything down
|
297
|
+
for i in 1..2
|
298
|
+
flat = []
|
299
|
+
parts.each do |p|
|
300
|
+
if MULTIPARTS_TO_SPLIT.include?(self.class.part_type?(p))
|
301
|
+
p.parts.each {|mp| flat << mp }
|
302
|
+
else
|
303
|
+
flat << p
|
304
|
+
end
|
305
|
+
end
|
306
|
+
parts = flat.dup
|
307
|
+
end
|
308
|
+
|
309
|
+
# get to work
|
310
|
+
parts.each do |p|
|
311
|
+
t = self.class.part_type?(p)
|
312
|
+
unless ignore_media?(t,p)
|
313
|
+
t,f = process_media(p)
|
314
|
+
add_file(t,f) unless t.nil? || f.nil?
|
315
|
+
end
|
257
316
|
end
|
258
|
-
end
|
259
317
|
|
260
|
-
|
261
|
-
parts.each do |p|
|
262
|
-
t = self.class.part_type?(p)
|
263
|
-
unless ignore_media?(t,p)
|
264
|
-
t,f = process_media(p)
|
265
|
-
add_file(t,f) unless t.nil? || f.nil?
|
266
|
-
end
|
318
|
+
@was_processed = true
|
267
319
|
end
|
268
320
|
|
269
321
|
# when process acts upon a block
|
@@ -276,68 +328,29 @@ module MMS2R
|
|
276
328
|
end
|
277
329
|
|
278
330
|
##
|
279
|
-
# Helper for process template method to determine if
|
280
|
-
#
|
281
|
-
#
|
282
|
-
#
|
283
|
-
# The corresponding *_ignore.yml for a given class contains
|
284
|
-
# either a regular expression for the text types or a file
|
285
|
-
# name for all other types. When writing an ignore regular
|
286
|
-
# expression assume that the text it will be evaluated against
|
287
|
-
# has been flattened where one or more consecutive whitespace
|
288
|
-
# (tab, space, new lines and line feeds) characters are replaced
|
289
|
-
# with one space ' ' character.
|
331
|
+
# Helper for process template method to determine if media contained in a
|
332
|
+
# part should be ignored. Producers should override this method to return
|
333
|
+
# true for media such as images that are advertising, carrier logos, etc.
|
334
|
+
# See the ignore section in the discussion of the built-in configuration.
|
290
335
|
|
291
336
|
def ignore_media?(type,part)
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
h = YAML::load_file(yf) if File::exist?(yf)
|
299
|
-
h ||= Hash.new
|
300
|
-
|
301
|
-
# merge in the ignore hash of the specific child
|
302
|
-
f = clz.yaml_file_name(clz, :ignore)
|
303
|
-
yf = File.join(self.class.conf_dir(), "#{f}")
|
304
|
-
if File::exist?(yf)
|
305
|
-
ignores = YAML::load_file(yf)
|
306
|
-
ignores.each do |k,v|
|
307
|
-
unless h[k]
|
308
|
-
h[k] = v
|
309
|
-
else
|
310
|
-
v.each{|e| h[k] << e}
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
a ||= h[type]
|
315
|
-
return false if h.empty? || a.nil?
|
316
|
-
|
317
|
-
m = /^([^\/]+)\//.match(type)[1]
|
318
|
-
# fire each regular expression, only break if there is a match
|
319
|
-
ignore = a.each do |i|
|
320
|
-
if m == 'text' || type == 'application/smil' || type == 'multipart/mixed'
|
321
|
-
s = part.body.gsub(/\s+/m," ").strip
|
322
|
-
break(i) if i.match(s)
|
323
|
-
end
|
324
|
-
break(i) if filename?(part).eql?(i)
|
325
|
-
end
|
326
|
-
return ignore.eql?(a) ? false : true # when ignore is equal to 'a' that
|
327
|
-
# means none of the breaks fired in
|
328
|
-
# the loop, if a break
|
337
|
+
ignores = config['ignore'][type] || []
|
338
|
+
ignore = ignores.detect{|test| filename?(part) == test}
|
339
|
+
ignore ||= ignores.detect{|test| filename?(part) =~ eval(test) rescue nil}
|
340
|
+
ignore ||= ignores.detect{|test| part.body.strip =~ eval(test) rescue nil}
|
341
|
+
ignore ||= (part.body.strip.size == 0 ? true : nil) rescue nil
|
342
|
+
ignore.nil? ? false : true
|
329
343
|
end
|
330
344
|
|
331
345
|
##
|
332
|
-
# Helper for process template method to decode the part based
|
333
|
-
#
|
334
|
-
#
|
335
|
-
#
|
336
|
-
# transform_text
|
346
|
+
# Helper for process template method to decode the part based on its type
|
347
|
+
# and write its content to a temporary file. Returns path to temporary
|
348
|
+
# file that holds the content. Parts with a main type of text will have
|
349
|
+
# their contents transformed with a call to transform_text
|
337
350
|
#
|
338
|
-
# Producers should only override this method if the parts of
|
339
|
-
#
|
340
|
-
#
|
351
|
+
# Producers should only override this method if the parts of the MMS need
|
352
|
+
# special treatment besides what is expected for a normal mime part (like
|
353
|
+
# Sprint).
|
341
354
|
#
|
342
355
|
# Returns a tuple of content type, file path
|
343
356
|
|
@@ -357,26 +370,17 @@ module MMS2R
|
|
357
370
|
return type, nil if content.nil?
|
358
371
|
|
359
372
|
@logger.info("#{self.class} writing file #{file}") unless @logger.nil?
|
360
|
-
File.open(file,'w'){ |f|
|
361
|
-
f.write(content)
|
362
|
-
}
|
373
|
+
File.open(file,'w'){ |f| f.write(content) }
|
363
374
|
return type, file
|
364
375
|
end
|
365
376
|
|
366
377
|
##
|
367
378
|
# Helper for process_media template method to transform text.
|
368
|
-
#
|
369
|
-
#
|
370
|
-
# Input is the type of text and the text to transform.
|
379
|
+
# See the transform section in the discussion of the built-in
|
380
|
+
# configuration.
|
371
381
|
|
372
382
|
def transform_text(type, text)
|
373
|
-
|
374
|
-
yf = File.join(self.class.conf_dir(), "#{f}")
|
375
|
-
return type, text unless File::exist?(yf)
|
376
|
-
|
377
|
-
h = YAML::load_file(yf)
|
378
|
-
a = h[type]
|
379
|
-
return type, text if a.nil?
|
383
|
+
return type, text unless transforms = config['transform'][type] rescue nil
|
380
384
|
|
381
385
|
#convert to UTF-8
|
382
386
|
begin
|
@@ -386,16 +390,18 @@ module MMS2R
|
|
386
390
|
utf_t = text
|
387
391
|
end
|
388
392
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
+
transforms.each do |transform|
|
394
|
+
next unless transform.size == 2
|
395
|
+
p = transform.first
|
396
|
+
r = transform.last
|
397
|
+
utf_t = utf_t.gsub(eval(p), r) rescue utf_t
|
398
|
+
end
|
399
|
+
|
400
|
+
return type, utf_t
|
393
401
|
end
|
394
402
|
|
395
403
|
##
|
396
404
|
# Helper for process_media template method to transform text.
|
397
|
-
# The regular expressions for the trans are in *_transform.yml
|
398
|
-
# Input is a mail part
|
399
405
|
|
400
406
|
def transform_text_part(part)
|
401
407
|
type = self.class.part_type?(part)
|
@@ -404,14 +410,13 @@ module MMS2R
|
|
404
410
|
end
|
405
411
|
|
406
412
|
##
|
407
|
-
# Helper for process template method to name a temporary
|
408
|
-
#
|
409
|
-
#
|
410
|
-
#
|
411
|
-
# the
|
412
|
-
#
|
413
|
-
#
|
414
|
-
# is mandatory that this behavior is retained.
|
413
|
+
# Helper for process template method to name a temporary filepath based on
|
414
|
+
# information in the part. This version attempts to honor the name of the
|
415
|
+
# media as labeled in the part header and creates a unique temporary
|
416
|
+
# directory for writing the file so filename collision does not occur.
|
417
|
+
# Consumers of this method expect the directory structure to the file
|
418
|
+
# exists, if the method is overridden it is mandatory that this behavior is
|
419
|
+
# retained.
|
415
420
|
|
416
421
|
def temp_file(part)
|
417
422
|
file_name = filename?(part)
|
@@ -431,14 +436,13 @@ module MMS2R
|
|
431
436
|
# Helper to add a file to the media hash.
|
432
437
|
|
433
438
|
def add_file(type, file)
|
434
|
-
|
435
|
-
|
439
|
+
media[type] = [] unless media[type]
|
440
|
+
media[type] << file
|
436
441
|
end
|
437
442
|
|
438
443
|
##
|
439
|
-
# Helper to temp_file to create a unique temporary directory that is
|
440
|
-
#
|
441
|
-
# mail.
|
444
|
+
# Helper to temp_file to create a unique temporary directory that is a
|
445
|
+
# child of tmp_dir This version is based on the message_id of the mail.
|
442
446
|
|
443
447
|
def msg_tmp_dir()
|
444
448
|
@dir_count += 1
|
@@ -457,13 +461,12 @@ module MMS2R
|
|
457
461
|
"#{Time.now.to_f}.#{self.class.default_ext(self.class.part_type?(part))}"
|
458
462
|
end
|
459
463
|
|
460
|
-
@@tmp_dir = File.join(Dir.tmpdir, (ENV['USER'].nil? ? '':ENV['USER']), 'mms2r')
|
461
464
|
|
462
465
|
##
|
463
466
|
# Get the temporary directory where media files are written to.
|
464
467
|
|
465
468
|
def self.tmp_dir
|
466
|
-
@@tmp_dir
|
469
|
+
@@tmp_dir ||= File.join(Dir.tmpdir, (ENV['USER'].nil? ? '':ENV['USER']), 'mms2r')
|
467
470
|
end
|
468
471
|
|
469
472
|
##
|
@@ -472,24 +475,23 @@ module MMS2R
|
|
472
475
|
@@tmp_dir=d
|
473
476
|
end
|
474
477
|
|
475
|
-
@@conf_dir = File.join(File.dirname(__FILE__), '..', '..', 'conf')
|
476
|
-
|
477
478
|
##
|
478
479
|
# Get the directory where conf files are stored.
|
479
480
|
|
480
481
|
def self.conf_dir
|
481
|
-
@@conf_dir
|
482
|
+
@@conf_dir ||= File.join(File.dirname(__FILE__), '..', '..', 'conf')
|
482
483
|
end
|
483
484
|
|
484
485
|
##
|
485
486
|
# Set the directory where conf files are stored.
|
487
|
+
|
486
488
|
def self.conf_dir=(d)
|
487
489
|
@@conf_dir=d
|
488
490
|
end
|
489
491
|
|
490
492
|
##
|
491
|
-
# Helper to create a safe directory path element based on the
|
492
|
-
#
|
493
|
+
# Helper to create a safe directory path element based on the mail message
|
494
|
+
# id.
|
493
495
|
|
494
496
|
def self.safe_message_id(mid)
|
495
497
|
return "#{Time.now.to_i}" if mid.nil?
|
@@ -501,12 +503,12 @@ module MMS2R
|
|
501
503
|
|
502
504
|
def self.default_ext(content_type)
|
503
505
|
ext = MMS2R::EXT[content_type]
|
504
|
-
ext = /
|
506
|
+
ext = content_type.split('/').last if ext.nil? rescue nil
|
505
507
|
ext
|
506
508
|
end
|
507
509
|
|
508
510
|
##
|
509
|
-
# Determines the
|
511
|
+
# Determines the mime-type of a part. Guarantees a type is returned.
|
510
512
|
|
511
513
|
def self.part_type?(part)
|
512
514
|
if part.content_type.nil?
|
@@ -516,80 +518,78 @@ module MMS2R
|
|
516
518
|
end
|
517
519
|
|
518
520
|
##
|
519
|
-
# Determines the main type of the part's
|
521
|
+
# Determines the main type of the part's mime-type
|
520
522
|
|
521
523
|
def self.main_type?(part)
|
522
524
|
/^([^\/]+)\//.match(self.part_type?(part))[1]
|
523
525
|
end
|
524
526
|
|
525
527
|
##
|
526
|
-
# Determines the sub type of the part's
|
528
|
+
# Determines the sub type of the part's mime-type
|
527
529
|
|
528
530
|
def self.sub_type?(part)
|
529
531
|
/\/([^\/]+)$/.match(self.part_type?(part))[1]
|
530
532
|
end
|
531
533
|
|
532
534
|
##
|
533
|
-
#
|
534
|
-
#
|
535
|
-
# for yaml_file_name(MMS2R::TMobileMedia,:ignore)
|
536
|
-
|
537
|
-
def self.yaml_file_name(clz,kind)
|
538
|
-
# like active_support's inflector
|
539
|
-
flat = clz.name.gsub(/::/, '_').
|
540
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
541
|
-
gsub(/([a-z])([A-Z])/,'\1_\2').
|
542
|
-
tr("-", "_").downcase
|
543
|
-
"#{flat}_#{kind.to_s}.yml"
|
544
|
-
end
|
535
|
+
# Joins the generic mms2r configuration with the carrier specific
|
536
|
+
# configuration.
|
545
537
|
|
546
|
-
|
547
|
-
|
538
|
+
def self.initialize_config(c)
|
539
|
+
f = File.join(self.conf_dir(), "mms2r_media.yml")
|
540
|
+
conf = YAML::load_file(f) rescue {}
|
541
|
+
conf['ignore'] = {} unless conf['ignore']
|
542
|
+
conf['transform'] = {} unless conf['transform']
|
543
|
+
return conf unless c
|
548
544
|
|
549
|
-
|
550
|
-
self.class
|
551
|
-
end
|
545
|
+
kinds = ['ignore', 'transform']
|
552
546
|
|
553
|
-
|
554
|
-
|
547
|
+
kinds.each do |kind|
|
548
|
+
if c[kind]
|
549
|
+
c[kind].each do |type,array|
|
550
|
+
conf[kind][type] = [] unless conf[kind][type]
|
551
|
+
conf[kind][type] += array
|
552
|
+
end
|
553
|
+
end
|
554
|
+
end
|
555
555
|
|
556
|
-
|
557
|
-
self.class.superclass
|
556
|
+
conf
|
558
557
|
end
|
559
558
|
|
560
559
|
private
|
561
560
|
|
561
|
+
##
|
562
|
+
# accessor for the config
|
563
|
+
|
564
|
+
def config
|
565
|
+
@config
|
566
|
+
end
|
567
|
+
|
562
568
|
##
|
563
569
|
# used by #default_media and #text to return the biggest attachment type
|
564
|
-
# listed in the types array
|
570
|
+
# listed in the types array
|
565
571
|
|
566
|
-
def
|
572
|
+
def attachment(types)
|
567
573
|
|
568
574
|
# get all the files that are of the major types passed in
|
569
|
-
files =
|
570
|
-
types.each do |
|
571
|
-
media.keys.
|
572
|
-
|
573
|
-
end
|
575
|
+
files = []
|
576
|
+
types.each do |type|
|
577
|
+
key = media.keys.detect{|k| k.split('/').first == type}
|
578
|
+
files += media[key] if key
|
574
579
|
end
|
575
580
|
return nil if files.empty?
|
576
581
|
|
577
|
-
#
|
582
|
+
# set temp holders
|
578
583
|
file = nil # explicitly declare the file and size
|
579
584
|
size = 0
|
580
585
|
mime_type = nil
|
581
586
|
|
587
|
+
#get the largest file
|
582
588
|
files.each do |f|
|
583
|
-
# this will safely evaluate since we wouldn't be looking at
|
584
|
-
# media[mime_type] after the check just before this
|
585
589
|
if File.size(f) > size
|
586
590
|
size = File.size(f)
|
587
591
|
file = File.new(f)
|
588
|
-
|
589
|
-
# detect on the hash returns an array, the 0th element is
|
590
|
-
# the mime type of the file that was found in the files array
|
591
|
-
# i.e. {'text/foo' => ['/foo/bar.txt', '/hello/world.txt']}
|
592
|
-
mime_type = media.detect{|k,v| v.detect{|fl| fl == f}}[0] rescue nil
|
592
|
+
mime_type = media.detect{|type,files| files.detect{|fl| fl == f}}[0] rescue nil
|
593
593
|
end
|
594
594
|
end
|
595
595
|
|
@@ -620,18 +620,6 @@ module MMS2R
|
|
620
620
|
file
|
621
621
|
end
|
622
622
|
|
623
|
-
def get_attachement(types) # :nodoc:
|
624
|
-
sclz.method_deprecated(:get_attachment, :attachment)
|
625
|
-
self.attachement(types)
|
626
|
-
end
|
627
|
-
|
628
|
-
def self.method_deprecated(from, to) # :nodoc:
|
629
|
-
msg = "Method '#{from}' has been deprecated use method '#{to}'." +
|
630
|
-
"\nMethod '#{from}' will be removed in a future release"
|
631
|
-
@logger.error(msg) if @logger
|
632
|
-
$stderr.puts msg
|
633
|
-
end
|
634
|
-
|
635
623
|
end
|
636
624
|
|
637
625
|
end
|