Class: Message
- Inherits:
-
Object
- Object
- Message
- Includes:
- ActionMailer::Quoting
- Defined in:
- lib/imap-feeder/message.rb
Instance Method Summary collapse
- #as_html ⇒ Object
- #body ⇒ Object
- #format ⇒ Object
- #from ⇒ Object
- #generate_identifier ⇒ Object
- #html_body ⇒ Object
-
#initialize(params) ⇒ Message
constructor
A new instance of Message.
- #quote(str) ⇒ Object
- #time ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
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_html ⇒ Object
60 61 62 |
# File 'lib/imap-feeder/message.rb', line 60 def as_html "html", "#{html_body}" + (url ? "<br/><br/><a href='#{url}'>#{url}</a>" : "") end |
#body ⇒ Object
31 32 33 |
# File 'lib/imap-feeder/message.rb', line 31 def body @body ||= strip_html(@params[:body] || @params[:url] || "") end |
#format ⇒ Object
56 57 58 |
# File 'lib/imap-feeder/message.rb', line 56 def format "plain", "#{body}" + (url ? "\n\n#{url}" : "") end |
#from ⇒ Object
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_identifier ⇒ Object
52 53 54 |
# File 'lib/imap-feeder/message.rb', line 52 def generate_identifier @cached_identifier ||= "#{title}##{Digest::MD5.hexdigest(body())}" end |
#html_body ⇒ Object
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 |
#time ⇒ Object
39 40 41 |
# File 'lib/imap-feeder/message.rb', line 39 def time @time ||= (@params[:time] || Time.now.localtime).rfc2822 end |
#title ⇒ Object
19 20 21 |
# File 'lib/imap-feeder/message.rb', line 19 def title @title ||= (dec( (@params[:title] || "").gsub(/(\r\n)|\r|\n/, " ")) || "") end |
#url ⇒ Object
43 44 45 |
# File 'lib/imap-feeder/message.rb', line 43 def url @url ||= @params[:url] end |