mailmanager 1.0.17 → 1.0.18

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.
data/Changelog CHANGED
@@ -1,4 +1,9 @@
1
- Current version is 1.0.17
1
+ Current version is 1.0.18
2
+
3
+ changes since 1.0.17
4
+ - added host_name getter/setter for lists
5
+ - cleaned & DRY'd up the lib class a bit
6
+ - cleaned up the lib spec helper method names
2
7
 
3
8
  changes since 1.0.16
4
9
  - removed rubygems-test since it doesn't work yet (says it can't find bundler)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailmanager (1.0.17)
4
+ mailmanager (1.0.18)
5
5
  json (~> 1.4.6)
6
6
  open4 (~> 1.0.1)
7
7
 
@@ -29,3 +29,9 @@ Feature: List metadata
29
29
  And I set its subject_prefix to "[Foo List] "
30
30
  When I ask for its subject_prefix
31
31
  Then I should get "[Foo List] "
32
+
33
+ Scenario: Getting & setting the host name
34
+ Given I have a list named "foo"
35
+ And I set its host_name to "groups.foo.org"
36
+ When I ask for its host_name
37
+ Then I should get "groups.foo.org"
@@ -59,153 +59,131 @@ module MailManager
59
59
  parse_output(cmd, out)
60
60
  end
61
61
 
62
+ def inject(list, message, queue=nil)
63
+ cmd = :inject
64
+ params = {:listname => list.name, :stdin => message}
65
+ params[:queue] = queue unless queue.nil?
66
+ command(cmd, params)
67
+ end
68
+
62
69
  def list_address(list)
63
- cmd = :withlist
64
- out = command(cmd, :name => list.name, :wlcmd => :getListAddress)
65
- parse_json_output(out)
70
+ withlist_command(:getListAddress, list)
66
71
  end
67
72
 
68
73
  def regular_members(list)
69
- cmd = :withlist
70
- out = command(cmd, :name => list.name, :wlcmd => :getRegularMemberKeys)
71
- parse_json_output(out)
74
+ withlist_command(:getRegularMemberKeys, list)
72
75
  end
73
76
 
74
77
  def digest_members(list)
75
- cmd = :withlist
76
- out = command(cmd, :name => list.name, :wlcmd => :getDigestMemberKeys)
77
- parse_json_output(out)
78
+ withlist_command(:getDigestMemberKeys, list)
78
79
  end
79
80
 
80
81
  def add_member(list, member)
81
- cmd = :withlist
82
- out = command(cmd, :name => list.name, :wlcmd => :AddMember, :arg => member)
83
- parse_json_output(out)
82
+ withlist_command(:AddMember, list, member)
84
83
  end
85
84
 
86
85
  def approved_add_member(list, member)
87
- cmd = :withlist
88
- out = command(cmd, :name => list.name, :wlcmd => :ApprovedAddMember,
89
- :arg => member)
90
- parse_json_output(out)
86
+ withlist_command(:ApprovedAddMember, list, member)
91
87
  end
92
88
 
93
89
  def delete_member(list, email)
94
- cmd = :withlist
95
- out = command(cmd, :name => list.name, :wlcmd => :DeleteMember,
96
- :arg => email)
97
- parse_json_output(out)
90
+ withlist_command(:DeleteMember, list, email)
98
91
  end
99
92
 
100
93
  def approved_delete_member(list, email)
101
- cmd = :withlist
102
- out = command(cmd, :name => list.name, :wlcmd => :ApprovedDeleteMember,
103
- :arg => email)
104
- parse_json_output(out)
94
+ withlist_command(:ApprovedDeleteMember, list, email)
105
95
  end
106
96
 
107
97
  def moderators(list)
108
- cmd = :withlist
109
- out = command(cmd, :name => list.name, :wlcmd => :moderator)
110
- parse_json_output(out)
98
+ withlist_command(:moderator, list)
111
99
  end
112
100
 
113
101
  def add_moderator(list, email)
114
102
  if moderators(list)['return'].include?(email)
