author | Mahlon E. Smith <mahlon@laika.com> |
Tue, 16 May 2017 15:57:53 -0700 | |
changeset 21 | 1ebc33d48c85 |
parent 20 | 9d59d30685cb |
child 24 | f8873b391f3d |
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: |
17 | 3 |
|
4 |
||
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
5 |
require 'pathname' |
15 | 6 |
require 'time' |
13 | 7 |
require 'etc' |
15 | 8 |
require 'ezmlm' unless defined?( Ezmlm ) |
1
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 |
|
20
9d59d30685cb
Fixes for documentation and test directories that didn't make it into the repo.
Mahlon E. Smith <mahlon@laika.com>
parents:
17
diff
changeset
|
11 |
# A Ruby interface to a single Ezmlm-idx mailing list directory. |
9d59d30685cb
Fixes for documentation and test directories that didn't make it into the repo.
Mahlon E. Smith <mahlon@laika.com>
parents:
17
diff
changeset
|
12 |
# |
9d59d30685cb
Fixes for documentation and test directories that didn't make it into the repo.
Mahlon E. Smith <mahlon@laika.com>
parents:
17
diff
changeset
|
13 |
# list = Ezmlm::List.new( '/path/to/listdir' ) |
9d59d30685cb
Fixes for documentation and test directories that didn't make it into the repo.
Mahlon E. Smith <mahlon@laika.com>
parents:
17
diff
changeset
|
14 |
# |
9d59d30685cb
Fixes for documentation and test directories that didn't make it into the repo.
Mahlon E. Smith <mahlon@laika.com>
parents:
17
diff
changeset
|
15 |
#--- |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
16 |
class Ezmlm::List |
20
9d59d30685cb
Fixes for documentation and test directories that didn't make it into the repo.
Mahlon E. Smith <mahlon@laika.com>
parents:
17
diff
changeset
|
17 |
# $Id$ |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
18 |
|
13 | 19 |
# Valid subdirectories/sections for subscriptions. |
20 |
SUBSCRIPTION_DIRS = %w[ deny mod digest allow ] |
|
21 |
||
22 |
||
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
23 |
### 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
|
24 |
### 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
|
25 |
### |
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
26 |
def initialize( listdir ) |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
27 |
listdir = Pathname.new( listdir ) unless listdir.is_a?( Pathname ) |
17 | 28 |
unless listdir.directory? && ( listdir + 'mailinglist' ).exist? |
29 |
raise ArgumentError, "%p doesn't appear to be an ezmlm-idx list." % [ listdir.to_s ] |
|
30 |
end |
|
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 the list is configured to respond |
|
15 | 223 |
### to remote management requests. |
14 | 224 |
### |
225 |
def public? |
|
226 |
return ( self.listdir + 'public' ).exist? |
|
227 |
end |
|
228 |
||
229 |
### Disable or enable remote management requests. |
|
230 |
### |
|
231 |
def public=( enable=true ) |
|
232 |
if enable |
|
233 |
self.touch( 'public' ) |
|
234 |
else |
|
235 |
self.unlink( 'public' ) |
|
236 |
end |
|
237 |
end |
|
15 | 238 |
alias_method :public, :public= |
14 | 239 |
|
240 |
### Returns +true+ if the list is not configured to respond |
|
15 | 241 |
### to remote management requests. |
13 | 242 |
### |
14 | 243 |
def private? |
244 |
return ! self.public? |
|
245 |
end |
|
246 |
||
247 |
### Disable or enable remote management requests. |
|
248 |
### |
|
249 |
def private=( enable=false ) |
|
250 |
self.public = ! enable |
|
251 |
end |
|
15 | 252 |
alias_method :private, :private= |
14 | 253 |
|
254 |
||
255 |
### Returns +true+ if the list supports remote administration |
|
256 |
### subscribe/unsubscribe requests from moderators. |
|
257 |
### |
|
258 |
def remote_subscriptions? |
|
259 |
return ( self.listdir + 'remote' ).exist? |
|
260 |
end |
|
261 |
||
262 |
### Disable or enable remote subscription requests. |
|
263 |
### |
|
264 |
def remote_subscriptions=( enable=false ) |
|
265 |
if enable |
|
266 |
self.touch( 'remote' ) |
|
267 |
else |
|
268 |
self.unlink( 'remote' ) |
|
269 |
end |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
270 |
end |
15 | 271 |
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
|
272 |
|
804e1c2b9a40
* Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents:
4
diff
changeset
|
273 |
|
14 | 274 |
### Returns +true+ if list subscription requests require moderator |
275 |
### approval. |
|
276 |
### |
|
277 |
def moderated_subscriptions? |
|
278 |
return ( self.listdir + 'modsub' ).exist? |
|
279 |
end |
|
280 |
||
281 |
### Disable or enable subscription moderation. |
|
282 |
### |
|
283 |
def moderated_subscriptions=( enable=false ) |
|
284 |
if enable |
|
285 |
self.touch( 'modsub' ) |
|
286 |
else |
|
287 |
self.unlink( 'modsub' ) |
|
288 |
end |
|
289 |
end |
|
15 | 290 |
alias_method :moderated_subscriptions, :moderated_subscriptions= |
14 | 291 |
|
292 |
### Returns +true+ if message moderation is enabled. |
|
293 |
### |
|
294 |
def moderated? |
|
295 |
return ( self.listdir + 'modpost' ).exist? |
|
296 |
end |
|
297 |
||
298 |
### Disable or enable message moderation. |
|
299 |
### |
|
15 | 300 |
### This has special meaning when combined with user_posts_only setting. |
14 | 301 |
### Lists act as unmoderated for subscribers, and posts from unknown |
302 |
### addresses go to moderation. |
|
13 | 303 |
### |
14 | 304 |
def moderated=( enable=false ) |
305 |
if enable |
|
306 |
self.touch( 'modpost' ) |
|
307 |
self.touch( 'noreturnposts' ) if self.user_posts_only? |
|
308 |
else |
|
309 |
self.unlink( 'modpost' ) |
|
310 |
self.unlink( 'noreturnposts' ) if self.user_posts_only? |
|
311 |
end |
|
312 |
end |
|
15 | 313 |
alias_method :moderated, :moderated= |
14 | 314 |
|
315 |
||
316 |
### Returns +true+ if posting is only allowed by moderators. |
|
317 |
### |
|
318 |
def moderator_posts_only? |
|
319 |
return ( self.listdir + 'modpostonly' ).exist? |
|
320 |
end |
|
321 |
||
322 |
### Disable or enable moderation only posts. |
|
323 |
### |
|
324 |
def moderator_posts_only=( enable=false ) |
|
325 |
if enable |
|
326 |
self.touch( 'modpostonly' ) |
|
327 |
else |
|
328 |
self.unlink( 'modpostonly' ) |
|
329 |
end |
|
330 |
end |
|
15 | 331 |
alias_method :moderator_posts_only, :moderator_posts_only= |
14 | 332 |
|
333 |
||
334 |
### Returns +true+ if posting is only allowed by subscribers. |
|
335 |
### |
|
336 |
def user_posts_only? |
|
337 |
return ( self.listdir + 'subpostonly' ).exist? |
|
338 |
end |
|
339 |
||
340 |
### Disable or enable user only posts. |
|
341 |
### This is easily defeated, moderated lists are preferred. |
|
342 |
### |
|
343 |
### This has special meaning for moderated lists. Lists act as |
|
344 |
### unmoderated for subscribers, and posts from unknown addresses |
|
345 |
### go to moderation. |
|
346 |
### |
|
347 |
def user_posts_only=( enable=false ) |
|
348 |
if enable |
|
349 |
self.touch( 'subpostonly' ) |
|
350 |
self.touch( 'noreturnposts' )if self.moderated? |
|
351 |
else |
|
352 |
self.unlink( 'subpostonly' ) |
|
353 |
self.unlink( 'noreturnposts' ) if self.moderated? |
|
354 |
end |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
355 |
end |
15 | 356 |
alias_method :user_posts_only, :user_posts_only= |
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
357 |
|
14 | 358 |
|
359 |
### Returns +true+ if message archival is enabled. |
|
360 |
### |
|
361 |
def archived? |
|
17 | 362 |
test = %w[ archived indexed threaded ].each_with_object( [] ) do |f, acc| |
363 |
acc << self.listdir + f |
|
364 |
end |
|
365 |
||
366 |
return test.all?( &:exist? ) |
|
14 | 367 |
end |
368 |
||
17 | 369 |
### Disable or enable message archiving (and indexing/threading.) |
14 | 370 |
### |
17 | 371 |
def archived=( enable=true ) |
14 | 372 |
if enable |
17 | 373 |
self.touch( 'archived', 'indexed', 'threaded' ) |
14 | 374 |
else |
17 | 375 |
self.unlink( 'archived', 'indexed', 'threaded' ) |
14 | 376 |
end |
377 |
end |
|
17 | 378 |
alias_method :archived, :archived= |
14 | 379 |
|
380 |
### Returns +true+ if the message archive is accessible only to |
|
381 |
### moderators. |
|
382 |
### |
|
383 |
def private_archive? |
|
384 |
return ( self.listdir + 'modgetonly' ).exist? |
|
385 |
end |
|
386 |
||
387 |
### Disable or enable private access to the archive. |
|
388 |
### |
|
389 |
def private_archive=( enable=true ) |
|
390 |
if enable |
|
391 |
self.touch( 'modgetonly' ) |
|
392 |
else |
|
393 |
self.unlink( 'modgetonly' ) |
|
394 |
end |
|
395 |
end |
|
15 | 396 |
alias_method :private_archive, :private_archive= |
14 | 397 |
|
398 |
### Returns +true+ if the message archive is accessible to anyone. |
|
399 |
### |
|
400 |
def public_archive? |
|
401 |
return ! self.private_archive? |
|
402 |
end |
|
403 |
||
15 | 404 |
### Disable or enable private access to the archive. |
405 |
### |
|
406 |
def public_archive=( enable=true ) |
|
407 |
self.private_archive = ! enable |
|
408 |
end |
|
409 |
alias_method :public_archive, :public_archive= |
|
410 |
||
14 | 411 |
### Returns +true+ if the message archive is accessible only to |
412 |
### list subscribers. |
|
413 |
### |
|
414 |
def guarded_archive? |
|
415 |
return ( self.listdir + 'subgetonly' ).exist? |
|
416 |
end |
|
417 |
||
418 |
### Disable or enable loimited access to the archive. |
|
419 |
### |
|
420 |
def guarded_archive=( enable=true ) |
|
421 |
if enable |
|
422 |
self.touch( 'subgetonly' ) |
|
423 |
else |
|
424 |
self.unlink( 'subgetonly' ) |
|
425 |
end |
|
426 |
end |
|
15 | 427 |
alias_method :guarded_archive, :guarded_archive= |
14 | 428 |
|
429 |
||
430 |
### Returns +true+ if message digests are enabled. |
|
13 | 431 |
### |
14 | 432 |
def digested? |
433 |
return ( self.listdir + 'digested' ).exist? |
|
434 |
end |
|
435 |
||
436 |
### Disable or enable message digesting. |
|
437 |
### |
|
438 |
def digest=( enable=true ) |
|
439 |
if enable |
|
440 |
self.touch( 'digested' ) |
|
441 |
else |
|
442 |
self.unlink( 'digested' ) |
|
443 |
end |
|
444 |
end |
|
15 | 445 |
alias_method :digest, :digest= |
14 | 446 |
|
447 |
### If the list is digestable, trigger the digest after this amount |
|
448 |
### of message body since the latest digest, in kbytes. |
|
449 |
### |
|
450 |
### See: ezmlm-tstdig(1) |
|
451 |
### |
|
452 |
def digest_kbytesize |
|
453 |
size = self.read( 'digsize' ).to_i |
|
454 |
return size.zero? ? 64 : size |
|
455 |
end |
|
456 |
||
457 |
### If the list is digestable, trigger the digest after this amount |
|
458 |
### of message body since the latest digest, in kbytes. |
|
459 |
### |
|
460 |
### See: ezmlm-tstdig(1) |
|
461 |
### |
|
462 |
def digest_kbytesize=( size=64 ) |
|
463 |
self.write( 'digsize' ) {|f| f.puts size.to_i } |
|
464 |
end |
|
465 |
||
466 |
### If the list is digestable, trigger the digest after this many |
|
467 |
### messages have accumulated since the latest digest. |
|
468 |
### |
|
469 |
### See: ezmlm-tstdig(1) |
|
470 |
### |
|
471 |
def digest_count |
|
472 |
count = self.read( 'digcount' ).to_i |
|
473 |
return count.zero? ? 30 : count |
|
474 |
end |
|
475 |
||
476 |
### If the list is digestable, trigger the digest after this many |
|
477 |
### messages have accumulated since the latest digest. |
|
478 |
### |
|
479 |
### See: ezmlm-tstdig(1) |
|
480 |
### |
|
481 |
def digest_count=( count=30 ) |
|
482 |
self.write( 'digcount' ) {|f| f.puts count.to_i } |
|
483 |
end |
|
484 |
||
485 |
### If the list is digestable, trigger the digest after this much |
|
486 |
### time has passed since the last digest, in hours. |
|
487 |
### |
|
488 |
### See: ezmlm-tstdig(1) |
|
489 |
### |
|
490 |
def digest_timeout |
|
491 |
hours = self.read( 'digtime' ).to_i |
|
492 |
return hours.zero? ? 48 : hours |
|
493 |
end |
|
494 |
||
495 |
### If the list is digestable, trigger the digest after this much |
|
496 |
### time has passed since the last digest, in hours. |
|
497 |
### |
|
498 |
### See: ezmlm-tstdig(1) |
|
499 |
### |
|
500 |
def digest_timeout=( hours=48 ) |
|
501 |
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
|
502 |
end |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
503 |
|
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
504 |
|
14 | 505 |
### Returns +true+ if the list requires subscriptions to be |
506 |
### confirmed. AKA "help" mode if disabled. |
|
507 |
### |
|
508 |
def confirm_subscriptions? |
|
509 |
return ! ( self.listdir + 'nosubconfirm' ).exist? |
|
510 |
end |
|
511 |
||
512 |
### Disable or enable subscription confirmation. |
|
513 |
### AKA "help" mode if disabled. |
|
514 |
### |
|
515 |
def confirm_subscriptions=( enable=true ) |
|
516 |
if enable |
|
517 |
self.unlink( 'nosubconfirm' ) |
|
518 |
else |
|
519 |
self.touch( 'nosubconfirm' ) |
|
520 |
end |
|
521 |
end |
|
15 | 522 |
alias_method :confirm_subscriptions, :confirm_subscriptions= |
14 | 523 |
|
524 |
### Returns +true+ if the list requires unsubscriptions to be |
|
525 |
### confirmed. AKA "jump" mode. |
|
526 |
### |
|
527 |
def confirm_unsubscriptions? |
|
528 |
return ! ( self.listdir + 'nounsubconfirm' ).exist? |
|
529 |
end |
|
530 |
||
531 |
### Disable or enable unsubscription confirmation. |
|
532 |
### AKA "jump" mode. |
|
533 |
### |
|
534 |
def confirm_unsubscriptions=( enable=true ) |
|
535 |
if enable |
|
536 |
self.unlink( 'nounsubconfirm' ) |
|
537 |
else |
|
538 |
self.touch( 'nounsubconfirm' ) |
|
539 |
end |
|
540 |
end |
|
15 | 541 |
alias_method :confirm_unsubscriptions, :confirm_unsubscriptions= |
14 | 542 |
|
543 |
||
544 |
### Returns +true+ if the list requires regular message postings |
|
545 |
### to be confirmed by the original sender. |
|
546 |
### |
|
547 |
def confirm_postings? |
|
548 |
return ( self.listdir + 'confirmpost' ).exist? |
|
549 |
end |
|
550 |
||
551 |
### Disable or enable message confirmation. |
|
552 |
### |
|
553 |
def confirm_postings=( enable=false ) |
|
554 |
if enable |
|
555 |
self.touch( 'confirmpost' ) |
|
556 |
else |
|
557 |
self.unlink( 'confirmpost' ) |
|
558 |
end |
|
559 |
end |
|
15 | 560 |
alias_method :confirm_postings, :confirm_postings= |
14 | 561 |
|
562 |
||
563 |
### Returns +true+ if the list allows moderators to |
|
564 |
### fetch a subscriber list remotely. |
|
565 |
### |
|
566 |
def allow_remote_listing? |
|
567 |
return ( self.listdir + 'modcanlist' ).exist? |
|
568 |
end |
|
569 |
||
570 |
### Disable or enable the ability for moderators to |
|
571 |
### remotely fetch a subscriber list. |
|
572 |
### |
|
573 |
def allow_remote_listing=( enable=false ) |
|
574 |
if enable |
|
575 |
self.touch( 'modcanlist' ) |
|
576 |
else |
|
577 |
self.unlink( 'modcanlist' ) |
|
578 |
end |
|
579 |
end |
|
15 | 580 |
alias_method :allow_remote_listing, :allow_remote_listing= |
14 | 581 |
|
582 |
||
583 |
### Returns +true+ if the list automatically manages |
|
584 |
### bouncing subscriber addresses. |
|
585 |
### |
|
586 |
def bounce_warnings? |
|
587 |
return ! ( self.listdir + 'nowarn' ).exist? |
|
588 |
end |
|
589 |
||
590 |
### Disable or enable automatic bounce probes and warnings. |
|
591 |
### |
|
592 |
def bounce_warnings=( enable=true ) |
|
593 |
if enable |
|
594 |
self.unlink( 'nowarn' ) |
|
595 |
else |
|
596 |
self.touch( 'nowarn' ) |
|
597 |
end |
|
598 |
end |
|
15 | 599 |
alias_method :bounce_warnings, :bounce_warnings= |
14 | 600 |
|
601 |
||
602 |
### Return the maximum message size, in bytes. Messages larger than |
|
603 |
### this size will be rejected. |
|
604 |
### |
|
605 |
### See: ezmlm-reject(1) |
|
606 |
### |
|
607 |
def maximum_message_size |
|
608 |
size = self.read( 'msgsize' ) |
|
609 |
return size ? size.split( ':' ).first.to_i : 0 |
|
610 |
end |
|
611 |
||
612 |
### Set the maximum message size, in bytes. Messages larger than |
|
15 | 613 |
### this size will be rejected. Defaults to 300kb. |
14 | 614 |
### |
615 |
### See: ezmlm-reject(1) |
|
616 |
### |
|
617 |
def maximum_message_size=( size=307200 ) |
|
618 |
if size.to_i.zero? |
|
619 |
self.unlink( 'msgsize' ) |
|
620 |
else |
|
621 |
self.write( 'msgsize' ) {|f| f.puts "#{size.to_i}:0" } |
|
622 |
end |
|
623 |
end |
|
624 |
||
625 |
||
15 | 626 |
|
14 | 627 |
### Return the number of messages in the list archive. |
628 |
### |
|
629 |
def message_count |
|
630 |
count = self.read( 'archnum' ) |
|
631 |
return count ? Integer( count ) : 0 |
|
632 |
end |
|
633 |
||
15 | 634 |
### Returns an individual message if archiving was enabled. |
635 |
### |
|
636 |
def message( message_id ) |
|
637 |
raise "Message archive is empty." if self.message_count.zero? |
|
17 | 638 |
return Ezmlm::List::Message.new( self, message_id ) rescue nil |
15 | 639 |
end |
640 |
||
641 |
### Lazy load each message ID as a Ezmlm::List::Message, |
|
642 |
### yielding it to the block. |
|
13 | 643 |
### |
15 | 644 |
def each_message |
645 |
( 1 .. self.message_count ).each do |id| |
|
646 |
yield self.message( id ) |
|
647 |
end |
|
648 |
end |
|
649 |
||
650 |
||
651 |
### Return a Thread object for the given +thread_id+. |
|
652 |
### |
|
653 |
def thread( thread_id ) |
|
17 | 654 |
return Ezmlm::List::Thread.new( self, thread_id ) rescue nil |
15 | 655 |
end |
656 |
||
657 |
||
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
658 |
### 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
|
659 |
### could also be an email address. |
15 | 660 |
### |
661 |
def author( author_id ) |
|
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
15
diff
changeset
|
662 |
author_id = Ezmlm::Hash.address(author_id) if author_id.index( '@' ) |
17 | 663 |
return Ezmlm::List::Author.new( self, author_id ) rescue nil |
15 | 664 |
end |
665 |
||
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
666 |
|
15 | 667 |
### Parse all thread indexes into a single array that can be used |
668 |
### as a lookup table. |
|
669 |
### |
|
670 |
### These are not expanded into objects, use #message, #thread, |
|
671 |
### and #author to do so. |
|
672 |
### |
|
673 |
def index |
|
674 |
raise "Archiving is not enabled." unless self.archived? |
|
675 |
archivedir = listdir + 'archive' |
|
676 |
||
677 |
idx = ( 0 .. self.message_count / 100 ).each_with_object( [] ) do |dir, acc| |
|
678 |
index = archivedir + dir.to_s + 'index' |
|
679 |
next unless index.exist? |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
680 |
|
17 | 681 |
index.open( 'r', encoding: Encoding::ISO8859_1 ) do |fh| |
682 |
fh.each_line.lazy.slice_before( /^\d+:/ ).each do |message| |
|
683 |
||
684 |
match = message[0].match( /^(?<message_id>\d+): (?<thread_id>\w+)/ ) |
|
685 |
next unless match |
|
686 |
thread_id = match[ :thread_id ] |
|
15 | 687 |
|
17 | 688 |
match = message[1].match( /^(?<date>[^;]+);(?<author_id>\w+) / ) |
689 |
next unless match |
|
690 |
author_id = match[ :author_id ] |
|
691 |
date = match[ :date ] |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
692 |
|
17 | 693 |
metadata = { |
694 |
date: Time.parse( date ), |
|
695 |
thread: thread_id, |
|
696 |
author: author_id |
|
697 |
} |
|
698 |
acc << metadata |
|
699 |
end |
|
15 | 700 |
end |
701 |
end |
|
702 |
||
703 |
return idx |
|
4
8c4ae0797d5f
Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents:
2
diff
changeset
|
704 |
end |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
705 |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
706 |
|
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
707 |
######### |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
708 |
protected |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
709 |
######### |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
710 |
|
13 | 711 |
### Just return the contents of the provided +file+, rooted |
712 |
### in the list directory. |
|
713 |
### |
|
714 |
def read( file ) |
|
715 |
file = self.listdir + file unless file.is_a?( Pathname ) |
|
716 |
return file.read.chomp |
|
717 |
rescue |
|
718 |
nil |
|
719 |
end |
|
720 |
||
721 |
||
14 | 722 |
### Overwrite +file+ safely, yielding the open filehandle to the |
723 |
### block. Set the new file to correct ownership and permissions. |
|
724 |
### |
|
725 |
def write( file, &block ) |
|
726 |
file = self.listdir + file unless file.is_a?( Pathname ) |
|
727 |
self.with_safety do |
|
728 |
file.open( 'w' ) do |f| |
|
729 |
yield( f ) |
|
730 |
end |
|
731 |
||
732 |
stat = self.listdir.stat |
|
733 |
file.chown( stat.uid, stat.gid ) |
|
734 |
file.chmod( 0600 ) |
|
735 |
end |
|
736 |
end |
|
737 |
||
738 |
||
739 |
### Simply create an empty file, safely. |
|
740 |
### |
|
17 | 741 |
def touch( *file ) |
742 |
self.with_safety do |
|
743 |
Array( file ).flatten.each do |f| |
|
744 |
f = self.listdir + f unless f.is_a?( Pathname ) |
|
745 |
f.open( 'w' ) {} |
|
746 |
end |
|
747 |
end |
|
14 | 748 |
end |
749 |
||
750 |
||
751 |
### Delete +file+ safely. |
|
752 |
### |
|
17 | 753 |
def unlink( *file ) |
14 | 754 |
self.with_safety do |
17 | 755 |
Array( file ).flatten.each do |f| |
756 |
f = self.listdir + f unless f.is_a?( Pathname ) |
|
757 |
next unless f.exist? |
|
758 |
f.unlink |
|
759 |
end |
|
14 | 760 |
end |
761 |
end |
|
762 |
||
763 |
||
13 | 764 |
### Return a Pathname to a subscription directory. |
765 |
### |
|
766 |
def subscription_dir( section=nil ) |
|
767 |
if section |
|
14 | 768 |
unless SUBSCRIPTION_DIRS.include?( section ) |
769 |
raise "Invalid subscription dir: %s, must be one of: %s" % [ |
|
770 |
section, |
|
771 |
SUBSCRIPTION_DIRS.join( ', ' ) |
|
772 |
] |
|
773 |
end |
|
13 | 774 |
return self.listdir + section + 'subscribers' |
775 |
else |
|
776 |
return self.listdir + 'subscribers' |
|
777 |
end |
|
778 |
end |
|
779 |
||
780 |
||
14 | 781 |
### Read the hashed subscriber email addresses from the specified |
782 |
### +directory+ and return them in an Array. |
|
13 | 783 |
### |
784 |
def read_subscriber_dir( section=nil ) |
|
785 |
directory = self.subscription_dir( section ) |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
786 |
rval = [] |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
787 |
Pathname.glob( directory + '*' ) do |hashfile| |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
788 |
rval.push( hashfile.read.scan(/T([^\0]+)\0/) ) |
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
789 |
end |
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
790 |
|
13 | 791 |
return rval.flatten.sort |
792 |
end |
|
793 |
||
794 |
||
795 |
### Return a Pathname object for the list owner's home directory. |
|
796 |
### |
|
797 |
def homedir |
|
798 |
user = Etc.getpwuid( self.listdir.stat.uid ) |
|
799 |
return Pathname( user.dir ) |
|
800 |
end |
|
801 |
||
802 |
||
803 |
### Safely make modifications to a file within a list directory. |
|
804 |
### |
|
805 |
### Mail can come in at any time. Make changes within a list |
|
806 |
### atomic -- if an incoming message hits when a sticky |
|
807 |
### is set, it is deferred to the Qmail queue. |
|
808 |
### |
|
809 |
### - Set sticky bit on the list directory owner's homedir |
|
810 |
### - Make changes with the block |
|
811 |
### - Unset sticky (just back to what it was previously) |
|
812 |
### |
|
813 |
### All writes should be wrapped in this method. |
|
814 |
### |
|
815 |
def with_safety( &block ) |
|
816 |
home = self.homedir |
|
817 |
mode = home.stat.mode |
|
818 |
||
819 |
home.chmod( mode | 01000 ) # enable sticky |
|
820 |
yield |
|
821 |
||
822 |
ensure |
|
823 |
home.chmod( mode ) |
|
2
7b5a0131d5cd
Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents:
1
diff
changeset
|
824 |
end |
1
1d3cfd4837a8
Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff
changeset
|
825 |
|
12
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
826 |
end # class Ezmlm::List |
3cc813140c80
First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents:
5
diff
changeset
|
827 |