Class: MIMEBuilder::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/mime_builder/text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, opts = {}) ⇒ Text

Returns a new instance of Text.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mime_builder/text.rb', line 8

def initialize(text, opts = {})
  @text = text

  if opts.key?(:content_type) && opts[:content_type].to_s.length>0
    content_type = opts[:content_type]
    if content_type =~ /^text\/([^\/]+)$/i
      @mime = MIME::Text.new(text, $1.downcase)
    else
      raise "Unknown Content Type: " + opts[:content_type].to_s
    end
  else
    @mime = MIME::Text.new(text, 'plain')
  end

  @mime.headers.delete('Content-Id') \
    if opts.key?(:content_id_disable) && opts[:content_id_disable]

  set_attachment_content_disposition(opts[:filename], opts[:is_attachment])
end

Instance Attribute Details

#mimeObject

Returns the value of attribute mime.



5
6
7
# File 'lib/mime_builder/text.rb', line 5

def mime
  @mime
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/mime_builder/text.rb', line 6

def text
  @text
end

Instance Method Details

#get_attachment_content_disposition(filename = nil) ⇒ Object



35
36
37
38
39
40
# File 'lib/mime_builder/text.rb', line 35

def get_attachment_content_disposition(filename = nil)
  if filename.to_s.length > 0
    return "attachment; filename=\"#{filename}\""
  end
  'attachment'
end

#set_attachment_content_disposition(filename, is_attachment) ⇒ Object



28
29
30
31
32
33
# File 'lib/mime_builder/text.rb', line 28

def set_attachment_content_disposition(filename, is_attachment)
  @mime.headers.set(
    'Content-Disposition',
    get_attachment_content_disposition(filename)
  ) if is_attachment
end