Class: Keystone::Mail::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/keystone/mail__old/content_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(st) ⇒ ContentType

Returns a new instance of ContentType.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/keystone/mail__old/content_type.rb', line 13

def initialize(st)
  if /text\/plain/i =~ st
    @content_type = :text_plain
    if /charset="?iso-2022-jp"?/i =~ st
      @charset = :iso_2022_jp
    elsif /charset="?utf-8"?/i =~ st
      @charset = :utf_8
    end
  elsif /multipart\/mixed/i =~ st
    @content_type = :multipart_mixed
    @boundary = get_boundary(st)
  elsif /multipart\/related/i =~ st
    @content_type = :multipart_related
    @boundary = get_boundary(st)
  elsif /multipart\/alternative/i =~ st
    @content_type = :multipart_alternative
    @boundary = get_boundary(st)
  elsif /text\/html/i =~ st
    @content_type = :text_html
    if /charset="?iso-2022-jp"?/i =~ st
      @charset = :iso_2022_jp
    elsif /charset="?utf-8"?/i =~ st
      @charset = :utf_8
    end
  else
    if /image\/(?:jpeg|jpg)/i =~ st
        @content_type = :image_jpeg
    elsif /image\/png/i =~ st
      @content_type = :image_png
    elsif /image\/gif/i =~ st
      @content_type = :image_gif
    else
      throw "this image does not support[#{st}]"
    end
  end
end

Instance Attribute Details

#boundaryObject

Returns the value of attribute boundary.



12
13
14
# File 'lib/keystone/mail__old/content_type.rb', line 12

def boundary
  @boundary
end

#charsetObject

Returns the value of attribute charset.



12
13
14
# File 'lib/keystone/mail__old/content_type.rb', line 12

def charset
  @charset
end

#content_typeObject

Returns the value of attribute content_type.



12
13
14
# File 'lib/keystone/mail__old/content_type.rb', line 12

def content_type
  @content_type
end

Instance Method Details

#get_boundary(st) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/keystone/mail__old/content_type.rb', line 50

def get_boundary(st)
  # TODO  modify regular expression 
    if /boundary="(.*)"/i =~ st
      return $1
    elsif /boundary=(.*)/i =~ st
      return $1
    end
    return nil
end