mail_manager 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.DS_Store +0 -0
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +27 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +141 -0
- data/Procfile +4 -0
- data/README +243 -0
- data/README.md +29 -0
- data/README.rdoc +3 -0
- data/Rakefile +33 -0
- data/app/.DS_Store +0 -0
- data/app/assets/javascripts/mail_manager/application.js +15 -0
- data/app/assets/stylesheets/mail_manager/application.css +13 -0
- data/app/controllers/mail_manager/application_controller.rb +4 -0
- data/app/controllers/mail_manager/base_controller.rb +22 -0
- data/app/controllers/mail_manager/bounces_controller.rb +32 -0
- data/app/controllers/mail_manager/contacts_controller.rb +75 -0
- data/app/controllers/mail_manager/mailing_lists_controller.rb +49 -0
- data/app/controllers/mail_manager/mailings_controller.rb +102 -0
- data/app/controllers/mail_manager/messages_controller.rb +30 -0
- data/app/controllers/mail_manager/subscriptions_controller.rb +104 -0
- data/app/helpers/mail_manager/application_helper.rb +4 -0
- data/app/helpers/mail_manager/subscriptions_helper.rb +8 -0
- data/app/models/.DS_Store +0 -0
- data/app/models/mail_manager.rb +12 -0
- data/app/models/mail_manager/bounce.rb +133 -0
- data/app/models/mail_manager/contact.rb +91 -0
- data/app/models/mail_manager/contactable_registry.rb +190 -0
- data/app/models/mail_manager/mailable_registry.rb +127 -0
- data/app/models/mail_manager/mailer.rb +267 -0
- data/app/models/mail_manager/mailing.rb +266 -0
- data/app/models/mail_manager/mailing_list.rb +36 -0
- data/app/models/mail_manager/message.rb +127 -0
- data/app/models/mail_manager/subscription.rb +126 -0
- data/app/models/mail_manager/test_message.rb +175 -0
- data/app/models/status_history.rb +60 -0
- data/app/views/layouts/mail_manager/application.html.erb +14 -0
- data/app/views/mail_manager/bounces/_email_parts.html.erb +30 -0
- data/app/views/mail_manager/bounces/index.html.erb +32 -0
- data/app/views/mail_manager/bounces/show.html.erb +38 -0
- data/app/views/mail_manager/contacts/_form.html.erb +27 -0
- data/app/views/mail_manager/contacts/double_opt_in.html.erb +1 -0
- data/app/views/mail_manager/contacts/edit.html.erb +12 -0
- data/app/views/mail_manager/contacts/index.html.erb +86 -0
- data/app/views/mail_manager/contacts/new.html.erb +9 -0
- data/app/views/mail_manager/contacts/show.html.erb +22 -0
- data/app/views/mail_manager/contacts/subscribe.html.erb +2 -0
- data/app/views/mail_manager/contacts/thank_you.html.erb +12 -0
- data/app/views/mail_manager/help/_available_email_substitutions.html.erb +5 -0
- data/app/views/mail_manager/mailer/double_opt_in.erb +6 -0
- data/app/views/mail_manager/mailer/unsubscribed.erb +5 -0
- data/app/views/mail_manager/mailer/unsubscribed.html.erb +5 -0
- data/app/views/mail_manager/mailing_lists/_form.html.erb +20 -0
- data/app/views/mail_manager/mailing_lists/edit.html.erb +13 -0
- data/app/views/mail_manager/mailing_lists/index.html.erb +39 -0
- data/app/views/mail_manager/mailing_lists/new.html.erb +9 -0
- data/app/views/mail_manager/mailing_lists/show.html.erb +13 -0
- data/app/views/mail_manager/mailings/_form.html.erb +81 -0
- data/app/views/mail_manager/mailings/edit.html.erb +12 -0
- data/app/views/mail_manager/mailings/index.html.erb +52 -0
- data/app/views/mail_manager/mailings/new.html.erb +9 -0
- data/app/views/mail_manager/mailings/show.html.erb +28 -0
- data/app/views/mail_manager/mailings/test.html.erb +12 -0
- data/app/views/mail_manager/messages/index.html.erb +37 -0
- data/app/views/mail_manager/subscriptions/_form.html.erb +37 -0
- data/app/views/mail_manager/subscriptions/_subscriptions.html.erb +13 -0
- data/app/views/mail_manager/subscriptions/edit.html.erb +11 -0
- data/app/views/mail_manager/subscriptions/index.html.erb +32 -0
- data/app/views/mail_manager/subscriptions/new.html.erb +9 -0
- data/app/views/mail_manager/subscriptions/show.html.erb +8 -0
- data/app/views/mail_manager/subscriptions/unsubscribe.html.erb +2 -0
- data/app/views/mail_manager/subscriptions/unsubscribe_by_email_address.html.erb +13 -0
- data/config/daemons.yml +5 -0
- data/config/routes.rb +43 -0
- data/db/migrate/001_mail_mgr_initial.rb +84 -0
- data/db/migrate/002_mail_mgr_create_contact.rb +60 -0
- data/db/migrate/003_mail_mgr_test_message.rb +23 -0
- data/db/migrate/004_add_deleted_at_to_mailing_lists.rb +15 -0
- data/db/migrate/005_contacts_deleted_at.rb +15 -0
- data/db/migrate/006_mail_mgr_mailing_list_add_defaults_to_active.rb +15 -0
- data/db/migrate/007_mail_mgr_message_add_from_email_address.rb +15 -0
- data/db/mlm_migrate/001_mlm_initial.rb +67 -0
- data/db/mlm_migrate/002_mailable_as_polymorphic.rb +27 -0
- data/db/mlm_migrate/003_contact_as_polymorphic.rb +64 -0
- data/db/mlm_migrate/004_bounce_mlm_mailing_id.rb +26 -0
- data/db/mlm_migrate/005_mlm_to_mail_mgr_scoped.rb +29 -0
- data/engine_plan.rb +13 -0
- data/features/bounce_management.feature +0 -0
- data/features/contact_management.feature +24 -0
- data/features/mailable.feature +23 -0
- data/features/mailing_management.feature +78 -0
- data/features/message.feature +11 -0
- data/features/step_definitions/email_steps.rb +50 -0
- data/features/step_definitions/mlm_steps.rb +11 -0
- data/features/step_definitions/pickle_steps.rb +41 -0
- data/features/step_definitions/webrat_steps.rb +115 -0
- data/features/subscription_management.feature +17 -0
- data/features/support/env.rb +31 -0
- data/features/support/paths.rb +44 -0
- data/lib/daemons/mail_manager.rb +38 -0
- data/lib/daemons/mail_manager_ctl +15 -0
- data/lib/deleteable.rb +50 -0
- data/lib/lock.rb +36 -0
- data/lib/mail_manager.rb +5 -0
- data/lib/mail_manager/config.rb +50 -0
- data/lib/mail_manager/engine.rb +43 -0
- data/lib/mail_manager/version.rb +3 -0
- data/lib/tasks/mail_manager.rake +143 -0
- data/lib/tasks/mail_manager_tasks.rake +4 -0
- data/lib/tasks/rspec.rake +165 -0
- data/lib/workers/mail_manager/bounce_job.rb +52 -0
- data/lib/workers/mail_manager/mailing_job.rb +30 -0
- data/lib/workers/mail_manager/message_job.rb +38 -0
- data/lib/workers/mail_manager/test_message_job.rb +37 -0
- data/mail_manager.gemspec +29 -0
- data/script/rails +8 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/test_app/README.rdoc +261 -0
- data/spec/test_app/Rakefile +7 -0
- data/spec/test_app/app/assets/javascripts/application.js +15 -0
- data/spec/test_app/app/assets/javascripts/users.js +2 -0
- data/spec/test_app/app/assets/stylesheets/application.css +13 -0
- data/spec/test_app/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/test_app/app/assets/stylesheets/users.css +4 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/users_controller.rb +83 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/helpers/users_helper.rb +2 -0
- data/spec/test_app/app/models/user.rb +13 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/app/views/users/_form.html.erb +33 -0
- data/spec/test_app/app/views/users/edit.html.erb +6 -0
- data/spec/test_app/app/views/users/index.html.erb +29 -0
- data/spec/test_app/app/views/users/new.html.erb +5 -0
- data/spec/test_app/app/views/users/show.html.erb +25 -0
- data/spec/test_app/config.ru +4 -0
- data/spec/test_app/config/application.rb +65 -0
- data/spec/test_app/config/boot.rb +10 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +14 -0
- data/spec/test_app/config/environments/development.rb +37 -0
- data/spec/test_app/config/environments/production.rb +67 -0
- data/spec/test_app/config/environments/test.rb +37 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/inflections.rb +15 -0
- data/spec/test_app/config/initializers/mime_types.rb +5 -0
- data/spec/test_app/config/initializers/secret_token.rb +7 -0
- data/spec/test_app/config/initializers/session_store.rb +8 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +5 -0
- data/spec/test_app/config/lockable.yml +3 -0
- data/spec/test_app/config/mail_manager.yml +21 -0
- data/spec/test_app/config/routes.rb +7 -0
- data/spec/test_app/db/migrate/20131217101010_create_users.rb +13 -0
- data/spec/test_app/db/migrate/20131221064151_mail_mgr_initial.rb +84 -0
- data/spec/test_app/db/migrate/20131221064152_mail_mgr_create_contact.rb +60 -0
- data/spec/test_app/db/migrate/20131221064153_mail_mgr_test_message.rb +23 -0
- data/spec/test_app/db/migrate/20131221064154_add_deleted_at_to_mailing_lists.rb +15 -0
- data/spec/test_app/db/migrate/20131221064155_contacts_deleted_at.rb +15 -0
- data/spec/test_app/db/migrate/20131221064156_mail_mgr_mailing_list_add_defaults_to_active.rb +15 -0
- data/spec/test_app/db/migrate/20131221064157_mail_mgr_message_add_from_email_address.rb +15 -0
- data/spec/test_app/db/migrate/20131221072600_create_delayed_jobs.rb +22 -0
- data/spec/test_app/db/schema.rb +131 -0
- data/spec/test_app/db/structure.sql +31 -0
- data/spec/test_app/public/404.html +26 -0
- data/spec/test_app/public/422.html +26 -0
- data/spec/test_app/public/500.html +25 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/test_app/script/delayed_job +5 -0
- data/spec/test_app/script/lockable +36 -0
- data/spec/test_app/script/rails +6 -0
- data/spec/test_app/spec/controllers/users_controller_spec.rb +160 -0
- data/spec/test_app/spec/factories/mailing_lists.rb +7 -0
- data/spec/test_app/spec/factories/mailings.rb +6 -0
- data/spec/test_app/spec/factories/original_factories.rb.txt +107 -0
- data/spec/test_app/spec/factories/users.rb +10 -0
- data/spec/test_app/spec/models/mail_manager/bounce_spec.rb +17 -0
- data/spec/test_app/spec/models/mail_manager/mailing_list_spec.rb +15 -0
- data/spec/test_app/spec/models/user_spec.rb +37 -0
- data/spec/test_app/spec/requests/users_spec.rb +11 -0
- data/spec/test_app/spec/routing/users_routing_spec.rb +35 -0
- data/spec/test_app/spec/support/database_cleaner.rb +23 -0
- data/spec/test_app/spec/support/files/bad_utf8_chars.eml +32 -0
- data/spec/test_app/spec/views/users/edit.html.erb_spec.rb +24 -0
- data/spec/test_app/spec/views/users/index.html.erb_spec.rb +29 -0
- data/spec/test_app/spec/views/users/new.html.erb_spec.rb +24 -0
- data/spec/test_app/spec/views/users/show.html.erb_spec.rb +21 -0
- data/zeus.json +22 -0
- metadata +424 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# You might want to change this
|
|
4
|
+
ENV['Rails.env'] ||= 'production'
|
|
5
|
+
require File.dirname(__FILE__) + "/../../config/environment"
|
|
6
|
+
require 'workers/mail_manager/mailing_job'
|
|
7
|
+
require 'workers/mail_manager/test_message_job'
|
|
8
|
+
require 'workers/mail_manager/message_job'
|
|
9
|
+
require 'workers/mail_manager/bounce_job'
|
|
10
|
+
|
|
11
|
+
$running = true
|
|
12
|
+
Signal.trap("TERM") do
|
|
13
|
+
$running = false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
while($running) do
|
|
17
|
+
begin
|
|
18
|
+
MailManager::MailingJob.run
|
|
19
|
+
rescue => e
|
|
20
|
+
Rails.logger.warn " MailManager::MailingJob.run failed.\n#{e.message}\n #{e.backtrace.join(" \n")}"
|
|
21
|
+
end
|
|
22
|
+
begin
|
|
23
|
+
MailManager::MessageJob.run
|
|
24
|
+
rescue => e
|
|
25
|
+
Rails.logger.warn " MailManager::MessageJob.run failed.\n#{e.message}\n #{e.backtrace.join(" \n")}"
|
|
26
|
+
end
|
|
27
|
+
begin
|
|
28
|
+
MailManager::TestMessageJob.run
|
|
29
|
+
rescue => e
|
|
30
|
+
Rails.logger.warn " MailManager::TestMessageJob.run failed.\n#{e.message}\n #{e.backtrace.join(" \n")}"
|
|
31
|
+
end
|
|
32
|
+
begin
|
|
33
|
+
MailManager::BounceJob.run
|
|
34
|
+
rescue => e
|
|
35
|
+
Rails.logger.warn " MailManager::Bounce.run failed.\n#{e.message}\n #{e.backtrace.join(" \n")}"
|
|
36
|
+
end
|
|
37
|
+
sleep 30
|
|
38
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require "daemons"
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'erb'
|
|
6
|
+
require 'active_support'
|
|
7
|
+
|
|
8
|
+
options = YAML.load(
|
|
9
|
+
ERB.new(
|
|
10
|
+
IO.read(
|
|
11
|
+
File.dirname(__FILE__) + "/../../config/daemons.yml"
|
|
12
|
+
)).result).with_indifferent_access
|
|
13
|
+
options[:dir_mode] = options[:dir_mode].to_sym
|
|
14
|
+
|
|
15
|
+
Daemons.run File.dirname(__FILE__) + '/mail_manager.rb', options
|
data/lib/deleteable.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Deleteable
|
|
2
|
+
|
|
3
|
+
def self.included(receiver)
|
|
4
|
+
receiver.extend ClassMethods
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def is_deleted?
|
|
8
|
+
!deleted_at.nil?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def delete
|
|
12
|
+
update_attribute(:deleted_at,Time.now)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def undelete
|
|
16
|
+
update_attribute(:deleted_at,nil)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module ClassMethods
|
|
20
|
+
def find(*args)
|
|
21
|
+
if args[0] == (:exclusive_scope)
|
|
22
|
+
args.shift
|
|
23
|
+
super
|
|
24
|
+
else
|
|
25
|
+
with_scope(:find => {:conditions => ["#{table_name}.deleted_at is null"]}) do
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module DeleteableActions
|
|
35
|
+
def delete
|
|
36
|
+
destroy
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def destroy
|
|
40
|
+
thing = controller_name.singularize.split('_').collect{|string| string.capitalize}.join.constantize.find(params[:id])
|
|
41
|
+
thing.delete
|
|
42
|
+
redirect_to(eval("#{controller_name}_path(derailed_params)"))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def undelete
|
|
46
|
+
thing = controller_name.singularize.split('_').collect{|string| string.capitalize}.join.constantize.find(:exclusive_scope,params[:id])
|
|
47
|
+
thing.undelete
|
|
48
|
+
redirect_to(eval("#{controller_name}_path(derailed_params)"))
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/lock.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class Lock
|
|
2
|
+
class LockException < Exception
|
|
3
|
+
end
|
|
4
|
+
def self.with_lock(name, timeout=5, max_attempts=1, &block)
|
|
5
|
+
ActiveRecord::Base.connection_pool.with_connection do |connection|
|
|
6
|
+
begin
|
|
7
|
+
lock = get_lock(connection,name,timeout,max_attempts)
|
|
8
|
+
raise LockException.new("Failed to obtain lock #{name} in #{timeout} secs") unless lock
|
|
9
|
+
yield lock
|
|
10
|
+
ensure
|
|
11
|
+
is_released = release_lock(connection,name)
|
|
12
|
+
Rails.logger.warn "Warning: lock #{name} not released!" unless is_released.values.include?('1')
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def self.name_prefix
|
|
20
|
+
"#{MailManager.site_url}-#{Rails.env}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.get_lock(connection,name,timeout,max_attempts)
|
|
24
|
+
attempts = 0
|
|
25
|
+
lock = {}
|
|
26
|
+
while !lock.values.include?('1') and attempts < max_attempts do
|
|
27
|
+
attempts += 1
|
|
28
|
+
lock = connection.select_one("SELECT GET_LOCK('#{name_prefix}-#{name}',#{timeout})")
|
|
29
|
+
end
|
|
30
|
+
lock.values.detect{|value| value.to_s.eql?('1')}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.release_lock(connection,name)
|
|
34
|
+
connection.select_one("SELECT RELEASE_LOCK('#{name_prefix}-#{name}')")
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/mail_manager.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'erb'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
class MailManager::Config
|
|
5
|
+
attr_reader :sections, :params
|
|
6
|
+
|
|
7
|
+
def initialize(file = nil)
|
|
8
|
+
@sections = {}
|
|
9
|
+
@params = {}
|
|
10
|
+
use_file!(file) if file
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def use_file!(file)
|
|
14
|
+
begin
|
|
15
|
+
hash = YAML::load(ERB.new(IO.read(file)).result)
|
|
16
|
+
@sections.merge!(hash) {|key, old_val, new_val| (old_val || new_val).merge new_val }
|
|
17
|
+
@params.merge!(@sections['common'])
|
|
18
|
+
rescue => e
|
|
19
|
+
nil
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def use_section!(section)
|
|
24
|
+
@params.merge!(@sections[section.to_s]) if @sections.key?(section.to_s)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def method_missing(param)
|
|
28
|
+
param = param.to_s
|
|
29
|
+
if @params.key?(param)
|
|
30
|
+
@params[param]
|
|
31
|
+
else
|
|
32
|
+
Rails.logger.warn "Invalid AppConfig Parameter " + param
|
|
33
|
+
nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.initialize!
|
|
38
|
+
standard_file = File.join(Rails.root,'config','mail_manager.yml')
|
|
39
|
+
local_file = File.join(Rails.root,'config','mail_manager.local.yml')
|
|
40
|
+
unless File.exists?(standard_file)
|
|
41
|
+
$stderr.puts "Missing Configuration: either define ::Conf with proper values or create a config/mail_manager.yml with rake mail_manager:default_app_config"
|
|
42
|
+
end
|
|
43
|
+
c = ::MailManager::Config.new
|
|
44
|
+
c.use_file!("#{Rails.root}/config/mail_manager.yml")
|
|
45
|
+
c.use_file!("#{Rails.root}/config/mail_manager.local.yml")
|
|
46
|
+
c.use_section!(Rails.env)
|
|
47
|
+
c
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module MailManager
|
|
2
|
+
mattr_accessor :secret, :site_url, :dont_include_images_domains, :sleep_time_between_messages, :table_prefix,
|
|
3
|
+
:default_from_email_address, :bounce, :unsubscribe_path, :site_path, :layout, :use_show_for_resources
|
|
4
|
+
class Engine < ::Rails::Engine
|
|
5
|
+
isolate_namespace MailManager
|
|
6
|
+
initializer "MailManager.config" do |app|
|
|
7
|
+
if File.exist?(File.join(Rails.root,'config','mail_manager.yml'))
|
|
8
|
+
require 'mail_manager/config'
|
|
9
|
+
MailManager.initialize_with_config(MailManager::Config.initialize!)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
config.generators do |g|
|
|
13
|
+
g.test_framework :rspec, :fixture => false
|
|
14
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
PLUGIN_ROOT = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
|
|
18
|
+
def self.edit_route_for(contactable)
|
|
19
|
+
ContactableRegistry.edit_route_for(contactable.is_a?(String) ? contactable : contactable.class.name)
|
|
20
|
+
end
|
|
21
|
+
def self.assets_path
|
|
22
|
+
File.join(PLUGIN_ROOT,'assets')
|
|
23
|
+
end
|
|
24
|
+
def self.initialize_with_config(conf)
|
|
25
|
+
MailManager.secret ||= conf.secret rescue nil
|
|
26
|
+
default_url_options = ActionController::Base.default_url_options
|
|
27
|
+
default_site_url = "#{default_url_options[:protocol]||'http'}://#{default_url_options[:domain]}"
|
|
28
|
+
MailManager.site_url ||= conf.site_url || default_site_url rescue default_site_url
|
|
29
|
+
MailManager.dont_include_images_domains ||= conf.dont_include_images_domains || [] rescue []
|
|
30
|
+
MailManager.sleep_time_between_messages ||= conf.sleep_time_between_messages || 0.3 rescue 0.3
|
|
31
|
+
MailManager.table_prefix ||= conf.table_prefix || 'mail_manager_' rescue 'mail_manager_'
|
|
32
|
+
MailManager.default_from_email_address ||= conf.default_from_email_address rescue nil
|
|
33
|
+
MailManager.bounce ||= conf.bounce || {} rescue {}
|
|
34
|
+
MailManager.unsubscribe_path ||= conf.unsubscribe_path || "/listmgr" rescue "/listmgr"
|
|
35
|
+
MailManager.site_path ||= conf.site_path || "/" rescue "/"
|
|
36
|
+
MailMatager.layout ||= conf.layout || "application" rescue "application"
|
|
37
|
+
MailMatager.use_show_for_resources ||= conf.use_show_for_resources || false rescue false
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
MailManager::Engine.config.to_prepare do
|
|
41
|
+
ApplicationController.helper(MailManager::SubscriptionsHelper)
|
|
42
|
+
end
|
|
43
|
+
require 'will_paginate'
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
ENV["Rails.env"] ||= "development"
|
|
3
|
+
require "#{Rails.root}/config/environment"
|
|
4
|
+
|
|
5
|
+
namespace :mail_manager do
|
|
6
|
+
desc "Create mlm LSI Auth Menus"
|
|
7
|
+
task :create_auth_menus, :parent_menu do |t,args|
|
|
8
|
+
Rails.logger.warn "Creating mlm LSI Auth Menus"
|
|
9
|
+
parent_menu = args.parent_menu
|
|
10
|
+
AdminMenu.create_or_find(
|
|
11
|
+
:description=>'Mailings',
|
|
12
|
+
:path=>'admin/mail_manager/mailings',
|
|
13
|
+
:admin_menu_id=>AdminMenu.find_by_description(parent_menu).id,
|
|
14
|
+
:menu_order=>15,
|
|
15
|
+
:is_visible=>1,
|
|
16
|
+
:auth_all=>1)
|
|
17
|
+
AdminMenu.create_or_find(
|
|
18
|
+
:description=>'Mailing Lists',
|
|
19
|
+
:path=>'admin/mail_manager/mailing_lists',
|
|
20
|
+
:admin_menu_id=>AdminMenu.find_by_description(parent_menu).id,
|
|
21
|
+
:menu_order=>20,
|
|
22
|
+
:is_visible=>1,
|
|
23
|
+
:auth_all=>1)
|
|
24
|
+
AdminMenu.create_or_find(
|
|
25
|
+
:description=>'Bounces',
|
|
26
|
+
:path=>'admin/mail_manager/bounces',
|
|
27
|
+
:admin_menu_id=>AdminMenu.find_by_description(parent_menu).id,
|
|
28
|
+
:menu_order=>30,
|
|
29
|
+
:is_visible=>1,
|
|
30
|
+
:auth_all=>1)
|
|
31
|
+
AdminMenu.create_or_find(
|
|
32
|
+
:description=>'Contacts',
|
|
33
|
+
:path=>'admin/mail_manager/contacts',
|
|
34
|
+
:admin_menu_id=>AdminMenu.find_by_description('Newsletter').id,
|
|
35
|
+
:menu_order=>10,
|
|
36
|
+
:is_visible=>1,
|
|
37
|
+
:auth_all=>1)
|
|
38
|
+
AdminMenu.create_or_find(
|
|
39
|
+
:description=>'MLM General Auth',
|
|
40
|
+
:path=>'admin/mail_manager',
|
|
41
|
+
:admin_menu_id=>nil,
|
|
42
|
+
:menu_order=>0,
|
|
43
|
+
:is_visible=>0,
|
|
44
|
+
:auth_all=>1)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
desc "Add mlm defaults to config/mail_manager.yml"
|
|
48
|
+
task :default_app_config, :table_prefix do |t,args|
|
|
49
|
+
Rails.logger.warn "Adding defaults to config/mail_manager.yml"
|
|
50
|
+
begin
|
|
51
|
+
app_config = YAML.load_file('config/mail_manager.yml')
|
|
52
|
+
rescue => e
|
|
53
|
+
app_config = Hash.new
|
|
54
|
+
end
|
|
55
|
+
File.open('config/mail_manager.yml','w') do |file|
|
|
56
|
+
file.write YAML.dump({
|
|
57
|
+
'common' => {
|
|
58
|
+
'site_url' => 'http://example.com',
|
|
59
|
+
'mail_manager' => {
|
|
60
|
+
'unsubscribe_path' => '/listmgr',
|
|
61
|
+
'dont_include_images_domains' => [
|
|
62
|
+
'yahoo.com', 'google.com', 'hotmail.com'
|
|
63
|
+
],
|
|
64
|
+
'sleep_time_between_messages' => 0.3,
|
|
65
|
+
'path_prefix' => '/admin',
|
|
66
|
+
'table_prefix' => args.table_prefix,
|
|
67
|
+
'default_from_email_address' => 'eESI <eESINews@eesipeo.com>',
|
|
68
|
+
'secret' => SecureRandom.hex(15).to_s,
|
|
69
|
+
'bounce' => {
|
|
70
|
+
'email_address' => 'test@example.com',
|
|
71
|
+
'login' => 'test',
|
|
72
|
+
'password' => 'secret',
|
|
73
|
+
'pop_server' => 'pop.example.com'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}.deep_merge(app_config))
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
desc "Import Migrations"
|
|
81
|
+
task :import_migrations do
|
|
82
|
+
Rails.logger.info "Importing Migrations"
|
|
83
|
+
seconds_offset = 1
|
|
84
|
+
migrations_dir = ::MailManager::PLUGIN_ROOT+'/db/migrate'
|
|
85
|
+
FileUtils.mkdir_p('db/migrate') unless File.exists?('db/migrate')
|
|
86
|
+
Dir.entries(migrations_dir).
|
|
87
|
+
select{|filename| filename =~ /^\d+.*rb$/}.sort.each do |filename|
|
|
88
|
+
migration_name = filename.gsub(/^\d+/,'')
|
|
89
|
+
if Dir.entries('db/migrate').detect{|file| file =~ /^\d+#{migration_name}$/}
|
|
90
|
+
puts "Migrations already exist for #{migration_name}"
|
|
91
|
+
else
|
|
92
|
+
Rails.logger.info "Importing Migration: #{migration_name}"
|
|
93
|
+
File.open("db/migrate/#{seconds_offset.seconds.from_now.strftime("%Y%m%d%H%M%S")}#{migration_name}",'w') do |file|
|
|
94
|
+
file.write File.readlines("#{migrations_dir}/#{filename}").join
|
|
95
|
+
end
|
|
96
|
+
seconds_offset += 1
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
desc "Create Mailing List"
|
|
101
|
+
task :create_mailing_list, :list_name do |t,args|
|
|
102
|
+
Rails.logger.warn "Creating Mailing List '#{args.list_name}'"
|
|
103
|
+
MailManager::MailingList.create(:name => args.list_name)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
desc "Create Delayed Jobs for Mail Mgr"
|
|
107
|
+
task :create_delayed_jobs do
|
|
108
|
+
Delayed::RepeatingJob.enqueue(MailManager::BounceJob.new(15.minutes))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
desc "Create Groups and Users"
|
|
112
|
+
task :import_groups_and_users do
|
|
113
|
+
groups = ["CORPORATE_GOVERNMENT_GROUP", "CORPORATE_MEDICAL_GROUP", "CORPORATE_BUSINESS_GROUP", "CORPORATE_SCIENCE_AND_TECH_GROUP"]
|
|
114
|
+
#groups = ["CORPORATE_BUSINESS_GROUP"]
|
|
115
|
+
|
|
116
|
+
groups.each do |group|
|
|
117
|
+
puts "Processing group #{group}..."
|
|
118
|
+
mailing_list = MailManager::MailingList.find(:first, :conditions => ["name=?",group])
|
|
119
|
+
if mailing_list.nil?
|
|
120
|
+
mailing_list = MailManager::MailingList.create(:name => group)
|
|
121
|
+
end
|
|
122
|
+
items_read = 0
|
|
123
|
+
items_added = 0
|
|
124
|
+
group_file = File.open("#{RAILS_ROOT}/imports/#{group}.csv", "r")
|
|
125
|
+
#this works with csv file generated on microsoft office for windows
|
|
126
|
+
group_file.readlines.each do |record|
|
|
127
|
+
users = record.split(" ")
|
|
128
|
+
for u in users
|
|
129
|
+
items_read += 1
|
|
130
|
+
user = MailManager::Contact.find(:first, :conditions => ["email_address=?", u])
|
|
131
|
+
if user.nil?
|
|
132
|
+
items_added += 1
|
|
133
|
+
user = MailManager::Contact.create(:email_address => u)
|
|
134
|
+
end
|
|
135
|
+
user.subscribe(mailing_list)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
puts "I read in #{items_read.to_s} items and added #{items_added.to_s} of them."
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
|
|
2
|
+
|
|
3
|
+
# # Don't load rspec if running "rake gems:*"
|
|
4
|
+
# unless ARGV.any? {|a| a =~ /^gems/}
|
|
5
|
+
|
|
6
|
+
# begin
|
|
7
|
+
# require 'spec/rake/spectask'
|
|
8
|
+
# rescue MissingSourceFile
|
|
9
|
+
# module Spec
|
|
10
|
+
# module Rake
|
|
11
|
+
# class SpecTask
|
|
12
|
+
# def initialize(name)
|
|
13
|
+
# task name do
|
|
14
|
+
# # if rspec-rails is a configured gem, this will output helpful material and exit ...
|
|
15
|
+
# require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
|
|
16
|
+
|
|
17
|
+
# # ... otherwise, do this:
|
|
18
|
+
# raise <<-MSG
|
|
19
|
+
|
|
20
|
+
# #{"*" * 80}
|
|
21
|
+
# * You are trying to run an rspec rake task defined in
|
|
22
|
+
# * #{__FILE__},
|
|
23
|
+
# * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
|
|
24
|
+
# #{"*" * 80}
|
|
25
|
+
# MSG
|
|
26
|
+
# end
|
|
27
|
+
# end
|
|
28
|
+
# end
|
|
29
|
+
# end
|
|
30
|
+
# end
|
|
31
|
+
# end
|
|
32
|
+
|
|
33
|
+
# Rake.application.instance_variable_get('@tasks').delete('default')
|
|
34
|
+
|
|
35
|
+
# spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
|
|
36
|
+
# task :noop do
|
|
37
|
+
# end
|
|
38
|
+
|
|
39
|
+
# task :default => :spec
|
|
40
|
+
# task :stats => "spec:statsetup"
|
|
41
|
+
|
|
42
|
+
# desc "Run all specs in spec directory (excluding plugin specs)"
|
|
43
|
+
# Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
|
|
44
|
+
# t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
|
|
45
|
+
# t.spec_files = FileList['spec/**/*/*_spec.rb']
|
|
46
|
+
# end
|
|
47
|
+
|
|
48
|
+
# namespace :spec do
|
|
49
|
+
# desc "Run all specs in spec directory with RCov (excluding plugin specs)"
|
|
50
|
+
# Spec::Rake::SpecTask.new(:rcov) do |t|
|
|
51
|
+
# t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
|
|
52
|
+
# t.spec_files = FileList['spec/**/*/*_spec.rb']
|
|
53
|
+
# t.rcov = true
|
|
54
|
+
# t.rcov_opts = lambda do
|
|
55
|
+
# IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
|
|
56
|
+
# end
|
|
57
|
+
# end
|
|
58
|
+
|
|
59
|
+
# desc "Print Specdoc for all specs (excluding plugin specs)"
|
|
60
|
+
# Spec::Rake::SpecTask.new(:doc) do |t|
|
|
61
|
+
# t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
|
62
|
+
# t.spec_files = FileList['spec/**/*/*_spec.rb']
|
|
63
|
+
# end
|
|
64
|
+
|
|
65
|
+
# desc "Print Specdoc for all plugin examples"
|
|
66
|
+
# Spec::Rake::SpecTask.new(:plugin_doc) do |t|
|
|
67
|
+
# t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
|
68
|
+
# t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*')
|
|
69
|
+
# end
|
|
70
|
+
|
|
71
|
+
# [:models, :controllers, :views, :helpers, :lib].each do |sub|
|
|
72
|
+
# desc "Run the code examples in spec/#{sub}"
|
|
73
|
+
# Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
|
|
74
|
+
# t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
|
|
75
|
+
# t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
|
76
|
+
# end
|
|
77
|
+
# end
|
|
78
|
+
|
|
79
|
+
# desc "Run the code examples in vendor/plugins (except RSpec's own)"
|
|
80
|
+
# Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
|
|
81
|
+
# t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
|
|
82
|
+
# t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
|
|
83
|
+
# end
|
|
84
|
+
|
|
85
|
+
# namespace :plugins do
|
|
86
|
+
# desc "Runs the examples for rspec_on_rails"
|
|
87
|
+
# Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
|
|
88
|
+
# t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
|
|
89
|
+
# t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*/*_spec.rb']
|
|
90
|
+
# end
|
|
91
|
+
# end
|
|
92
|
+
|
|
93
|
+
# # Setup specs for stats
|
|
94
|
+
# task :statsetup do
|
|
95
|
+
# require 'code_statistics'
|
|
96
|
+
# ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
|
|
97
|
+
# ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
|
|
98
|
+
# ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
|
|
99
|
+
# ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
|
|
100
|
+
# ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
|
|
101
|
+
# ::STATS_DIRECTORIES << %w(Routing\ specs spec/lib) if File.exist?('spec/routing')
|
|
102
|
+
# ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
|
|
103
|
+
# ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
|
|
104
|
+
# ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
|
|
105
|
+
# ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
|
|
106
|
+
# ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
|
|
107
|
+
# ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
|
|
108
|
+
# end
|
|
109
|
+
|
|
110
|
+
# namespace :db do
|
|
111
|
+
# namespace :fixtures do
|
|
112
|
+
# desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
|
|
113
|
+
# task :load => :environment do
|
|
114
|
+
# ActiveRecord::Base.establish_connection(Rails.env)
|
|
115
|
+
# base_dir = File.join(Rails.root, 'spec', 'fixtures')
|
|
116
|
+
# fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
|
|
117
|
+
|
|
118
|
+
# require 'active_record/fixtures'
|
|
119
|
+
# (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
|
|
120
|
+
# Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
|
|
121
|
+
# end
|
|
122
|
+
# end
|
|
123
|
+
# end
|
|
124
|
+
# end
|
|
125
|
+
|
|
126
|
+
# namespace :server do
|
|
127
|
+
# daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid")
|
|
128
|
+
|
|
129
|
+
# desc "start spec_server."
|
|
130
|
+
# task :start do
|
|
131
|
+
# if File.exist?(daemonized_server_pid)
|
|
132
|
+
# $stderr.puts "spec_server is already running."
|
|
133
|
+
# else
|
|
134
|
+
# $stderr.puts %Q{Starting up spec_server ...}
|
|
135
|
+
# FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
|
|
136
|
+
# system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
|
|
137
|
+
# end
|
|
138
|
+
# end
|
|
139
|
+
|
|
140
|
+
# desc "stop spec_server."
|
|
141
|
+
# task :stop do
|
|
142
|
+
# unless File.exist?(daemonized_server_pid)
|
|
143
|
+
# $stderr.puts "No server running."
|
|
144
|
+
# else
|
|
145
|
+
# $stderr.puts "Shutting down spec_server ..."
|
|
146
|
+
# system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
|
|
147
|
+
# File.delete(daemonized_server_pid)
|
|
148
|
+
# end
|
|
149
|
+
# end
|
|
150
|
+
|
|
151
|
+
# desc "restart spec_server."
|
|
152
|
+
# task :restart => [:stop, :start]
|
|
153
|
+
|
|
154
|
+
# desc "check if spec server is running"
|
|
155
|
+
# task :status do
|
|
156
|
+
# if File.exist?(daemonized_server_pid)
|
|
157
|
+
# $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
|
|
158
|
+
# else
|
|
159
|
+
# $stderr.puts "No server running."
|
|
160
|
+
# end
|
|
161
|
+
# end
|
|
162
|
+
# end
|
|
163
|
+
# end
|
|
164
|
+
|
|
165
|
+
# end
|