Sha256: 24647d67288a719fe45e5b375c5142d68da143d10526f73edd7f625e9bab254d

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

# =メールアドレスモジュール
#
module Jpmobile
  # email関連の処理
  class Email
    class << self
      # メールアドレスよりキャリア情報を取得する
      # _param1_:: email メールアドレス
      # return  :: Jpmobile::Mobileで定義されている携帯キャリアクラス
      def detect(email)
        Mobile.carriers.each do |const|
          c = Mobile.const_get(const)
          return c if c::MAIL_ADDRESS_REGEXP && email.match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
        end
        nil
      end

      # 含まれているメールアドレスからキャリア情報を取得する
      def detect_from_mail_header(header)
        Mobile.carriers.each do |const|
          c = Mobile.const_get(const)
          if c::MAIL_ADDRESS_REGEXP &&
             header.match(/(\S+@[A-Za-z0-9\-._]+)/) &&
             Regexp.last_match(1).match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
            return c
          end
        end

        if japanese_mail?(header)
          return Jpmobile::Mobile::AbstractMobile
        end

        nil
      end

      attr_writer :japanese_mail_address_regexp, :converting_content_type

      def japanese_mail?(header)
        @japanese_mail_address_regexp and header.match(@japanese_mail_address_regexp)
      end

      def converting_content_type
        @converting_content_type ||= ['text/plain', 'text/html']
      end

      def convertable?(content_type)
        if converting_content_type.respond_to?(:each)
          converting_content_type.each do |c|
            return true if content_type.match?(c)
          end
        end

        nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jpmobile-7.0.1 lib/jpmobile/email.rb
jpmobile-7.0.0 lib/jpmobile/email.rb
jpmobile-6.1.2 lib/jpmobile/email.rb
jpmobile-6.1.1 lib/jpmobile/email.rb