mailman-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mailman-rails.gemspec
4
+ gemspec
5
+ # Uncomment this line to get tests working:
6
+ #gem 'mailman', :git => 'https://github.com/titanous/mailman' # The version in rubygems isn't yet compatible with this gem at time of writing
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Cant
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Mailman::Rails
2
+
3
+ This gem helps you integrate <a href="https://github.com/titanous/mailman">ruby Mailman</a> with Rails. It adds rake tasks to manage a mailman daemon and allows you to configure a Mailman::Application instance from within your models.
4
+
5
+ ## Installation
6
+
7
+ Add these line to your application's Gemfile:
8
+
9
+ gem 'mailman-rails'
10
+ gem 'mailman', :git => 'https://github.com/titanous/mailman' # The version in rubygems isn't yet compatible with this gem
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install mailman-rails
19
+
20
+ ## Usage
21
+
22
+ Put your Mailman config in config/initializers/mailman.rb
23
+
24
+ Match Mailman stuff from your models:
25
+ <pre>
26
+ class Post < ActiveRecord::Base # Or whatever
27
+
28
+ Mailman::Rails.receive do
29
+ to "posts@example.com" do
30
+ Post.create(JSON.parse(message.body))
31
+ end
32
+ end
33
+
34
+ # The daemon would be started from the rake task but only after all the code is loaded.
35
+
36
+ end
37
+ </pre>
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ Return-Path: <test@example.com>
2
+ X-Original-To: email1@example.com
3
+ Delivered-To: email1@example.com
4
+ Received: from localhost (localhost [127.0.0.1])
5
+ by mail.example.com (Postfix) with SMTP id BC4F6421C5
6
+ for <email1@example.com>; Mon, 26 Nov 2012 22:11:45 +0000 (UTC)
7
+ Message-Id: <20121126221205.BC4F6421C5@mail.example.com>
8
+ Date: Mon, 26 Nov 2012 22:11:45 +0000 (UTC)
9
+ From: test@example.com
10
+ To: Email1 <email1@example.com>
11
+ Subject: Foo to email1
12
+
13
+ Foo
@@ -0,0 +1,13 @@
1
+ Return-Path: <test@example.com>
2
+ X-Original-To: email2@example.com
3
+ Delivered-To: email2@example.com
4
+ Received: from localhost (localhost [127.0.0.1])
5
+ by mail.example.com (Postfix) with SMTP id BC4F6421C5
6
+ for <email2@example.com>; Mon, 26 Nov 2012 22:11:45 +0000 (UTC)
7
+ Message-Id: <20121126221205.BC4F6421C5@mail.example.com>
8
+ Date: Mon, 26 Nov 2012 22:11:45 +0000 (UTC)
9
+ From: test@example.com
10
+ To: Email2 <email2@example.com>
11
+ Subject: Bar to email2
12
+
13
+ Bar
@@ -0,0 +1,11 @@
1
+ require "mailman-rails/version"
2
+ require "mailman"
3
+ require "mailman/rails"
4
+ require "mailman/rails/railtie"
5
+ require File.expand_path("../mailman", __FILE__)
6
+
7
+ module Mailman
8
+ module Rails
9
+ # Railtie added further down the tree
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Mailman
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/mailman.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Mailman
2
+ @@application = nil
3
+
4
+ def self.application
5
+ @@application ||= Mailman::Application.new do end # Avoid forcing Mailman to require a block
6
+ end
7
+
8
+ def self.configure(&block)
9
+ Mailman.config.instance_exec(&block)
10
+ end
11
+
12
+ def self.receive(&block)
13
+ self.application.instance_exec(&block)
14
+ end
15
+
16
+ def self.run!
17
+
18
+ # Under no circumstances should Mailman itself load the Rails enviroment!
19
+ Mailman.config.rails_root = false
20
+
21
+ self.application.run
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module Mailman
2
+ module Rails
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module Mailman
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ rake_tasks do
7
+ Dir[File.expand_path('../tasks/*.rake', __FILE__)].each { |f| puts f ; load f }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ namespace :mailman do
2
+
3
+ mailman_tasks = [:start, :stop, :restart, :status]
4
+
5
+ mailman_tasks.each do |task_name|
6
+
7
+ # Generate description
8
+ if task_name == :status
9
+ desc "Check the status of the Mailman service"
10
+ else
11
+ desc "#{task_name.to_s.camelize} the Mailman service"
12
+ end
13
+
14
+ task task_name do
15
+ Daemons.run_proc("mailman_daemon", :ARGV => [task_name.to_s]) do
16
+ Rake::Task["mailman"].invoke
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+
25
+ desc "Mailman service in the foreground"
26
+ task :mailman => :environment do
27
+
28
+ Mailman.config.logger = Logger.new("#{Rails.root}/log/mailman.#{Rails.env}.log")
29
+
30
+ Mailman.run!
31
+
32
+ end
33
+
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailman-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mailman-rails"
8
+ gem.version = Mailman::Rails::VERSION
9
+ gem.authors = ["John Cant"]
10
+ gem.email = ["a.johncant@gmail.com"]
11
+ gem.description = %q{Ease Mailman integration with Rails}
12
+ gem.summary = %q{Ease Mailman integration with Rails}
13
+ gem.homepage = "https://github.com/johncant/mailman-rails"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "mailman"
21
+ gem.add_dependency "rails"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "daemons"
24
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ # WARNING - Requires mailman version from GitHub to run the tests
4
+
5
+ describe Mailman do
6
+
7
+ def gem_root
8
+ File.expand_path('../../', __FILE__)
9
+ end
10
+
11
+ before do
12
+ `cp -r #{gem_root}/examples #{gem_root}/tmp/examples`
13
+ end
14
+
15
+ it "Should store one instance configurable from different places" do
16
+
17
+ # Imagine that these next two blocks are in separate Rails models
18
+ # This spec reports that only 1 spec has been executed, despite my best efforts. (See hackery below)
19
+ # It's not true though, if one of the "ghost" specs fails, you still notice.
20
+ spec = self
21
+
22
+ Mailman.configure do
23
+ self.maildir = "#{spec.gem_root}/tmp/examples/"
24
+ end
25
+
26
+ emails_parsed = 0
27
+
28
+ Mailman.receive do
29
+ to('email1@example') do
30
+ route = self
31
+ spec.instance_eval do
32
+ # Tried making sure that self refers to the spec
33
+ route.message.body.should match(/Foo/)
34
+ emails_parsed += 1
35
+ end
36
+ end
37
+ end
38
+
39
+ Mailman.receive do
40
+ to('email2@example') do
41
+ route = self
42
+ spec.instance_eval do
43
+ # Tried making sure that self refers to the spec
44
+ route.message.body.should spec.match(/Bar/)
45
+ emails_parsed += 1
46
+ end
47
+ end
48
+ end
49
+
50
+ Mailman.application.process_maildir # If this had already happened, the spec would fail
51
+
52
+ emails_parsed.should == 2
53
+
54
+ end
55
+
56
+ after do
57
+ `rm -r #{gem_root}/tmp/examples`
58
+ end
59
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'mailman-rails'
4
+
5
+ RSpec.configure do |config|
6
+ # Don't need to configure anything yet
7
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailman-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Cant
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mailman
16
+ requirement: &18860620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *18860620
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &18860200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *18860200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &18859740 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *18859740
47
+ - !ruby/object:Gem::Dependency
48
+ name: daemons
49
+ requirement: &18859280 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *18859280
58
+ description: Ease Mailman integration with Rails
59
+ email:
60
+ - a.johncant@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - examples/new/1353967927.V801I42421M758136.example
72
+ - examples/new/1353967928.V801I42421M758136.example
73
+ - lib/mailman-rails.rb
74
+ - lib/mailman-rails/version.rb
75
+ - lib/mailman.rb
76
+ - lib/mailman/rails.rb
77
+ - lib/mailman/rails/railtie.rb
78
+ - lib/mailman/rails/tasks/mailman.rake
79
+ - mailman-rails.gemspec
80
+ - spec/mailman_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: https://github.com/johncant/mailman-rails
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.15
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Ease Mailman integration with Rails
106
+ test_files:
107
+ - spec/mailman_spec.rb
108
+ - spec/spec_helper.rb