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