module MailManager

Author

Chris Hauboldt (biz@lnstar.com)

Copyright

2009 Lone Star Internet Inc.

Worker used to check for ready Mailings and process/send them.

Author

Chris Hauboldt (biz@lnstar.com)

Copyright

2009 Lone Star Internet Inc.

Worker used to check for ready Messages and process/send them.

Author

Chris Hauboldt (biz@lnstar.com)

Copyright

2009 Lone Star Internet Inc.

Worker used to check for ready Mailings and process/send them.

Constants

Lock
LockException
PLUGIN_ROOT

used to easily know where the mail manager gem files are

VERSION

Public Class Methods

abilities() click to toggle source

can be used to inject cancan abilities into your application

# File lib/mail_manager/engine.rb, line 112
  def self.abilities
    <<-EOT
      if MailManager.authorized?(user)
        can :manage, [
          MailManager::Mailing,
          MailManager::MailingList,
          MailManager::Contact,
          MailManager::Subscription,
          MailManager::Bounce,
          MailManager::Message
        ]
        can [:send_test, :test, :schedule, :cancel], MailManager::Mailing
        can [:dismiss, :fail_address], MailManager::Bounce
        can [:delete, :undelete], MailManager::Contact
      end
      can [:subscribe, :double_opt_in, :thank_you], MailManager::Contact 
      can [:unsubscribe, :unsubscribe_by_email_address], MailManager::Subscription
    EOT
  end
assets_path() click to toggle source

easily get a path to the gem's assets

# File lib/mail_manager/engine.rb, line 139
def self.assets_path
  File.join(PLUGIN_ROOT,'assets')
end
authorized?(user) click to toggle source

logic for authorization mail manager

# File lib/mail_manager/engine.rb, line 104
def self.authorized?(user)
  return true unless ::MailManager.requires_authentication
  return false if user.blank?
  return true unless ::MailManager.authorized_roles.present?
  authorized_for_roles?(user, ::MailManager.authorized_roles)
end
authorized_for_roles?(user,roles=[]) click to toggle source

checks if the given 'user' has a role

# File lib/mail_manager/engine.rb, line 83
def self.authorized_for_roles?(user,roles=[])
  return true unless roles.present?
  user_roles = if ::MailManager.roles_method.present?
    if user.respond_to? ::MailManager.roles_method
      user.send(::MailManager.roles_method)
    else
      false
    end
  elsif user.respond_to?(:roles)
    user.roles 
  elsif user.respond_to?(:role)
    [user.role]
  else
    []
  end
  return false unless user_roles.present?
  user_roles = [user_roles] unless user_roles.is_a?(Array)
  roles.detect{|role| user_roles.map(&:to_sym).map(&:to_s).include?(role.to_s)}.present?
end
edit_route_for(contactable) click to toggle source

gives the url for a contactable object (such as users or members or whatever you set up for mapping to your contacts

# File lib/mail_manager/engine.rb, line 134
def self.edit_route_for(contactable)
  ContactableRegistry.edit_route_for(contactable.is_a?(String) ? contactable : contactable.class.name)
end
initialize_with_config(conf) click to toggle source

sets up your MailManager.blah configuration options from config/mail_manager.yml and can override those with config/mail_manager.local.yml for development environments

# File lib/mail_manager/engine.rb, line 155
def self.initialize_with_config(conf)
  MailManager.secret ||= conf.secret rescue nil
  default_url_options = ActionController::Base.default_url_options
  default_site_url = "#{default_url_options[:protocol]||'http'}://#{default_url_options[:domain]}" 
  MailManager.site_url ||= conf.site_url || default_site_url rescue default_site_url
  MailManager.dont_include_images_domains ||= conf.dont_include_images_domains || [] rescue []
  MailManager.sleep_time_between_messages ||= conf.sleep_time_between_messages || 0.3 rescue 0.3
  if conf.params.has_key?('table_prefix')
    MailManager.table_prefix ||= conf.table_prefix.to_s # allow empty
  else
    MailManager.table_prefix ||= 'mail_manager_'
  end
  MailManager.default_from_email_address ||= conf.default_from_email_address rescue nil
  MailManager.deliveries_per_run ||= (conf.deliveries_per_run || 50) rescue 50
  MailManager.signup_email_address ||= conf.signup_email_address rescue nil
  MailManager.bounce ||= conf.bounce || {} rescue {}
  MailManager.unsubscribe_path ||= conf.unsubscribe_path || "/listmgr" rescue "/listmgr"
  MailManager.subscribe_path ||= conf.subscribe_path || "/listmgr/subscribe" rescue "/listmgr/subscribe"
  MailManager.double_opt_in_path ||= conf.double_opt_in_path || "/listmgr/confirm" rescue "/listmgr/confirm"
  MailManager.honey_pot_field ||= conf.honey_pot_field || "company_name" rescue "company_name"
  MailManager.subscribe_thank_you_path ||= conf.subscribe_thank_you_path || "/listmgr/subscribe_thank_you" rescue "/listmgr/subscribe_thank_you"
  MailManager.site_path ||= conf.site_path || "/" rescue "/"
  MailManager.layout ||= conf.layout || "mail_manager/application" rescue "mail_manager/application"
  MailManager.public_layout ||= conf.public_layout || "mail_manager/application" rescue "mail_manager/application"
  MailManager.use_show_for_resources ||= conf.use_show_for_resources || false rescue false
  MailManager.show_title ||= conf.show_title || true rescue true
  MailManager.requires_authentication ||= conf.requires_authentication || false rescue false
  MailManager.authorized_roles ||= conf.authorized_roles || [] rescue []
  MailManager.roles_method ||= conf.roles_method || nil rescue nil
  MailManager.register_generic_mailable ||= conf.register_generic_mailable || false rescue false
  MailManager.exception_notification = {}
  MailManager.exception_notification[:to_addresses] ||= conf.exception_notification['to_addresses'] || [] rescue []
  MailManager.exception_notification[:from_address] ||= conf.exception_notification['from_address'] || nil rescue nil
end
public_path?(path) click to toggle source
# File lib/mail_manager/engine.rb, line 143
def self.public_path?(path)
  [
    MailManager.subscribe_path,
    MailManager.unsubscribe_path,
    MailManager.double_opt_in_path,
    MailManager.subscribe_thank_you_path
  ].detect{|public_path| public_path =~ /#{path}/i}.present?
end