115
103
  raise ModeratorAlreadyExistsError, "#{email} is already a moderator of #{list.name}"
116
104
  end
117
- cmd = :withlist
118
- out = command(cmd, :name => list.name, :wlcmd => 'moderator.append',
119
- :arg => email)
120
- parse_json_output(out)
105
+ withlist_command('moderator.append', list, email)
121
106
  end
122
107
 
123
108
  def delete_moderator(list, email)
124
109
  unless moderators(list)['return'].include?(email)
125
110
  raise ModeratorNotFoundError, "#{email} is not a moderator of #{list.name}"
126
111
  end
127
- cmd = :withlist
128
- out = command(cmd, :name => list.name, :wlcmd => 'moderator.remove',
129
- :arg => email)
130
- parse_json_output(out)
112
+ withlist_command('moderator.remove', list, email)
131
113
  end
132
114
 
133
- def inject(list, message, queue=nil)
134
- cmd = :inject
135
- params = {:listname => list.name, :stdin => message}
136
- params[:queue] = queue unless queue.nil?
137
- command(cmd, params)
138
- end
139
-
140
- # TODO: DRY this up!
141
-
142
115
  def web_page_url(list)
143
- cmd = :withlist
144
- out = command(cmd, :name => list.name, :wlcmd => 'web_page_url')
145
- parse_json_output(out)
116
+ withlist_command('web_page_url', list)
146
117
  end
147
118
 
148
119
  def request_email(list)
149
- cmd = :withlist
150
- out = command(cmd, :name => list.name, :wlcmd => :GetRequestEmail)
151
- parse_json_output(out)
120
+ withlist_command(:GetRequestEmail, list)
152
121
  end
153
122
 
154
123
  def description(list)
155
- cmd = :withlist
156
- out = command(cmd, :name => list.name, :wlcmd => :description)
157
- parse_json_output(out)
124
+ withlist_command(:description, list)
158
125
  end
159
126
 
160
- def subject_prefix(list)
161
- cmd = :withlist
162
- out = command(cmd, :name => list.name, :wlcmd => :subject_prefix)
163
- parse_json_output(out)
127
+ def set_description(list, desc)
128
+ withlist_command(:description, list, desc)
164
129
  end
165
130
 
166
- def set_description(list, desc)
167
- cmd = :withlist
168
- out = command(cmd, :name => list.name, :wlcmd => :description, :arg => desc)
169
- parse_json_output(out)
131
+ def subject_prefix(list)
132
+ withlist_command(:subject_prefix, list)
170
133
  end
171
134
 
172
135
  def set_subject_prefix(list, sp)
173
- cmd = :withlist
174
- out = command(cmd, :name => list.name, :wlcmd => :subject_prefix, :arg => sp)
136
+ withlist_command(:subject_prefix, list, sp)
137
+ end
138
+
139
+ def host_name(list)
140
+ withlist_command(:host_name, list)
141
+ end
142
+
143
+ def set_host_name(list, host_name)
144
+ withlist_command(:host_name, list, host_name)
145
+ end
146
+
147
+ private
148
+
149
+ def withlist_command(wlcmd, list, *args)
150
+ params = {:name => list.name, :wlcmd => wlcmd}
151
+ params[:arg] = args[0] unless args[0].nil?
152
+ out = command(:withlist, params)
175
153
  parse_json_output(out)
176
154
  end
177
155
 
178
- def command(cmd, opts = {})
156
+ def command(cmd, params = {})
179
157
  mailman_cmd = "#{mailmanager.root}/bin/#{cmd.to_s} "
180
- # delete opts as we handle them explicitly
158
+ # delete params as we handle them explicitly
181
159
  stdin = nil
182
- stdin = opts.delete(:stdin) if opts.respond_to?(:has_key?) && opts.has_key?(:stdin)
160
+ stdin = params.delete(:stdin) if params.respond_to?(:has_key?) && params.has_key?(:stdin)
183
161
  case cmd
184
162
  when :newlist
185
163
  mailman_cmd += "-q "
