Class: MList::Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MList::Message
- Includes:
- Util::EmailHelpers
- Defined in:
- lib/mlist/message.rb
Direct Known Subclasses
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 Attribute Summary collapse
-
#recipients ⇒ Object
A temporary storage of recipient subscribers, obtained from MList::Lists.
Instance Method Summary collapse
-
#delivery ⇒ Object
Answers an MList::TMailBuilder for assembling the TMail::Mail object that will be fit for delivery.
- #email_with_capture=(email) ⇒ Object
-
#html ⇒ Object
Answers the html content of the message.
-
#html_for_reply ⇒ Object
Answers text suitable for creating a reply message, converted to the same simple html of text_html.
- #parent_with_identifier_capture=(parent) ⇒ Object
-
#recipient_addresses ⇒ Object
Answers the recipient email addresses from the MList::List recipient subscribers, except those that are in the email TO or CC fields as placed there by the sending MUA.
-
#subject_for_reply ⇒ Object
Answers the subject with ‘Re:’ prefixed.
-
#subscriber ⇒ Object
Answers the subscriber from which this message comes.
-
#subscriber=(subscriber) ⇒ Object
Assigns the subscriber from which this message comes.
-
#text ⇒ Object
Answers the text content of the message.
-
#text_for_reply ⇒ Object
Answers text suitable for creating a reply message.
-
#text_html ⇒ Object
Answers the text content of the message as HTML.
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
Instance Attribute Details
#recipients ⇒ Object
A temporary storage of recipient subscribers, obtained from MList::Lists. This list is not available when a message is reloaded.
18 19 20 |
# File 'lib/mlist/message.rb', line 18 def recipients @recipients end |
Instance Method Details
#delivery ⇒ Object
Answers an MList::TMailBuilder for assembling the TMail::Mail object that will be fit for delivery. If this is not a new message, the delivery will be updated to reflect the message-id, x-mailer, etc. of this message.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mlist/message.rb', line 25 def delivery @delivery ||= begin d = MList::Util::TMailBuilder.new(TMail::Mail.parse(email.source)) unless new_record? d. = self.identifier d.mailer = self.mailer d.date = self.created_at end d end end |
#email_with_capture=(email) ⇒ Object
37 38 39 40 41 |
# File 'lib/mlist/message.rb', line 37 def email_with_capture=(email) self.subject = email.subject self.mailer = email.mailer self.email_without_capture = email end |
#html ⇒ Object
Answers the html content of the message.
46 47 48 |
# File 'lib/mlist/message.rb', line 46 def html email.html end |
#html_for_reply ⇒ Object
Answers text suitable for creating a reply message, converted to the same simple html of text_html.
74 75 76 |
# File 'lib/mlist/message.rb', line 74 def html_for_reply text_to_html(text_for_reply) end |
#parent_with_identifier_capture=(parent) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/mlist/message.rb', line 78 def parent_with_identifier_capture=(parent) if parent self.parent_without_identifier_capture = parent self.parent_identifier = parent.identifier else self.parent_without_identifier_capture = nil self.parent_identifier = nil end end |
#recipient_addresses ⇒ Object
Answers the recipient email addresses from the MList::List recipient subscribers, except those that are in the email TO or CC fields as placed there by the sending MUA. It is assumed that those addresses have received a copy of the email already, and that by including them here, we would cause them to receive two copies of the message.
95 96 97 |
# File 'lib/mlist/message.rb', line 95 def recipient_addresses @recipients.collect(&:rfc5322_email).collect(&:downcase) - email.recipient_addresses end |
#subject_for_reply ⇒ Object
Answers the subject with ‘Re:’ prefixed. Note that it is the responsibility of the MList::MailList to perform any processing of the persisted subject (ie, cleaning up labels, etc).
.subject = '[List Label] Re: The new Chrome Browser from Google'
.subject_for_reply => 'Re: [List Label] The new Chrome Browser from Google'
.subject = 'Re: [List Label] Re: The new Chrome Browser from Google'
.subject_for_reply => 'Re: [List Label] The new Chrome Browser from Google'
109 110 111 |
# File 'lib/mlist/message.rb', line 109 def subject_for_reply subject =~ REGARD_RE ? subject : "Re: #{subject}" end |
#subscriber ⇒ Object
Answers the subscriber from which this message comes.
115 116 117 118 119 120 121 122 123 |
# File 'lib/mlist/message.rb', line 115 def subscriber @subscriber ||= begin if subscriber_type? && subscriber_id? subscriber_type.constantize.find(subscriber_id) elsif subscriber_address? MList::EmailSubscriber.new(subscriber_address) end end end |
#subscriber=(subscriber) ⇒ Object
Assigns the subscriber from which this message comes.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/mlist/message.rb', line 127 def subscriber=(subscriber) case subscriber when ActiveRecord::Base @subscriber = subscriber self.subscriber_address = subscriber.rfc5322_email self.subscriber_type = subscriber.class.base_class.name self.subscriber_id = subscriber.id when MList::EmailSubscriber @subscriber = subscriber self.subscriber_address = subscriber.rfc5322_email self.subscriber_type = self.subscriber_id = nil when String self.subscriber = MList::EmailSubscriber.new(subscriber) else @subscriber = self.subscriber_address = self.subscriber_type = self.subscriber_id = nil end end |
#text ⇒ Object
Answers the text content of the message.
52 53 54 |
# File 'lib/mlist/message.rb', line 52 def text email.text end |
#text_for_reply ⇒ Object
Answers text suitable for creating a reply message.
66 67 68 69 |
# File 'lib/mlist/message.rb', line 66 def text_for_reply = email.date.to_s(:mlist_reply_timestamp) "On #{}, #{email.from} wrote:\n#{text_to_quoted(text)}" end |
#text_html ⇒ Object
Answers the text content of the message as HTML. The structure of this output is very simple. For examples of what it can handle, please check out the spec documents for MList::Util::EmailHelpers.
60 61 62 |
# File 'lib/mlist/message.rb', line 60 def text_html text_to_html(text) end |