Skip to content

Commit

Permalink
Mark images name photo.PNG as coming from iphones. Mark images coming…
Browse files Browse the repository at this point in the history
… from Hipstamatic as coming from apple products.
  • Loading branch information
monde committed Oct 31, 2011
1 parent 88a1050 commit f72ed90
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
17 changes: 10 additions & 7 deletions conf/mms2r_media.yml
Expand Up @@ -40,14 +40,8 @@ device_types:
# NOTE: These model strings are stored in the exif model header of an image file
# created and sent by the device, the regex is used by mms2r to detect the
# model string
models:
:blackberry: !ruby/regexp /BlackBerry/i
:dash: !ruby/regexp /T-Mobile Dash/i
:droid: !ruby/regexp /Droid/i
:htc: !ruby/regexp /HTC|Eris|HERO200/i
:iphone: !ruby/regexp /iPhone/i
makes:
:apple: !ruby/regexp /^Apple$/i
:apple: !ruby/regexp /^(Apple|Hipstamatic)$/i
:casio: !ruby/regexp /^CASIO$/i
:dash: !ruby/regexp /T-Mobile Dash/i
:google: !ruby/regexp /^google$/i
Expand All @@ -61,5 +55,14 @@ device_types:
:seoul_electronics: !ruby/regexp /^ISUS0/i
:sprint: !ruby/regexp /^Sprint$/i
:utstarcom: !ruby/regexp /^T1A_UC1.88$/i
models:
:blackberry: !ruby/regexp /BlackBerry/i
:dash: !ruby/regexp /T-Mobile Dash/i
:droid: !ruby/regexp /Droid/i
:htc: !ruby/regexp /HTC|Eris|HERO200/i
:iphone: !ruby/regexp /iPhone|201/i
software:
:blackberry: !ruby/regexp /^Rim Exif/i
filenames:
:iphone: !ruby/regexp /^photo.JPG$/
:iphone: !ruby/regexp /^photo.PNG$/
41 changes: 30 additions & 11 deletions lib/mms2r/media.rb
Expand Up @@ -537,10 +537,20 @@ def aliases
end

##
# Best guess of the mobile device type. Simple heuristics thus far by
# inspecting mail headers and jpeg/tiff exif metadata.
# Smart phone types are
# :iphone :blackberry :dash :droid
# Best guess of the mobile device type. Simple heuristics thus far by
# inspecting mail headers and jpeg/tiff exif metadata, and file name.
# Known smart phone types thus far are
#
# * :blackberry
# * :dash
# * :droid
# * :htc
# * :iphone
# * :lge
# * :motorola
# * :pantech
# * :samsung
#
# If the message is from a carrier known to MMS2R, and not a smart phone
# its type is returned as :handset
# Otherwise device type is :unknown
Expand All @@ -558,16 +568,16 @@ def device_type?
end
if @exif
models = config['device_types']['models'] rescue {}
models.each do |model, regex|
return model if @exif.model =~ regex
models.each do |type, regex|
return type if @exif.model =~ regex
end
makes = config['device_types']['makes'] rescue {}
makes.each do |make, regex|
return make if @exif.make =~ regex
makes.each do |type, regex|
return type if @exif.make =~ regex
end
softwares = config['device_types']['software'] rescue {}
softwares.each do |software, regex|
return software if @exif.software =~ regex
software = config['device_types']['software'] rescue {}
software.each do |type, regex|
return type if @exif.software =~ regex
end
end
end
Expand All @@ -583,6 +593,15 @@ def device_type?
end
end

file = attachment(['image'])
if file
original_filename = file.original_filename
filenames = config['device_types']['filenames'] rescue {}
filenames.each do |type, regex|
return type if original_filename =~ regex
end
end

return :handset if File.exist?( File.expand_path(
File.join(self.conf_dir, "#{self.aliases[self.carrier] || self.carrier}.yml")
) )
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/sprint-blackberry-01.mail
Expand Up @@ -2,7 +2,7 @@ Return-Path: <tommy.tutone@example.com>
Delivered-To: unknown
Received: from imap.gmail.com (209.85.225.109) by ntk with IMAP4-SSL; 30 Oct
2011 06:10:03 -0000
Delivered-To: cellphotobot@gmail.com
Delivered-To: foo@example.com
Received: by 10.216.10.213 with SMTP id 63cs4880wev;
Sat, 29 Oct 2011 23:07:11 -0700 (PDT)
Received: by 10.224.189.7 with SMTP id dc7mr8092483qab.90.1319954829144;
Expand All @@ -21,7 +21,7 @@ Content-Type: multipart/mixed;
boundary="_99db4215-8df5-4407-9408-286fd34bd3a9_"
MIME-Version: 1.0
From: "tommy tutone " <tommy.tutone@example.com>
To: "Cellphotobot " <cellphotobot@gmail.com>
To: foo@example.com
Date: Sun, 30 Oct 2011 06:07:08 +0000
Subject: Washington-20111030-00056.jpg
X-OriginalArrivalTime: 30 Oct 2011 06:07:08.0134 (UTC) FILETIME=[27BFC060:01CC96CA]
Expand Down
16 changes: 15 additions & 1 deletion test/test_mms2r_media.rb
Expand Up @@ -769,12 +769,26 @@ def test_iphone_device_type_by_exif
end

def test_faux_tiff_iphone_device_type_by_exif
mail = smart_phone_mock('Apple', 'iPhone', nil, jpeg = false)
mail = smart_phone_mock('Apple', 'iPhone', nil, nil, jpeg = false)
mms = MMS2R::Media.new(mail)
assert_equal :iphone, mms.device_type?
assert_equal true, mms.is_mobile?
end

def test_iphone_device_type_by_filename_jpg
mail = smart_phone_mock('Hipstamatic', '201')
mms = MMS2R::Media.new(mail)
assert_equal :apple, mms.device_type?
assert_equal true, mms.is_mobile?
end

def test_iphone_device_type_by_filename_png
mail = mail('iphone-image-02.mail')
mms = MMS2R::Media.new(mail)
assert_equal true, mms.is_mobile?
assert_equal :iphone, mms.device_type?
end

def test_blackberry_device_type_by_exif_make_model
mail = smart_phone_mock('Research In Motion', 'BlackBerry')
mms = MMS2R::Media.new(mail)
Expand Down

0 comments on commit f72ed90

Please sign in to comment.