186
- raise ArgumentError, "Missing :name param" if opts[:name].nil?
187
- raise ArgumentError, "Missing :admin_email param" if opts[:admin_email].nil?
188
- raise ArgumentError, "Missing :admin_password param" if opts[:admin_password].nil?
164
+ raise ArgumentError, "Missing :name param" if params[:name].nil?
165
+ raise ArgumentError, "Missing :admin_email param" if params[:admin_email].nil?
166
+ raise ArgumentError, "Missing :admin_password param" if params[:admin_password].nil?
189
167
  mailman_cmd_suffix = [:name, :admin_email, :admin_password].map { |key|
190
- escape(opts.delete(key))
168
+ escape(params.delete(key))
191
169
  }.join(' ')
192
170
  mailman_cmd += "#{mailman_cmd_suffix} "
193
171
  when :rmlist
194
- raise ArgumentError, "Missing :name param" if opts[:name].nil?
195
- mailman_cmd += "#{escape(opts.delete(:name))} "
172
+ raise ArgumentError, "Missing :name param" if params[:name].nil?
173
+ mailman_cmd += "#{escape(params.delete(:name))} "
196
174
  when :withlist
197
- raise ArgumentError, "Missing :name param" if opts[:name].nil?
175
+ raise ArgumentError, "Missing :name param" if params[:name].nil?
198
176
  proxy_path = File.dirname(__FILE__)
199
177
  mailman_cmd = "PYTHONPATH=#{proxy_path} #{MailManager.python} #{mailman_cmd}"
200
- mailman_cmd += "-q -r listproxy.command #{escape(opts.delete(:name))} " +
201
- "#{opts.delete(:wlcmd)} "
202
- if !opts[:arg].nil? && opts[:arg].length > 0
203
- mailman_cmd += "#{escape(opts.delete(:arg))} "
178
+ mailman_cmd += "-q -r listproxy.command #{escape(params.delete(:name))} " +
179
+ "#{params.delete(:wlcmd)} "
180
+ if !params[:arg].nil? && params[:arg].length > 0
181
+ mailman_cmd += "#{escape(params.delete(:arg))} "
204
182
  end
205
183
  end
206
184
 
207
- # assume any leftover opts are POSIX-style args
208
- mailman_cmd += opts.keys.map { |k| "--#{k}=#{escape(opts[k])}" }.join(' ')
185
+ # assume any leftover params are POSIX-style args
186
+ mailman_cmd += params.keys.map { |k| "--#{k}=#{escape(params[k])}" }.join(' ')
209
187
  mailman_cmd += ' ' if mailman_cmd[-1,1] != ' '
210
188
  mailman_cmd += "2>&1"
211
189
  if MailManager.debug
@@ -158,6 +158,18 @@ EOF
158
158
  result['result'].to_sym
159
159
  end
160
160
 
161
+ # Returns the list's host name
162
+ def host_name
163
+ result = lib.host_name(self)
164
+ result['return']
165
+ end
166
+
167
+ # Sets the list's host name
168
+ def host_name=(host_name)
169
+ result = lib.set_host_name(self, host_name)
170
+ result['result'].to_sym
171
+ end
172
+
161
173
  private
162
174
 
163
175
  def add_member_using(method, email, name)
@@ -47,10 +47,10 @@ def unwindattrs(obj, attrname, *args):
47
47
  return unwindattrs(nextobj, nextattrname, *args)
48
48
 
49
49
  needs_userdesc = dict(AddMember=True, ApprovedAddMember=True)
50
- needs_save = dict(AddMember=True, ApprovedAddMember=True,
51
- DeleteMember=True, ApprovedDeleteMember=True,
52
- moderator_append=True, moderator_remove=True)
53
- needs_save_with_arg = dict(description=True, subject_prefix=True)
50
+ needs_save = dict(AddMember=True, ApprovedAddMember=True, DeleteMember=True,
51
+ ApprovedDeleteMember=True, moderator_append=True,
52
+ moderator_remove=True)
53
+ needs_save_with_arg = dict(description=True, subject_prefix=True, host_name=True)
54
54
 
