author | Mahlon E. Smith <mahlon@laika.com> |
Fri, 12 May 2017 16:17:41 -0700 | |
changeset 16 | e135ccae6783 |
parent 15 | a38e6916504c |
child 17 | 23c7f5c8ee39 |
permissions | -rw-r--r-- |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/ruby |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
2 |
# vim: set nosta noet ts=4 sw=4: |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
3 |
# |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
4 |
# A Ruby interface to a single Ezmlm-idx mailing list directory. |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
5 |
# |
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
6 |
# == Version |
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
7 |
# |
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
8 |
# $Id$ |
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
9 |
# |
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
10 |
#--- |
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
11 |
|
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
12 |
require 'pathname' |
15 | 13 |
require 'time' |
13 | 14 |
require 'etc' |
15 | 15 |
require 'ezmlm' unless defined?( Ezmlm ) |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
16 |
|
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
17 |
|
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
18 |
### A Ruby interface to an ezmlm-idx mailing list directory |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
19 |
### |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
20 |
class Ezmlm::List |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
21 |
|
13 | 22 |
# Valid subdirectories/sections for subscriptions. |
23 |
SUBSCRIPTION_DIRS = %w[ deny mod digest allow ] |
|
24 |
||
25 |
||
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
26 |
### Create a new Ezmlm::List object for the specified +listdir+, which should be |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
27 |
### an ezmlm-idx mailing list directory. |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
28 |
### |
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
29 |
def initialize( listdir ) |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
30 |
listdir = Pathname.new( listdir ) unless listdir.is_a?( Pathname ) |
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
31 |
@listdir = listdir |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
32 |
end |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
33 |
|
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
34 |
# The Pathname object for the list directory |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
35 |
attr_reader :listdir |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
36 |
|
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
37 |
|
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
38 |
### Return the configured name of the list (without the host) |
13 | 39 |
### |
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
40 |
def name |
13 | 41 |
@name = self.read( 'outlocal' ) unless @name |
42 |
return @name |
|
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
43 |
end |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
44 |
|
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
45 |
|
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
46 |
### Return the configured host of the list |
13 | 47 |
### |
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
48 |
def host |
13 | 49 |
@host = self.read( 'outhost' ) unless @host |
50 |
return @host |
|
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
51 |
end |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
52 |
|
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
53 |
|
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
54 |
### Return the configured address of the list (in list@host form) |
13 | 55 |
### |
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
56 |
def address |
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
57 |
return "%s@%s" % [ self.name, self.host ] |
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
58 |
end |
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
59 |
alias_method :fullname, :address |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
60 |
|
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
61 |
|
13 | 62 |
### Return the email address of the list's owner. |
63 |
### |
|
64 |
def owner |
|
65 |
owner = self.read( 'owner' ) |
|
66 |
return owner =~ /@/ ? owner : nil |
|
67 |
end |
|
68 |
||
69 |
||
14 | 70 |
### Returns +true+ if +address+ is a subscriber to this list. |
13 | 71 |
### |
14 | 72 |
def include?( addr, section: nil ) |
73 |
addr.downcase! |
|
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
74 |
file = self.subscription_dir( section ) + Ezmlm::Hash.subscriber( addr ) |
14 | 75 |
return false unless file.exist? |
76 |
return file.read.scan( /T([^\0]+)\0/ ).flatten.include?( addr ) |
|
13 | 77 |
end |
14 | 78 |
alias_method :is_subscriber?, :include? |
13 | 79 |
|
80 |
||
81 |
### Fetch a sorted Array of the email addresses for all of the list's |
|
82 |
### subscribers. |
|
83 |
### |
|
84 |
def subscribers |
|
85 |
return self.read_subscriber_dir |
|
86 |
end |
|
87 |
||
88 |
||
89 |
### Subscribe +addr+ to the list within +section+. |
|
90 |
### |
|
91 |
def subscribe( *addr, section: nil ) |
|
92 |
addr.each do |address| |
|
93 |
next unless address.index( '@' ) |
|
94 |
address.downcase! |
|
95 |
||
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
96 |
file = self.subscription_dir( section ) + Ezmlm::Hash.subscriber( address ) |
13 | 97 |
self.with_safety do |
98 |
if file.exist? |
|
99 |
addresses = file.read.scan( /T([^\0]+)\0/ ).flatten |
|
100 |
addresses << address |
|
101 |
file.open( 'w' ) do |f| |
|
102 |
f.print addresses.uniq.sort.map{|a| "T#{a}\0" }.join |
|
103 |
end |
|
104 |
||
105 |
else |
|
106 |
file.open( 'w' ) do |f| |
|
107 |
f.print "T%s\0" % [ address ] |
|
108 |
end |
|
109 |
end |
|
110 |
end |
|
111 |
end |
|
112 |
end |
|
14 | 113 |
alias_method :add_subscriber, :subscribe |
13 | 114 |
|
115 |
||
116 |
### Unsubscribe +addr+ from the list within +section+. |
|
117 |
### |
|
118 |
def unsubscribe( *addr, section: nil ) |
|
119 |
addr.each do |address| |
|
120 |
address.downcase! |
|
121 |
||
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
122 |
file = self.subscription_dir( section ) + Ezmlm::Hash.subscriber( address ) |
13 | 123 |
self.with_safety do |
124 |
next unless file.exist? |
|
125 |
addresses = file.read.scan( /T([^\0]+)\0/ ).flatten |
|
126 |
addresses = addresses - [ address ] |
|
127 |
||
128 |
if addresses.empty? |
|
129 |
file.unlink |
|
130 |
else |
|
131 |
file.open( 'w' ) do |f| |
|
132 |
f.print addresses.uniq.sort.map{|a| "T#{a}\0" }.join |
|
133 |
end |
|
134 |
end |
|
135 |
end |
|
136 |
end |
|
137 |
end |
|
14 | 138 |
alias_method :remove_subscriber, :unsubscribe |
139 |
||
140 |
||
141 |
### Returns an Array of email addresses of people responsible for |
|
142 |
### moderating subscription of a closed list. |
|
143 |
### |
|
144 |
def moderators |
|
145 |
return self.read_subscriber_dir( 'mod' ) |
|
146 |
end |
|
147 |
||
148 |
### Returns +true+ if +address+ is a moderator. |
|
149 |
### |
|
150 |
def is_moderator?( addr ) |
|
151 |
return self.include?( addr, section: 'mod' ) |
|
152 |
end |
|
153 |
||
154 |
### Subscribe +addr+ to the list as a Moderator. |
|
155 |
### |
|
156 |
def add_moderator( *addr ) |
|
157 |
return self.subscribe( *addr, section: 'mod' ) |
|
158 |
end |
|
159 |
||
160 |
### Remove +addr+ from the list as a Moderator. |
|
161 |
### |
|
162 |
def remove_moderator( *addr ) |
|
163 |
return self.unsubscribe( *addr, section: 'mod' ) |
|
164 |
end |
|
13 | 165 |
|
166 |
||
14 | 167 |
### Returns an Array of email addresses denied access |
168 |
### to the list. |
|
169 |
### |
|
170 |
def blacklisted |
|
171 |
return self.read_subscriber_dir( 'deny' ) |
|
172 |
end |
|
173 |
||
174 |
### Returns +true+ if +address+ is disallowed from participating. |
|
175 |
### |
|
176 |
def is_blacklisted?( addr ) |
|
177 |
return self.include?( addr, section: 'deny' ) |
|
178 |
end |
|
179 |
||
180 |
### Blacklist +addr+ from the list. |
|
181 |
### |
|
182 |
def add_blacklisted( *addr ) |
|
183 |
return self.subscribe( *addr, section: 'deny' ) |
|
184 |
end |
|
185 |
||
186 |
### Remove +addr+ from the blacklist. |
|
187 |
### |
|
188 |
def remove_blacklisted( *addr ) |
|
189 |
return self.unsubscribe( *addr, section: 'deny' ) |
|
190 |
end |
|
191 |
||
192 |
||
193 |
||
194 |
### Returns an Array of email addresses that act like |
|
195 |
### regular subscribers for user-post only lists. |
|
13 | 196 |
### |
14 | 197 |
def allowed |
198 |
return self.read_subscriber_dir( 'allow' ) |
|
199 |
end |
|
200 |
||
201 |
### Returns +true+ if +address+ is given the same benefits as a |
|
202 |
### regular subscriber for user-post only lists. |
|
203 |
### |
|
204 |
def is_allowed?( addr ) |
|
205 |
return self.include?( addr, section: 'allow' ) |
|
206 |
end |
|
207 |
||
208 |
### Add +addr+ to allow posting to user-post only lists, |
|
209 |
### when +addr+ isn't a subscriber. |
|
210 |
### |
|
211 |
def add_allowed( *addr ) |
|
212 |
return self.subscribe( *addr, section: 'allow' ) |
|
213 |
end |
|
214 |
||
215 |
### Remove +addr+ from the allowed list. |
|
216 |
### |
|
217 |
def remove_allowed( *addr ) |
|
218 |
return self.unsubscribe( *addr, section: 'allow' ) |
|
219 |
end |
|
220 |
||
221 |
||
222 |
### Returns +true+ if message threading is enabled. |
|
223 |
### |
|
224 |
def threaded? |
|
225 |
return ( self.listdir + 'threaded' ).exist? |
|
226 |
end |
|
227 |
||
228 |
### Disable or enable message threading. |
|
229 |
### |
|
230 |
### This automatically builds message indexes and thread |
|
231 |
### information on an incoming message. |
|
232 |
### |
|
233 |
def threaded=( enable=true ) |
|
234 |
if enable |
|
235 |
self.touch( 'threaded' ) |
|
236 |
else |
|
237 |
self.unlink( 'threaded' ) |
|
238 |
end |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
239 |
end |
15 | 240 |
alias_method :threaded, :threaded= |
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
241 |
|
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
242 |
|
14 | 243 |
### Returns +true+ if the list is configured to respond |
15 | 244 |
### to remote management requests. |
14 | 245 |
### |
246 |
def public? |
|
247 |
return ( self.listdir + 'public' ).exist? |
|
248 |
end |
|
249 |
||
250 |
### Disable or enable remote management requests. |
|
251 |
### |
|
252 |
def public=( enable=true ) |
|
253 |
if enable |
|
254 |
self.touch( 'public' ) |
|
255 |
else |
|
256 |
self.unlink( 'public' ) |
|
257 |
end |
|
258 |
end |
|
15 | 259 |
alias_method :public, :public= |
14 | 260 |
|
261 |
### Returns +true+ if the list is not configured to respond |
|
15 | 262 |
### to remote management requests. |
13 | 263 |
### |
14 | 264 |
def private? |
265 |
return ! self.public? |
|
266 |
end |
|
267 |
||
268 |
### Disable or enable remote management requests. |
|
269 |
### |
|
270 |
def private=( enable=false ) |
|
271 |
self.public = ! enable |
|
272 |
end |
|
15 | 273 |
alias_method :private, :private= |
14 | 274 |
|
275 |
||
276 |
### Returns +true+ if the list supports remote administration |
|
277 |
### subscribe/unsubscribe requests from moderators. |
|
278 |
### |
|
279 |
def remote_subscriptions? |
|
280 |
return ( self.listdir + 'remote' ).exist? |
|
281 |
end |
|
282 |
||
283 |
### Disable or enable remote subscription requests. |
|
284 |
### |
|
285 |
def remote_subscriptions=( enable=false ) |
|
286 |
if enable |
|
287 |
self.touch( 'remote' ) |
|
288 |
else |
|
289 |
self.unlink( 'remote' ) |
|
290 |
end |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
291 |
end |
15 | 292 |
alias_method :remote_subscriptions, :remote_subscriptions= |
5
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
293 |
|
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
294 |
|
14 | 295 |
### Returns +true+ if list subscription requests require moderator |
296 |
### approval. |
|
297 |
### |
|
298 |
def moderated_subscriptions? |
|
299 |
return ( self.listdir + 'modsub' ).exist? |
|
300 |
end |
|
301 |
||
302 |
### Disable or enable subscription moderation. |
|
303 |
### |
|
304 |
def moderated_subscriptions=( enable=false ) |
|
305 |
if enable |
|
306 |
self.touch( 'modsub' ) |
|
307 |
else |
|
308 |
self.unlink( 'modsub' ) |
|
309 |
end |
|
310 |
end |
|
15 | 311 |
alias_method :moderated_subscriptions, :moderated_subscriptions= |
14 | 312 |
|
313 |
### Returns +true+ if message moderation is enabled. |
|
314 |
### |
|
315 |
def moderated? |
|
316 |
return ( self.listdir + 'modpost' ).exist? |
|
317 |
end |
|
318 |
||
319 |
### Disable or enable message moderation. |
|
320 |
### |
|
15 | 321 |
### This has special meaning when combined with user_posts_only setting. |
14 | 322 |
### Lists act as unmoderated for subscribers, and posts from unknown |
323 |
### addresses go to moderation. |
|
13 | 324 |
### |
14 | 325 |
def moderated=( enable=false ) |
326 |
if enable |
|
327 |
self.touch( 'modpost' ) |
|
328 |
self.touch( 'noreturnposts' ) if self.user_posts_only? |
|
329 |
else |
|
330 |
self.unlink( 'modpost' ) |
|
331 |
self.unlink( 'noreturnposts' ) if self.user_posts_only? |
|
332 |
end |
|
333 |
end |
|
15 | 334 |
alias_method :moderated, :moderated= |
14 | 335 |
|
336 |
||
337 |
### Returns +true+ if posting is only allowed by moderators. |
|
338 |
### |
|
339 |
def moderator_posts_only? |
|
340 |
return ( self.listdir + 'modpostonly' ).exist? |
|
341 |
end |
|
342 |
||
343 |
### Disable or enable moderation only posts. |
|
344 |
### |
|
345 |
def moderator_posts_only=( enable=false ) |
|
346 |
if enable |
|
347 |
self.touch( 'modpostonly' ) |
|
348 |
else |
|
349 |
self.unlink( 'modpostonly' ) |
|
350 |
end |
|
351 |
end |
|
15 | 352 |
alias_method :moderator_posts_only, :moderator_posts_only= |
14 | 353 |
|
354 |
||
355 |
### Returns +true+ if posting is only allowed by subscribers. |
|
356 |
### |
|
357 |
def user_posts_only? |
|
358 |
return ( self.listdir + 'subpostonly' ).exist? |
|
359 |
end |
|
360 |
||
361 |
### Disable or enable user only posts. |
|
362 |
### This is easily defeated, moderated lists are preferred. |
|
363 |
### |
|
364 |
### This has special meaning for moderated lists. Lists act as |
|
365 |
### unmoderated for subscribers, and posts from unknown addresses |
|
366 |
### go to moderation. |
|
367 |
### |
|
368 |
def user_posts_only=( enable=false ) |
|
369 |
if enable |
|
370 |
self.touch( 'subpostonly' ) |
|
371 |
self.touch( 'noreturnposts' )if self.moderated? |
|
372 |
else |
|
373 |
self.unlink( 'subpostonly' ) |
|
374 |
self.unlink( 'noreturnposts' ) if self.moderated? |
|
375 |
end |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
376 |
end |
15 | 377 |
alias_method :user_posts_only, :user_posts_only= |
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
378 |
|
14 | 379 |
|
380 |
### Returns +true+ if message archival is enabled. |
|
381 |
### |
|
382 |
def archived? |
|
383 |
return ( self.listdir + 'archived' ).exist? || ( self.listdir + 'indexed' ).exist? |
|
384 |
end |
|
385 |
||
386 |
### Disable or enable message archiving (and indexing.) |
|
387 |
### |
|
388 |
def archive=( enable=true ) |
|
389 |
if enable |
|
390 |
self.touch( 'archived' ) |
|
391 |
self.touch( 'indexed' ) |
|
392 |
else |
|
393 |
self.unlink( 'archived' ) |
|
394 |
self.unlink( 'indexed' ) |
|
395 |
end |
|
396 |
end |
|
15 | 397 |
alias_method :archive, :archive= |
14 | 398 |
|
399 |
### Returns +true+ if the message archive is accessible only to |
|
400 |
### moderators. |
|
401 |
### |
|
402 |
def private_archive? |
|
403 |
return ( self.listdir + 'modgetonly' ).exist? |
|
404 |
end |
|
405 |
||
406 |
### Disable or enable private access to the archive. |
|
407 |
### |
|
408 |
def private_archive=( enable=true ) |
|
409 |
if enable |
|
410 |
self.touch( 'modgetonly' ) |
|
411 |
else |
|
412 |
self.unlink( 'modgetonly' ) |
|
413 |
end |
|
414 |
end |
|
15 | 415 |
alias_method :private_archive, :private_archive= |
14 | 416 |
|
417 |
### Returns +true+ if the message archive is accessible to anyone. |
|
418 |
### |
|
419 |
def public_archive? |
|
420 |
return ! self.private_archive? |
|
421 |
end |
|
422 |
||
15 | 423 |
### Disable or enable private access to the archive. |
424 |
### |
|
425 |
def public_archive=( enable=true ) |
|
426 |
self.private_archive = ! enable |
|
427 |
end |
|
428 |
alias_method :public_archive, :public_archive= |
|
429 |
||
14 | 430 |
### Returns +true+ if the message archive is accessible only to |
431 |
### list subscribers. |
|
432 |
### |
|
433 |
def guarded_archive? |
|
434 |
return ( self.listdir + 'subgetonly' ).exist? |
|
435 |
end |
|
436 |
||
437 |
### Disable or enable loimited access to the archive. |
|
438 |
### |
|
439 |
def guarded_archive=( enable=true ) |
|
440 |
if enable |
|
441 |
self.touch( 'subgetonly' ) |
|
442 |
else |
|
443 |
self.unlink( 'subgetonly' ) |
|
444 |
end |
|
445 |
end |
|
15 | 446 |
alias_method :guarded_archive, :guarded_archive= |
14 | 447 |
|
448 |
||
449 |
### Returns +true+ if message digests are enabled. |
|
13 | 450 |
### |
14 | 451 |
def digested? |
452 |
return ( self.listdir + 'digested' ).exist? |
|
453 |
end |
|
454 |
||
455 |
### Disable or enable message digesting. |
|
456 |
### |
|
457 |
def digest=( enable=true ) |
|
458 |
if enable |
|
459 |
self.touch( 'digested' ) |
|
460 |
else |
|
461 |
self.unlink( 'digested' ) |
|
462 |
end |
|
463 |
end |
|
15 | 464 |
alias_method :digest, :digest= |
14 | 465 |
|
466 |
### If the list is digestable, trigger the digest after this amount |
|
467 |
### of message body since the latest digest, in kbytes. |
|
468 |
### |
|
469 |
### See: ezmlm-tstdig(1) |
|
470 |
### |
|
471 |
def digest_kbytesize |
|
472 |
size = self.read( 'digsize' ).to_i |
|
473 |
return size.zero? ? 64 : size |
|
474 |
end |
|
475 |
||
476 |
### If the list is digestable, trigger the digest after this amount |
|
477 |
### of message body since the latest digest, in kbytes. |
|
478 |
### |
|
479 |
### See: ezmlm-tstdig(1) |
|
480 |
### |
|
481 |
def digest_kbytesize=( size=64 ) |
|
482 |
self.write( 'digsize' ) {|f| f.puts size.to_i } |
|
483 |
end |
|
484 |
||
485 |
### If the list is digestable, trigger the digest after this many |
|
486 |
### messages have accumulated since the latest digest. |
|
487 |
### |
|
488 |
### See: ezmlm-tstdig(1) |
|
489 |
### |
|
490 |
def digest_count |
|
491 |
count = self.read( 'digcount' ).to_i |
|
492 |
return count.zero? ? 30 : count |
|
493 |
end |
|
494 |
||
495 |
### If the list is digestable, trigger the digest after this many |
|
496 |
### messages have accumulated since the latest digest. |
|
497 |
### |
|
498 |
### See: ezmlm-tstdig(1) |
|
499 |
### |
|
500 |
def digest_count=( count=30 ) |
|
501 |
self.write( 'digcount' ) {|f| f.puts count.to_i } |
|
502 |
end |
|
503 |
||
504 |
### If the list is digestable, trigger the digest after this much |
|
505 |
### time has passed since the last digest, in hours. |
|
506 |
### |
|
507 |
### See: ezmlm-tstdig(1) |
|
508 |
### |
|
509 |
def digest_timeout |
|
510 |
hours = self.read( 'digtime' ).to_i |
|
511 |
return hours.zero? ? 48 : hours |
|
512 |
end |
|
513 |
||
514 |
### If the list is digestable, trigger the digest after this much |
|
515 |
### time has passed since the last digest, in hours. |
|
516 |
### |
|
517 |
### See: ezmlm-tstdig(1) |
|
518 |
### |
|
519 |
def digest_timeout=( hours=48 ) |
|
520 |
self.write( 'digtime' ) {|f| f.puts hours.to_i } |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
521 |
end |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
522 |
|
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
523 |
|
14 | 524 |
### Returns +true+ if the list requires subscriptions to be |
525 |
### confirmed. AKA "help" mode if disabled. |
|
526 |
### |
|
527 |
def confirm_subscriptions? |
|
528 |
return ! ( self.listdir + 'nosubconfirm' ).exist? |
|
529 |
end |
|
530 |
||
531 |
### Disable or enable subscription confirmation. |
|
532 |
### AKA "help" mode if disabled. |
|
533 |
### |
|
534 |
def confirm_subscriptions=( enable=true ) |
|
535 |
if enable |
|
536 |
self.unlink( 'nosubconfirm' ) |
|
537 |
else |
|
538 |
self.touch( 'nosubconfirm' ) |
|
539 |
end |
|
540 |
end |
|
15 | 541 |
alias_method :confirm_subscriptions, :confirm_subscriptions= |
14 | 542 |
|
543 |
### Returns +true+ if the list requires unsubscriptions to be |
|
544 |
### confirmed. AKA "jump" mode. |
|
545 |
### |
|
546 |
def confirm_unsubscriptions? |
|
547 |
return ! ( self.listdir + 'nounsubconfirm' ).exist? |
|
548 |
end |
|
549 |
||
550 |
### Disable or enable unsubscription confirmation. |
|
551 |
### AKA "jump" mode. |
|
552 |
### |
|
553 |
def confirm_unsubscriptions=( enable=true ) |
|
554 |
if enable |
|
555 |
self.unlink( 'nounsubconfirm' ) |
|
556 |
else |
|
557 |
self.touch( 'nounsubconfirm' ) |
|
558 |
end |
|
559 |
end |
|
15 | 560 |
alias_method :confirm_unsubscriptions, :confirm_unsubscriptions= |
14 | 561 |
|
562 |
||
563 |
### Returns +true+ if the list requires regular message postings |
|
564 |
### to be confirmed by the original sender. |
|
565 |
### |
|
566 |
def confirm_postings? |
|
567 |
return ( self.listdir + 'confirmpost' ).exist? |
|
568 |
end |
|
569 |
||
570 |
### Disable or enable message confirmation. |
|
571 |
### |
|
572 |
def confirm_postings=( enable=false ) |
|
573 |
if enable |
|
574 |
self.touch( 'confirmpost' ) |
|
575 |
else |
|
576 |
self.unlink( 'confirmpost' ) |
|
577 |
end |
|
578 |
end |
|
15 | 579 |
alias_method :confirm_postings, :confirm_postings= |
14 | 580 |
|
581 |
||
582 |
### Returns +true+ if the list allows moderators to |
|
583 |
### fetch a subscriber list remotely. |
|
584 |
### |
|
585 |
def allow_remote_listing? |
|
586 |
return ( self.listdir + 'modcanlist' ).exist? |
|
587 |
end |
|
588 |
||
589 |
### Disable or enable the ability for moderators to |
|
590 |
### remotely fetch a subscriber list. |
|
591 |
### |
|
592 |
def allow_remote_listing=( enable=false ) |
|
593 |
if enable |
|
594 |
self.touch( 'modcanlist' ) |
|
595 |
else |
|
596 |
self.unlink( 'modcanlist' ) |
|
597 |
end |
|
598 |
end |
|
15 | 599 |
alias_method :allow_remote_listing, :allow_remote_listing= |
14 | 600 |
|
601 |
||
602 |
### Returns +true+ if the list automatically manages |
|
603 |
### bouncing subscriber addresses. |
|
604 |
### |
|
605 |
def bounce_warnings? |
|
606 |
return ! ( self.listdir + 'nowarn' ).exist? |
|
607 |
end |
|
608 |
||
609 |
### Disable or enable automatic bounce probes and warnings. |
|
610 |
### |
|
611 |
def bounce_warnings=( enable=true ) |
|
612 |
if enable |
|
613 |
self.unlink( 'nowarn' ) |
|
614 |
else |
|
615 |
self.touch( 'nowarn' ) |
|
616 |
end |
|
617 |
end |
|
15 | 618 |
alias_method :bounce_warnings, :bounce_warnings= |
14 | 619 |
|
620 |
||
621 |
### Return the maximum message size, in bytes. Messages larger than |
|
622 |
### this size will be rejected. |
|
623 |
### |
|
624 |
### See: ezmlm-reject(1) |
|
625 |
### |
|
626 |
def maximum_message_size |
|
627 |
size = self.read( 'msgsize' ) |
|
628 |
return size ? size.split( ':' ).first.to_i : 0 |
|
629 |
end |
|
630 |
||
631 |
### Set the maximum message size, in bytes. Messages larger than |
|
15 | 632 |
### this size will be rejected. Defaults to 300kb. |
14 | 633 |
### |
634 |
### See: ezmlm-reject(1) |
|
635 |
### |
|
636 |
def maximum_message_size=( size=307200 ) |
|
637 |
if size.to_i.zero? |
|
638 |
self.unlink( 'msgsize' ) |
|
639 |
else |
|
640 |
self.write( 'msgsize' ) {|f| f.puts "#{size.to_i}:0" } |
|
641 |
end |
|
642 |
end |
|
643 |
||
644 |
||
15 | 645 |
|
14 | 646 |
### Return the number of messages in the list archive. |
647 |
### |
|
648 |
def message_count |
|
649 |
count = self.read( 'archnum' ) |
|
650 |
return count ? Integer( count ) : 0 |
|
651 |
end |
|
652 |
||
15 | 653 |
### Returns an individual message if archiving was enabled. |
654 |
### |
|
655 |
def message( message_id ) |
|
656 |
raise "Archiving is not enabled." unless self.archived? |
|
657 |
raise "Message archive is empty." if self.message_count.zero? |
|
658 |
return Ezmlm::List::Message.new( self, message_id ) |
|
659 |
end |
|
660 |
||
661 |
### Lazy load each message ID as a Ezmlm::List::Message, |
|
662 |
### yielding it to the block. |
|
13 | 663 |
### |
15 | 664 |
def each_message |
665 |
( 1 .. self.message_count ).each do |id| |
|
666 |
yield self.message( id ) |
|
667 |
end |
|
668 |
end |
|
669 |
||
670 |
||
671 |
### Return a Thread object for the given +thread_id+. |
|
672 |
### |
|
673 |
def thread( thread_id ) |
|
674 |
raise "Archiving is not enabled." unless self.archived? |
|
675 |
return Ezmlm::List::Thread.new( self, thread_id ) |
|
676 |
end |
|
677 |
||
678 |
||
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
679 |
### Return an Author object for the given +author_id+, which |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
680 |
### could also be an email address. |
15 | 681 |
### |
682 |
def author( author_id ) |
|
683 |
raise "Archiving is not enabled." unless self.archived? |
|
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
684 |
author_id = Ezmlm::Hash.address(author_id) if author_id.index( '@' ) |
15 | 685 |
return Ezmlm::List::Author.new( self, author_id ) |
686 |
end |
|
687 |
||
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
688 |
|
15 | 689 |
### Parse all thread indexes into a single array that can be used |
690 |
### as a lookup table. |
|
691 |
### |
|
692 |
### These are not expanded into objects, use #message, #thread, |
|
693 |
### and #author to do so. |
|
694 |
### |
|
695 |
def index |
|
696 |
raise "Archiving is not enabled." unless self.archived? |
|
697 |
archivedir = listdir + 'archive' |
|
698 |
||
699 |
idx = ( 0 .. self.message_count / 100 ).each_with_object( [] ) do |dir, acc| |
|
700 |
index = archivedir + dir.to_s + 'index' |
|
701 |
next unless index.exist? |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
702 |
|
15 | 703 |
index.each_line.lazy.slice_before( /^\d+:/ ).each do |message| |
704 |
match = message[0].match( /^(?<message_id>\d+): (?<thread_id>\w+)/ ) |
|
705 |
next unless match |
|
706 |
thread_id = match[ :thread_id ] |
|
707 |
||
708 |
match = message[1].match( /^(?<date>[^;]+);(?<author_id>\w+) / ) |
|
709 |
next unless match |
|
710 |
author_id = match[ :author_id ] |
|
711 |
date = match[ :date ] |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
712 |
|
15 | 713 |
metadata = { |
714 |
date: Time.parse( date ), |
|
715 |
thread: thread_id, |
|
716 |
author: author_id |
|
717 |
} |
|
718 |
acc << metadata |
|
719 |
end |
|
720 |
end |
|
721 |
||
722 |
return idx |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
723 |
end |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
724 |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
725 |
|
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
726 |
######### |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
727 |
protected |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
728 |
######### |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
729 |
|
13 | 730 |
### Just return the contents of the provided +file+, rooted |
731 |
### in the list directory. |
|
732 |
### |
|
733 |
def read( file ) |
|
734 |
file = self.listdir + file unless file.is_a?( Pathname ) |
|
735 |
return file.read.chomp |
|
736 |
rescue |
|
737 |
nil |
|
738 |
end |
|
739 |
||
740 |
||
14 | 741 |
### Overwrite +file+ safely, yielding the open filehandle to the |
742 |
### block. Set the new file to correct ownership and permissions. |
|
743 |
### |
|
744 |
def write( file, &block ) |
|
745 |
file = self.listdir + file unless file.is_a?( Pathname ) |
|
746 |
self.with_safety do |
|
747 |
file.open( 'w' ) do |f| |
|
748 |
yield( f ) |
|
749 |
end |
|
750 |
||
751 |
stat = self.listdir.stat |
|
752 |
file.chown( stat.uid, stat.gid ) |
|
753 |
file.chmod( 0600 ) |
|
754 |
end |
|
755 |
end |
|
756 |
||
757 |
||
758 |
### Simply create an empty file, safely. |
|
759 |
### |
|
760 |
def touch( file ) |
|
761 |
self.write( file ) {} |
|
762 |
end |
|
763 |
||
764 |
||
765 |
### Delete +file+ safely. |
|
766 |
### |
|
767 |
def unlink( file ) |
|
768 |
file = self.listdir + file unless file.is_a?( Pathname ) |
|
769 |
return unless file.exist? |
|
770 |
self.with_safety do |
|
771 |
file.unlink |
|
772 |
end |
|
773 |
end |
|
774 |
||
775 |
||
13 | 776 |
### Return a Pathname to a subscription directory. |
777 |
### |
|
778 |
def subscription_dir( section=nil ) |
|
779 |
if section |
|
14 | 780 |
unless SUBSCRIPTION_DIRS.include?( section ) |
781 |
raise "Invalid subscription dir: %s, must be one of: %s" % [ |
|
782 |
section, |
|
783 |
SUBSCRIPTION_DIRS.join( ', ' ) |
|
784 |
] |
|
785 |
end |
|
13 | 786 |
return self.listdir + section + 'subscribers' |
787 |
else |
|
788 |
return self.listdir + 'subscribers' |
|
789 |
end |
|
790 |
end |
|
791 |
||
792 |
||
14 | 793 |
### Read the hashed subscriber email addresses from the specified |
794 |
### +directory+ and return them in an Array. |
|
13 | 795 |
### |
796 |
def read_subscriber_dir( section=nil ) |
|
797 |
directory = self.subscription_dir( section ) |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
798 |
rval = [] |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
799 |
Pathname.glob( directory + '*' ) do |hashfile| |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
800 |
rval.push( hashfile.read.scan(/T([^\0]+)\0/) ) |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
801 |
end |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
802 |
|
13 | 803 |
return rval.flatten.sort |
804 |
end |
|
805 |
||
806 |
||
807 |
### Return a Pathname object for the list owner's home directory. |
|
808 |
### |
|
809 |
def homedir |
|
810 |
user = Etc.getpwuid( self.listdir.stat.uid ) |
|
811 |
return Pathname( user.dir ) |
|
812 |
end |
|
813 |
||
814 |
||
815 |
### Safely make modifications to a file within a list directory. |
|
816 |
### |
|
817 |
### Mail can come in at any time. Make changes within a list |
|
818 |
### atomic -- if an incoming message hits when a sticky |
|
819 |
### is set, it is deferred to the Qmail queue. |
|
820 |
### |
|
821 |
### - Set sticky bit on the list directory owner's homedir |
|
822 |
### - Make changes with the block |
|
823 |
### - Unset sticky (just back to what it was previously) |
|
824 |
### |
|
825 |
### All writes should be wrapped in this method. |
|
826 |
### |
|
827 |
def with_safety( &block ) |
|
828 |
home = self.homedir |
|
829 |
mode = home.stat.mode |
|
830 |
||
831 |
home.chmod( mode | 01000 ) # enable sticky |
|
832 |
yield |
|
833 |
||
834 |
ensure |
|
835 |
home.chmod( mode ) |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
836 |
end |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
837 |
|
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
838 |
end # class Ezmlm::List |
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
839 |