Class: Message

Inherits:
Object
  • Object
show all
Includes:
ActionMailer::Quoting
Defined in:
lib/imap-feeder/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Message

Returns a new instance of Message.



15
16
17
# File 'lib/imap-feeder/message.rb', line 15

def initialize(params)
  @params = params
end

Instance Method Details

#as_htmlObject



60
61
62
# File 'lib/imap-feeder/message.rb', line 60

def as_html
  construct_message "html", "#{html_body}" + (url ? "<br/><br/><a href='#{url}'>#{url}</a>" : "")
end

#bodyObject



31
32
33
# File 'lib/imap-feeder/message.rb', line 31

def body
  @body ||= strip_html(@params[:body] || @params[:url] || "")
end

#formatObject



56
57
58
# File 'lib/imap-feeder/message.rb', line 56

def format
  construct_message "plain", "#{body}" + (url ? "\n\n#{url}" : "")
end

#fromObject



23
24
25
26
27
28
29
# File 'lib/imap-feeder/message.rb', line 23

def from
  from = dec(@params[:from]) || "Unknown <[email protected]>"
  unless from =~ /@/
    from << " <[email protected]>"
  end
  @from ||= from
end

#generate_identifierObject



52
53
54
# File 'lib/imap-feeder/message.rb', line 52

def generate_identifier
  @cached_identifier ||= "#{title}##{Digest::MD5.hexdigest(body())}"
end

#html_bodyObject



35
36
37
# File 'lib/imap-feeder/message.rb', line 35

def html_body
  dec(@params[:body])
end

#quote(str) ⇒ Object



47
48
49
50
# File 'lib/imap-feeder/message.rb', line 47

def quote(str)
  return "" if not str
  str.gsub(/[^a-zA-Z0-9 -_:,\.]+/) {|to_quote| quote_if_necessary(to_quote, "UTF-8")}
end

#timeObject



39
40
41
# File 'lib/imap-feeder/message.rb', line 39

def time
  @time ||= (@params[:time] || Time.now.localtime).rfc2822
end

#titleObject



19
20
21
# File 'lib/imap-feeder/message.rb', line 19

def title
  @title ||= (dec( (@params[:title] || "").gsub(/(\r\n)|\r|\n/, " ")) || "")
end

#urlObject



43
44
45
# File 'lib/imap-feeder/message.rb', line 43

def url
  @url ||= @params[:url]
end