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