55
55
  def command(mlist, cmd, *args):
56
56
  result = {}
@@ -1,3 +1,3 @@
1
1
  module MailManager
2
- VERSION = '1.0.17'
2
+ VERSION = '1.0.18'
3
3
  end
@@ -150,54 +150,54 @@ EOF
150
150
 
151
151
  describe "#regular_members" do
152
152
  it "should ask Mailman for the regular list members" do
153
- test_lib_method(:regular_members, :getRegularMemberKeys, regular_members)
153
+ test_mailman_cmd(:regular_members, :getRegularMemberKeys, regular_members)
154
154
  end
155
155
  end
156
156
 
157
157
  describe "#digest_members" do
158
158
  it "should ask Mailman for the digest list members" do
159
- test_lib_method(:digest_members, :getDigestMemberKeys, digest_members)
159
+ test_mailman_cmd(:digest_members, :getDigestMemberKeys, digest_members)
160
160
  end
161
161
  end
162
162
 
163
163
  describe "#add_member" do
164
164
  it "should ask Mailman to add the member to the list" do
165
165
  new_member = 'newb@dnc.org'
166
- test_lib_setter(:add_member, new_member)
166
+ test_method_setter(:add_member, new_member)
167
167
  end
168
168
  end
169
169
 
170
170
  describe "#approved_add_member" do
171
171
  it "should ask Mailman to add the member to the list" do
172
172
  new_member = 'newb@dnc.org'
173
- test_lib_setter(:approved_add_member, new_member)
173
+ test_method_setter(:approved_add_member, new_member)
174
174
  end
175
175
  end
176
176
 
177
177
  describe "#delete_member" do
178
178
  it "should ask Mailman to delete the member from the list" do
179
179
  former_member = 'oldie@ofa.org'
180
- test_lib_setter(:delete_member, former_member)
180
+ test_method_setter(:delete_member, former_member)
181
181
  end
182
182
  end
183
183
 
184
184
  describe "#approved_delete_member" do
185
185
  it "should ask Mailman to delete the member from the list" do
186
186
  former_member = 'oldie@ofa.org'
187
- test_lib_setter(:approved_delete_member, former_member)
187
+ test_method_setter(:approved_delete_member, former_member)
188
188
  end
189
189
  end
190
190
 
191
191
  describe "#moderators" do
192
192
  it "should ask Mailman for the list's moderators" do
193
- test_lib_method(:moderators, :moderator, ['phb@bigcorp.com', 'nhb@smallstartup.com'])
193
+ test_mailman_cmd(:moderators, :moderator, ['phb@bigcorp.com', 'nhb@smallstartup.com'])
194
194
  end
195
195
  end
196
196
 
197
197
  describe "#add_moderator" do
198
198
  it "should ask Mailman to add the moderator to the list" do
199
199
  subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => []})
200
- test_lib_method(:add_moderator, 'moderator.append', nil, 'foo@bar.com')
200
+ test_mailman_cmd(:add_moderator, 'moderator.append', nil, 'foo@bar.com')
201
201
  end
202
202
 
203
203
  it "should raise ModeratorAlreadyExistsError if they already a moderator" do
@@ -211,7 +211,7 @@ EOF
211
211
  describe "#delete_moderator" do
212
212
  it "should ask Mailman to delete the moderator from the list" do
213
213
  subject.should_receive(:moderators).with(list).and_return({'result' => 'success', 'return' => ['foo@bar.com']})
214
- test_lib_method(:delete_moderator, 'moderator.remove', nil, 'foo@bar.com')
214
+ test_mailman_cmd(:delete_moderator, 'moderator.remove', nil, 'foo@bar.com')
215
215
  end
216
216
 
217
217
  it "should raise ModeratorNotFoundError if they are not already a moderator" do
@@ -224,44 +224,60 @@ EOF
224
224
 
225
225
  describe "#web_page_url" do
226
226
  it "should ask Mailman for the list's web address" do
