Class: MList::Email
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MList::Email
- Includes:
- Util::EmailHelpers, Util::TMailReaders
- Defined in:
- lib/mlist/email.rb
Constant Summary
Constants included from Util::EmailHelpers
Util::EmailHelpers::AUTO_LINK_RE, Util::EmailHelpers::BRACKETS, Util::EmailHelpers::BRACKETS_RE, Util::EmailHelpers::HTML_ESCAPE, Util::EmailHelpers::REGARD_RE
Instance Method Summary collapse
-
#been_there_addresses ⇒ Object
Answers the values of all the X-BeenThere headers.
-
#bounce? ⇒ Boolean
Answers true if this email is a bounce.
- #date ⇒ Object
- #from ⇒ Object
-
#list_addresses ⇒ Object
Answers the usable destination addresses of the email.
-
#method_missing(symbol, *args, &block) ⇒ Object
Provide reader delegation to most of the underlying TMail::Mail methods, excluding those overridden by this Class and the [] method (an ActiveRecord method).
-
#recipient_addresses ⇒ Object
Answers the set of addresses found in the TO and CC fields of the email.
- #respond_to?(method) ⇒ Boolean
- #tmail ⇒ Object
- #tmail=(tmail) ⇒ Object
Methods included from Util::TMailReaders
#from_address, #html, #identifier, #mailer, #text, #text_html_part, #text_plain_part
Methods included from Util::EmailHelpers
#auto_link_urls, #bracket, #escape_once, #header_sanitizer, #html_to_text, #normalize_new_lines, #remove_brackets, #remove_regard, #sanitize_header, #subscriber_name_and_address, #text_to_html, #text_to_quoted
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
Provide reader delegation to most of the underlying TMail::Mail methods, excluding those overridden by this Class and the [] method (an ActiveRecord method).
53 54 55 56 57 58 59 |
# File 'lib/mlist/email.rb', line 53 def method_missing(symbol, *args, &block) # :nodoc: if symbol.to_s !~ /=\Z/ && symbol != :[] && symbol != :source && tmail.respond_to?(symbol) tmail.__send__(symbol, *args, &block) else super end end |
Instance Method Details
#been_there_addresses ⇒ Object
Answers the values of all the X-BeenThere headers.
23 24 25 |
# File 'lib/mlist/email.rb', line 23 def been_there_addresses Array(tmail['x-beenthere']).collect { |e| e.body.strip.downcase }.uniq end |
#bounce? ⇒ Boolean
Answers true if this email is a bounce.
TODO Delegate to the email_server’s bounce detector.
37 38 39 |
# File 'lib/mlist/email.rb', line 37 def bounce? tmail.header_string('to') =~ /\Amlist-/ end |
#date ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/mlist/email.rb', line 9 def date if date_from_email = super return date_from_email else self.created_at ||= Time.now end end |
#from ⇒ Object
17 18 19 |
# File 'lib/mlist/email.rb', line 17 def from tmail.header_string('from') end |
#list_addresses ⇒ Object
Answers the usable destination addresses of the email.
29 30 31 |
# File 'lib/mlist/email.rb', line 29 def list_addresses bounce? ? tmail.header_string('to').sub(/\Amlist-/, '') : recipient_addresses end |
#recipient_addresses ⇒ Object
Answers the set of addresses found in the TO and CC fields of the email.
63 64 65 |
# File 'lib/mlist/email.rb', line 63 def recipient_addresses (Array(tmail.to) + Array(tmail.cc)).collect(&:downcase).uniq end |
#respond_to?(method) ⇒ Boolean
67 68 69 |
# File 'lib/mlist/email.rb', line 67 def respond_to?(method) super || (method.to_s !~ /=\Z/ && tmail.respond_to?(method)) end |
#tmail ⇒ Object
46 47 48 |
# File 'lib/mlist/email.rb', line 46 def tmail @tmail ||= TMail::Mail.parse(source) end |
#tmail=(tmail) ⇒ Object
41 42 43 44 |
# File 'lib/mlist/email.rb', line 41 def tmail=(tmail) @tmail = tmail write_attribute(:source, tmail.port.read_all) end |