mailmanager 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.pyc
2
+ pkg/mailmanager-*.gem
3
+ html/*
4
+ doc/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ruby_string="ruby-1.9.2-p136"
4
+ gemset_name="mailmanager"
5
+
6
+ if rvm list strings | grep -q "${ruby_string}" ; then
7
+
8
+ # Load or create the specified environment
9
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
10
+ && -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
11
+ \. "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}"
12
+ else
13
+ rvm --create "${ruby_string}@${gemset_name}"
14
+ fi
15
+
16
+ # Ensure that Bundler is installed; install it if not
17
+ if ! command -v bundle ; then
18
+ echo "Installing bundler... "
19
+ gem install bundler
20
+ fi
21
+
22
+ # Run bundler but reduce excess noise
23
+ echo "Checking your bundle... "
24
+ bundle | grep -v 'Using' | grep -v 'complete' | sed '/^$/d'
25
+
26
+ else
27
+
28
+ # Notify user to install the requested interpreter before proceeding
29
+ echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into this directory."
30
+
31
+ fi
data/Changelog CHANGED
@@ -1,4 +1,9 @@
1
- Current version is 1.0.8
1
+ Current version is 1.0.11
2
+
3
+ changes since 1.0.8
4
+ - added more list metadata methods (see API docs)
5
+ - cleaned up test suite & added more tests
6
+ - cleaned up bundler and gemspec dependencies
2
7
 
3
8
  changes since 1.0.7
4
9
  - added documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mailmanager (1.0.11)
5
+ json (~> 1.4.6)
6
+ open4 (~> 1.0.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ ZenTest (4.4.2)
12
+ archive-tar-minitar (0.5.2)
13
+ columnize (0.3.2)
14
+ diff-lcs (1.1.2)
15
+ json (1.4.6)
16
+ linecache19 (0.5.11)
17
+ ruby_core_source (>= 0.1.4)
18
+ open4 (1.0.1)
19
+ rspec (2.4.0)
20
+ rspec-core (~> 2.4.0)
21
+ rspec-expectations (~> 2.4.0)
22
+ rspec-mocks (~> 2.4.0)
23
+ rspec-core (2.4.0)
24
+ rspec-expectations (2.4.0)
25
+ diff-lcs (~> 1.1.2)
26
+ rspec-mocks (2.4.0)
27
+ ruby-debug-base19 (0.11.24)
28
+ columnize (>= 0.3.1)
29
+ linecache19 (>= 0.5.11)
30
+ ruby_core_source (>= 0.1.4)
31
+ ruby-debug19 (0.11.6)
32
+ columnize (>= 0.3.1)
33
+ linecache19 (>= 0.5.11)
34
+ ruby-debug-base19 (>= 0.11.19)
35
+ ruby_core_source (0.1.4)
36
+ archive-tar-minitar (>= 0.5.2)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ ZenTest (~> 4.4.2)
43
+ mailmanager!
44
+ rspec (~> 2.4.0)
45
+ ruby-debug19
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'mailmanager/version'
3
+ require 'rake'
4
+ require 'rake/rdoctask'
5
+
6
+ desc "Build gem locally"
7
+ task :build do
8
+ system "gem build mailmanager.gemspec"
9
+ FileUtils.mkdir_p "pkg"
10
+ FileUtils.mv "mailmanager-#{MailManager::VERSION}.gem", "pkg"
11
+ end
12
+
13
+ desc "Install gem locally"
14
+ task :install => :build do
15
+ system "gem install pkg/mailmanager-#{MailManager::VERSION}.gem"
16
+ end
17
+
18
+ desc "Push gem to gems.dnc.org"
19
+ task :inabox => :build do
20
+ system "gem inabox pkg/mailmanager-#{MailManager::VERSION}.gem"
21
+ end
22
+
23
+ desc "Push gem to rubygems.org"
24
+ task :release => :build do
25
+ system "gem push pkg/mailmanager-#{MailManager::VERSION}.gem"
26
+ end
27
+
28
+ Rake::RDocTask.new do |rd|
29
+ rd.main = "lib/mailmanager.rb"
30
+ rd.rdoc_files.include("lib/**/*.rb")
31
+ end
@@ -83,7 +83,9 @@ module MailManager
83
83
  end
84
84
 
85
85
  def delete_moderator(list, email)
86
- raise "#{email} is not a moderator" unless moderators(list)['return'].include?(email)
86
+ unless moderators(list)['return'].include?(email)
87
+ return {'result' => 'not_a_moderator'}
88
+ end
87
89
  cmd = :withlist