227
- test_lib_attr(:web_page_url, "http://bar.com/mailman/listinfo/foo")
227
+ test_attr_getter(:web_page_url, "http://bar.com/mailman/listinfo/foo")
228
228
  end
229
229
  end
230
230
 
231
231
  describe "#request_email" do
232
232
  it "should ask Mailman for the request email address" do
233
- test_lib_getter(:request_email, "foo-request@bar.com")
233
+ test_method_getter(:request_email, "foo-request@bar.com")
234
234
  end
235
235
  end
236
236
 
237
237
  describe "#description" do
238
238
  it "should ask Mailman for the list's description" do
239
- test_lib_attr(:description, "this is a mailing list")
239
+ test_attr_getter(:description, "this is a mailing list")
240
240
  end
241
241
  end
242
242
 
243
243
  describe "#subject_prefix" do
244
244
  it "should ask Mailman for the list's subject prefix" do
245
- test_lib_attr(:subject_prefix, "[Foo] ")
245
+ test_attr_getter(:subject_prefix, "[Foo] ")
246
+ end
247
+ end
248
+
249
+ describe "#host_name" do
250
+ it "should ask Mailman for the list's host name" do
251
+ test_attr_getter(:host_name, "groups.foo.org")
252
+ end
253
+ end
254
+
255
+ describe "#set_host_name" do
256
+ it "should tell Mailman to set the list's host name" do
257
+ test_attr_setter(:host_name, 'groups.foo.org')
246
258
  end
247
259
  end
248
260
  end
249
261
 
250
- def test_lib_getter(lib_method, return_value, *args)
262
+ def test_method_getter(lib_method, return_value, *args)
251
263
  cc_mailman_method = camel_case("get_#{lib_method.to_s}")
252
- test_lib_method(lib_method, cc_mailman_method, return_value, *args)
264
+ test_mailman_cmd(lib_method, cc_mailman_method, return_value, *args)
253
265
  end
254
266
 
255
- def test_lib_setter(lib_method, *args)
267
+ def test_method_setter(lib_method, *args)
256
268
  cc_mailman_method = camel_case(lib_method.to_s)
257
- test_lib_method(lib_method, cc_mailman_method, nil, *args)
269
+ test_mailman_cmd(lib_method, cc_mailman_method, nil, *args)
270
+ end
271
+
272
+ def test_attr_getter(attr, return_value)
273
+ test_mailman_cmd(attr, attr, return_value)
258
274
  end
259
275
 
260
- def test_lib_attr(lib_attr, return_value)
261
- test_lib_method(lib_attr, lib_attr, return_value)
276
+ def test_attr_setter(attr, *args)
277
+ test_mailman_cmd("set_#{attr}", attr, nil, *args)
262
278
  end
263
279
 
264
- def test_lib_method(lib_method, mailman_method, return_value=nil, *args)
280
+ def test_mailman_cmd(lib_method, mailman_method, return_value=nil, *args)
265
281
  if return_value.is_a?(Hash)
266
282
  result = return_value
267
283
  else
@@ -113,4 +113,24 @@ describe MailManager::List do
113
113
  subject.approved_delete_member('foo@bar.baz').should == :success
114
114
  end
115
115
  end
116
+
117
+ context "host_name accessors" do
118
+ let(:host_name) { 'groups.foo.org' }
119
+
120
+ describe "#host_name=" do
121
+ it "should tell lib to set the host_name" do
122
+ lib.should_receive(:set_host_name).with(subject, host_name).
123
+ and_return({'result' => 'success'})
124
+ subject.host_name = host_name
125
+ end
126
+ end
127
+
128
+ describe "#host_name" do
129
+ it "should ask lib for the host_name" do
130
+ lib.should_receive(:host_name).with(subject).
131
+ and_return({'result' => 'success', 'return' => host_name})
132
+ subject.host_name.should == host_name
133
+ end
134
+ end
135
+ end
116
136
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mailmanager
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.17
5
+ version: 1.0.18
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wes Morgan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-03 00:00:00 -05:00
13
+ date: 2011-02-10 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency