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