Class: Cms::EmailMessage
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::EmailMessage
- Extended by:
- DefaultAccessible, DomainSupport
- Defined in:
- app/models/cms/email_message.rb
Class Method Summary collapse
-
.absolute_cms_url(path) ⇒ String
Converts a relative path to a path in the CMS.
- .deliver! ⇒ Object
-
.mailbot_address ⇒ Object
Returns a default address that mail will be sent from.
-
.normalize_domain(domain) ⇒ Object
Returns a clean (non-www prefixed) domain name.
Instance Method Summary collapse
- #deliver! ⇒ Object
-
#deliver_now ⇒ Object
TODO: Take this out when we have an email queue processor.
- #delivered? ⇒ Boolean
Methods included from DefaultAccessible
non_permitted_params, permitted_params
Class Method Details
.absolute_cms_url(path) ⇒ String
Converts a relative path to a path in the CMS. Used for creating a links to internal pages in the body of emails.
33 34 35 36 |
# File 'app/models/cms/email_message.rb', line 33 def self.absolute_cms_url(path) host = normalize_domain(Rails.configuration.cms.site_domain) "http://#{cms_domain_prefix}.#{host}#{path}" end |
.deliver! ⇒ Object
15 16 17 18 19 20 |
# File 'app/models/cms/email_message.rb', line 15 def self.deliver! # Send all messages, 100 at a time undelivered.all(:limit => 100).each do |m| m.deliver! end end |
.mailbot_address ⇒ Object
Returns a default address that mail will be sent from. (i.e. [email protected])
39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/cms/email_message.rb', line 39 def self.mailbot_address address = Rails.configuration.cms.mailbot if address == :default host = normalize_domain(Rails.configuration.cms.site_domain) "mailbot@#{host}" else address end end |
.normalize_domain(domain) ⇒ Object
Returns a clean (non-www prefixed) domain name
23 24 25 26 27 |
# File 'app/models/cms/email_message.rb', line 23 def self.normalize_domain(domain) normalized = domain =~ /^www/ ? domain.sub(/^www\./, "") : domain # Strip the port URI.parse("http://#{normalized}").host end |
Instance Method Details
#deliver! ⇒ Object
55 56 57 58 59 60 |
# File 'app/models/cms/email_message.rb', line 55 def deliver! return false if delivered? self.sender = self.class.mailbot_address if self.sender.blank? Cms::EmailMessageMailer.(self).deliver update_attributes(:delivered_at => Time.now) end |
#deliver_now ⇒ Object
TODO: Take this out when we have an email queue processor
51 52 53 |
# File 'app/models/cms/email_message.rb', line 51 def deliver_now deliver! end |
#delivered? ⇒ Boolean
11 12 13 |
# File 'app/models/cms/email_message.rb', line 11 def delivered? !!delivered_at end |