From f72ed908f5965f3eb130faf54ae9d178c0776905 Mon Sep 17 00:00:00 2001 From: Mike Mondragon Date: Mon, 31 Oct 2011 16:44:06 -0700 Subject: [PATCH] Mark images name photo.PNG as coming from iphones. Mark images coming from Hipstamatic as coming from apple products. --- conf/mms2r_media.yml | 17 +++++----- lib/mms2r/media.rb | 41 ++++++++++++++++++------- test/fixtures/sprint-blackberry-01.mail | 4 +-- test/test_mms2r_media.rb | 16 +++++++++- 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/conf/mms2r_media.yml b/conf/mms2r_media.yml index 9be7a75..78bf269 100644 --- a/conf/mms2r_media.yml +++ b/conf/mms2r_media.yml @@ -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 @@ -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$/ diff --git a/lib/mms2r/media.rb b/lib/mms2r/media.rb index 625d649..2ab70d1 100644 --- a/lib/mms2r/media.rb +++ b/lib/mms2r/media.rb @@ -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 @@ -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 @@ -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") ) ) diff --git a/test/fixtures/sprint-blackberry-01.mail b/test/fixtures/sprint-blackberry-01.mail index f0fdad6..0255b13 100644 --- a/test/fixtures/sprint-blackberry-01.mail +++ b/test/fixtures/sprint-blackberry-01.mail @@ -2,7 +2,7 @@ Return-Path: 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; @@ -21,7 +21,7 @@ Content-Type: multipart/mixed; boundary="_99db4215-8df5-4407-9408-286fd34bd3a9_" MIME-Version: 1.0 From: "tommy tutone " -To: "Cellphotobot " +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] diff --git a/test/test_mms2r_media.rb b/test/test_mms2r_media.rb index 5527789..af7d767 100644 --- a/test/test_mms2r_media.rb +++ b/test/test_mms2r_media.rb @@ -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)