Class: Jpmobile::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/jpmobile/email.rb

Overview

email関連の処理

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.converting_content_typeObject



42
43
44
# File 'lib/jpmobile/email.rb', line 42

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

.japanese_mail_address_regexp=(value) ⇒ Object (writeonly)

Sets the attribute japanese_mail_address_regexp

Parameters:

  • value

    the value to set the attribute japanese_mail_address_regexp to.



36
37
38
# File 'lib/jpmobile/email.rb', line 36

def japanese_mail_address_regexp=(value)
  @japanese_mail_address_regexp = value
end

Class Method Details

.convertable?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
# File 'lib/jpmobile/email.rb', line 46

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

  false
end

.detect(email) ⇒ Object

メールアドレスよりキャリア情報を取得する

param1

email メールアドレス

return

Jpmobile::Mobileで定義されている携帯キャリアクラス



10
11
12
13
14
15
16
# File 'lib/jpmobile/email.rb', line 10

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}$/) # rubocop:disable Performance/ConstantRegexp
  end
  nil
end

.detect_from_mail_header(header) ⇒ Object

含まれているメールアドレスからキャリア情報を取得する



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jpmobile/email.rb', line 19

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}$/) # rubocop:disable Performance/ConstantRegexp
      return c
    end
  end

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

  nil
end

.japanese_mail?(header) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/jpmobile/email.rb', line 38

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