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