88
90
  out = command(cmd, :name => list.name, :wlcmd => 'moderator.remove',
89
91
  :arg => email)
@@ -103,6 +105,18 @@ module MailManager
103
105
  parse_json_output(out)
104
106
  end
105
107
 
108
+ def request_email(list)
109
+ cmd = :withlist
110
+ out = command(cmd, :name => list.name, :wlcmd => :GetRequestEmail)
111
+ parse_json_output(out)
112
+ end
113
+
114
+ def description(list)
115
+ cmd = :withlist
116
+ out = command(cmd, :name => list.name, :wlcmd => :description)
117
+ parse_json_output(out)
118
+ end
119
+
106
120
  def command(cmd, opts = {})
107
121
  mailman_cmd = "#{mailmanager.root}/bin/#{cmd.to_s} "
108
122
  # delete opts as we handle them explicitly
@@ -157,12 +171,15 @@ module MailManager
157
171
  [output, process]
158
172
  end
159
173
 
160
- def escape(s)
161
- # no idea what this does, stole it from the ruby-git gem
174
+ def self.escape(s)
162
175
  escaped = s.to_s.gsub('\'', '\'\\\'\'')
163
176
  %Q{"#{escaped}"}
164
177
  end
165
178
 
179
+ def escape(s)
180
+ self.class.escape(s)
181
+ end
182
+
166
183
  def parse_output(mailman_cmd, output)
167
184
  case mailman_cmd
168
185
  when :newlist
@@ -84,14 +84,15 @@ module MailManager
84
84
  result['return']
85
85
  end
86
86
 
87
- # Adds a new moderator to the list
87
+ # Adds a new moderator to the list. Returns :already_a_moderator if the
88
+ # requested new moderator is already a moderator.
88
89
  def add_moderator(email)
89
90
  result = lib.add_moderator(self, email)
90
91
  result['result'].to_sym
91
92
  end
92
93
 
93
- # Deletes a moderator from the list. Will raise an exception if the
94
- # moderator doesn't exist yet.
94
+ # Deletes a moderator from the list. Returns :not_a_moderator if the
95
+ # requested deletion isn't a moderator.
95
96
  def delete_moderator(email)
96
97
  result = lib.delete_moderator(self, email)
97
98
  result['result'].to_sym
@@ -117,6 +118,16 @@ EOF
117
118
  "#{root}listinfo/#{name}"
118
119
  end
119
120
 
121
+ def request_email
122
+ result = lib.request_email(self)
123
+ result['return']
124
+ end
125
+
126
+ def description
127
+ result = lib.description(self)
128
+ result['return']
129
+ end
130
+
120
131
  private
121
132
 
122
133
  def add_member_using(method, email, name)
@@ -1,3 +1,3 @@
1
1
  module MailManager
2
- VERSION = '1.0.10'
2
+ VERSION = '1.0.11'
3
3
  end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'mailmanager/version'
