Class: Cms::EmailMessage

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
DefaultAccessible, DomainSupport
Defined in:
app/models/cms/email_message.rb

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • path (String)

    A relative path (i.e. /cms/your-page)

Returns:



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_addressObject

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.email_message(self).deliver
  update_attributes(:delivered_at => Time.now)
end

#deliver_nowObject

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

Returns:

  • (Boolean)


11
12
13
# File 'app/models/cms/email_message.rb', line 11

def delivered?
  !!delivered_at
end