lib/mms2r/media.rb
def device_type?

      file = attachment(['image'])
      if file
        original = file.original_filename
        @exif = case original
                when /\.je?pg$/i
                  EXIFR::JPEG.new(file)
                when /\.tiff?$/i
                  EXIFR::TIFF.new(file)
                end
        if @exif
          models = config['device_types']['models'] rescue {}
          models.each do |type, regex|
            return type if @exif.model =~ regex
          end
          makes = config['device_types']['makes'] rescue {}
          makes.each do |type, regex|
            return type if @exif.make =~ regex
          end
          software = config['device_types']['software'] rescue {}
          software.each do |type, regex|
            return type if @exif.software =~ regex
          end
        end
      end

      headers = config['device_types']['headers'] rescue {}
      headers.keys.each do |header|
        if mail.header[header]
          # headers[header] refers to a hash of smart phone types with regex values
          # that if they match, the header signals the type should be returned
          headers[header].each do |type, regex|
            return type if mail.header[header].decoded =~ regex
            field = mail.header.fields.detect { |field| field.name == header }
            return type if field && field.to_s =~ regex
          end
        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

      file = attachment(['video'])
      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

      boundary = mail.boundary
      boundaries = config['device_types']['boundary'] rescue {}
      boundaries.each do |type, regex|
        return type if boundary =~ regex
      end

      return :handset if File.exist?( File.expand_path(
                             File.join(self.conf_dir, "#{self.aliases[self.carrier] || self.carrier}.yml")
                         ) )

      :unknown
    end
def device_type?

      file = attachment(['image'])
      if file
        original = file.original_filename
        @exif = case original
                when /\.je?pg$/i
                  EXIFR::JPEG.new(file)
                when /\.tiff?$/i
                  EXIFR::TIFF.new(file)
                end
        if @exif
          models = config['device_types']['models'] rescue {}
          models.each do |type, regex|
            return type if @exif.model =~ regex
          end
          makes = config['device_types']['makes'] rescue {}
          makes.each do |type, regex|
            return type if @exif.make =~ regex
          end
          software = config['device_types']['software'] rescue {}
          software.each do |type, regex|
            return type if @exif.software =~ regex
          end
        end
      end

      headers = config['device_types']['headers'] rescue {}
      headers.keys.each do |header|
        if mail.header[header]
          # headers[header] refers to a hash of smart phone types with regex values
          # that if they match, the header signals the type should be returned
          headers[header].each do |type, regex|
            return type if mail.header[header].decoded =~ regex
            field = mail.header.fields.detect { |field| field.name == header }
            return type if field && field.to_s =~ regex
          end
        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

      file = attachment(['video'])
      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

      boundary = mail.boundary
      boundaries = config['device_types']['boundary'] rescue {}
      boundaries.each do |type, regex|
        return type if boundary =~ regex
      end

      return :handset if File.exist?( File.expand_path(
                             File.join(self.conf_dir, "#{self.aliases[self.carrier] || self.carrier}.yml")
                         ) )

      :unknown
    end
def device_type? file = attachment ( [ 'image' ] ) if file original = file . original_filename @exif = case original when / \. /i EXIFR :: JPEG . new ( file ) when / \. /i EXIFR :: TIFF . new ( file ) end if @exif models = config [ 'device_types' ] [ 'models' ] rescue { } models . each do | type , regex | return type if @exif . model =~ regex end makes = config [ 'device_types' ] [ 'makes' ] rescue { } makes . each do | type , regex | return type if @exif . make =~ regex end software = config [ 'device_types' ] [ 'software' ] rescue { } software . each do | type , regex | return type if @exif . software =~ regex end end end headers = config [ 'device_types' ] [ 'headers' ] rescue { } headers . keys . each do | header | if mail . header [ header ] # headers[header] refers to a hash of smart phone types with regex values # that if they match, the header signals the type should be returned headers [ header ] . each do | type , regex | return type if mail . header [ header ] . decoded =~ regex field = mail . header . fields . detect { | field | field . name == header } return type if field && field . to_s =~ regex end 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 file = attachment ( [ 'video' ] ) 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 boundary = mail . boundary boundaries = config [ 'device_types' ] [ 'boundary' ] rescue { } boundaries . each do | type , regex | return type if boundary =~ regex end return :handset if File . exist? ( File . expand_path ( File . join ( self . conf_dir , "#{self.aliases[self.carrier] || self.carrier}.yml" ) ) ) :unknown end
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
 * :nokia
 * :palm
 * :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
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