6
+
7
+ spec = Gem::Specification.new do |s|
8
+ s.name = 'mailmanager'
9
+ s.version = MailManager::VERSION
10
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
11
+ s.summary = "GNU Mailman wrapper for Ruby"
12
+ s.description = %{Ruby wrapper library for GNU Mailman's admin functions}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files spec`.split("\n")
15
+ s.require_paths = ['lib']
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = [
18
+ "README.rdoc"
19
+ ]
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.authors = ["Wes Morgan"]
22
+ s.email = "MorganW@dnc.org"
23
+ s.homepage = "http://github.com/dnclabs/mailmanager"
24
+ s.add_runtime_dependency('json', '~>1.4.6')
25
+ s.add_runtime_dependency('open4', '~>1.0.1')
26
+ s.add_development_dependency('rspec', '~>2.4.0')
27
+ s.add_development_dependency('ZenTest', '~>4.4.2')
28
+ s.add_development_dependency('ruby-debug19')
29
+ end
@@ -92,69 +92,135 @@ EOF
92
92
  let(:digest_members) { ['them@that.net'] }
93
93
 
94
94
  let(:cmd) { "PYTHONPATH=#{File.expand_path('lib/mailmanager')} " +
95
+ "/usr/bin/env python " +
95
96
  "#{fake_root}/bin/withlist -q -r listproxy.command \"foo\" " }
96
97
 
97
98
  describe "#regular_members" do
98
99
  it "should ask Mailman for the regular list members" do
99
- subject.should_receive(:run_command).
100
- with(cmd+"getRegularMemberKeys 2>&1", nil).
101
- and_return([JSON.generate(regular_members),process])
102
- subject.regular_members(list).should == regular_members
100
+ test_lib_method(:regular_members, :getRegularMemberKeys, regular_members)
103
101
  end
104
102
  end
105
103
 
106
104
  describe "#digest_members" do
107
105
  it "should ask Mailman for the digest list members" do
108
- subject.should_receive(:run_command).
109
- with(cmd+"getDigestMemberKeys 2>&1", nil).
110
- and_return([JSON.generate(digest_members),process])
111
- subject.digest_members(list).should == digest_members
106
+ test_lib_method(:digest_members, :getDigestMemberKeys, digest_members)
112
107
  end
113
108
  end
114
109
 
115
110
  describe "#add_member" do
116
111
  it "should ask Mailman to add the member to the list" do
117
112
  new_member = 'newb@dnc.org'
118
- result = {"result" => "pending_confirmation"}
119
- subject.should_receive(:run_command).
120
- with(cmd+"AddMember \"#{new_member}\" 2>&1", nil).
121
- and_return([JSON.generate(result),process])
122
- subject.add_member(list, new_member).should == result
113
+ test_lib_setter(:add_member, new_member)
123
114
  end
124
115
  end
125
116
 
126
117
  describe "#approved_add_member" do
127
118
  it "should ask Mailman to add the member to the list" do
128
119
  new_member = 'newb@dnc.org'
129
- result = {"result" => "success"}
130
- subject.should_receive(:run_command).
131
- with(cmd+"ApprovedAddMember \"#{new_member}\" 2>&1", nil).
132
- and_return([JSON.generate(result),process])
133
- subject.approved_add_member(list, new_member).should == result
120
+ test_lib_setter(:approved_add_member, new_member)
134
121
  end
135
122
  end
136
123
 
137
124
  describe "#delete_member" do
138
125
  it "should ask Mailman to delete the member from the list" do
139
126
  former_member = 'oldie@ofa.org'
140
- result = {"result" => "success"}
141
- subject.should_receive(:run_command).
142
- with(cmd+"DeleteMember \"#{former_member}\" 2>&1", nil).
143
- and_return([JSON.generate(result),process])
144
- subject.delete_member(list, former_member).should == result
127
+ test_lib_setter(:delete_member, former_member)
145
128
  end
146
129
  end
147
130
 
148
131
  describe "#approved_delete_member" do
149
132
  it "should ask Mailman to delete the member from the list" do
150
133
  former_member = 'oldie@ofa.org'
151
- result = {"result" => "success"}
152
- subject.should_receive(:run_command).
153
- with(cmd+"ApprovedDeleteMember \"#{former_member}\" 2>&1", nil).
154
- and_return([JSON.generate(result),process])
155
- subject.approved_delete_member(list, former_member).should == result
134
+ test_lib_setter(:approved_delete_member, former_member)
135
+ end
136
+ end
137
+
138
+ describe "#moderators" do
139
+ it "should ask Mailman for the list's moderators" do
140
+ test_lib_method(:moderators, :moderator, ['phb@bigcorp.com', 'nhb@smallstartup.com'])
141
+ end
142
+ end
143
+
144
+ describe "#add_moderator" do
145
+ it "should ask Mailman to add the moderator to the list" do
146
+ subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => []})
147
+ test_lib_method(:add_moderator, 'moderator.append', nil, 'foo@bar.com')
148
+ end
149
+
150
+ it "should return 'already_a_moderator' if they already a moderator" do
151
+ result = {'result' => 'already_a_moderator'}
152
+ subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => ['foo@bar.com']})
153
+ subject.add_moderator(list, 'foo@bar.com').should == result
154
+ end
155
+ end
156
+
157
+ describe "#delete_moderator" do
158
+ it "should ask Mailman to delete the moderator from the list" do
159
+ subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => ['foo@bar.com']})
160
+ test_lib_method(:delete_moderator, 'moderator.remove', nil, 'foo@bar.com')
161
+ end
162
+
163
+ it "should return 'not_a_moderator' if they are not already a moderator" do
164
+ result = {'result' => 'not_a_moderator'}
165
+ subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => ['other@bar.com']})
166
+ subject.delete_moderator(list, 'foo@bar.com').should == result
167
+ end
168
+ end
169
+
170
+ describe "#web_page_url" do
171
+ it "should ask Mailman for the list's web address" do
172
+ test_lib_attr(:web_page_url, "http://bar.com/mailman/listinfo/foo")
173
+ end
174
+ end
175
+
176
+ describe "#request_email" do
177
+ it "should ask Mailman for the request email address" do
178
+ test_lib_getter(:request_email, "foo-request@bar.com")
156
179
  end
157
180
  end
181
+
182
+ describe "#description" do
183
+ it "should ask Mailman for the list's description" do
184
+ test_lib_attr(:description, "this is a mailing list")
185
+ end
186
+ end
187
+ end
188
+
189
+ def test_lib_getter(lib_method, return_value, *args)
190
+ cc_mailman_method = camel_case("get_#{lib_method.to_s}")
191
+ test_lib_method(lib_method, cc_mailman_method, return_value, *args)
192
+ end
193
+
194
+ def test_lib_setter(lib_method, *args)
195
+ cc_mailman_method = camel_case(lib_method.to_s)
196
+ test_lib_method(lib_method, cc_mailman_method, nil, *args)
197
+ end
198
+
199
+ def test_lib_attr(lib_attr, return_value)
200
+ test_lib_method(lib_attr, lib_attr, return_value)
201
+ end
202
+
203
+ def test_lib_method(lib_method, mailman_method, return_value=nil, *args)
204
+ if return_value.is_a?(Hash)
205
+ result = return_value
206
+ else
207
+ result = {"result" => "success"}
208
+ result["return"] = return_value unless return_value.nil?
209
+ end
210
+ subject.should_receive(:run_command).
211
+ with(cmd+"#{mailman_method.to_s} #{cmd_args(*args)}2>&1", nil).
212
+ and_return([JSON.generate(result),process])
213
+ subject.send(lib_method, list, *args).should == result
158
214
  end
159
215
 
216
+ def camel_case(s)
217
+ s.gsub(/^[a-z]|[\s_]+[a-z]/) { |a| a.upcase }.gsub(/[\s_]/, '')
218
+ end
219
+
220
+ def cmd_args(*args)
221
+ arg_str = args.map { |a|
222
+ MailManager::Lib::escape(a)
223
+ }.join(' ')
224
+ arg_str += ' ' if arg_str.length > 0
225
+ end
160
226
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 10
9
- version: 1.0.10
8
+ - 11
9
+ version: 1.0.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wes Morgan
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-21 00:00:00 -05:00
17
+ date: 2011-01-25 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -47,34 +47,84 @@ dependencies:
47
47
  version: 1.0.1
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 2
60
+ - 4
61
+ - 0
62
+ version: 2.4.0
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: ZenTest
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 4
75
+ - 4
76
+ - 2
77
+ version: 4.4.2
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: ruby-debug19
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id005
50
93
  description: Ruby wrapper library for GNU Mailman's admin functions
51
94
  email: MorganW@dnc.org
52
95
  executables: []
53
96
 
54
97
  extensions: []
55
98
 
56
- extra_rdoc_files: []
57
-
99
+ extra_rdoc_files:
100
+ - README.rdoc
58
101
  files:
102
+ - .gitignore
103
+ - .rspec
104
+ - .rvmrc
105
+ - Changelog
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE
109
+ - README.rdoc
110
+ - Rakefile
111
+ - lib/mailmanager.rb
59
112
  - lib/mailmanager/lib.rb
60
113
  - lib/mailmanager/list.rb
61
- - lib/mailmanager/version.rb
62
- - lib/mailmanager.rb
63
114
  - lib/mailmanager/listproxy.py
115
+ - lib/mailmanager/version.rb
116
+ - mailmanager.gemspec
64
117
  - spec/lib/mailmanager/lib_spec.rb
65
118
  - spec/lib/mailmanager/list_spec.rb
66
119
  - spec/lib/mailmanager_spec.rb
67
120
  - spec/spec_helper.rb
68
- - Changelog
69
- - LICENSE
70
- - README.rdoc
71
121
  has_rdoc: true
72
122
  homepage: http://github.com/dnclabs/mailmanager
73
123
  licenses: []
74
124
 
75
125
  post_install_message:
76
- rdoc_options: []
77
-
126
+ rdoc_options:
127
+ - --charset=UTF-8
78
128
  require_paths:
79
129
  - lib
80
130
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -100,5 +150,8 @@ rubygems_version: 1.3.7
100
150
  signing_key:
101
151
  specification_version: 3
102
152
  summary: GNU Mailman wrapper for Ruby
103
- test_files: []
104
-
153
+ test_files:
154
+ - spec/lib/mailmanager/lib_spec.rb
155
+ - spec/lib/mailmanager/list_spec.rb
156
+ - spec/lib/mailmanager_spec.rb
157
+ - spec/spec_helper.rb