lib/ezmlm/list.rb
author Mahlon E. Smith <mahlon@martini.nu>
Fri, 03 Feb 2017 10:52:46 -0800
changeset 13 a03c08c289e9
parent 12 3cc813140c80
child 14 cba9fb39bcdb
permissions -rw-r--r--
Multiple changes. - Start converting from from the old 'config' file format where applicable. - Port the ezmlm address hashing algorithm for fast email lookups - Add subscription and unsubscription for primary and behavioral dirs - Add a safety check for writes to the list directory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    22
	# Quick address space detection, to (hopefully)
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    23
	# match the overflow size on this machine.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    24
	#
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    25
	ADDRESS_SPACE = case [ 'i' ].pack( 'p' ).size
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    26
					when 4
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    27
						32
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    28
					when 8
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    29
						64
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    30
					end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    31
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    32
	# Valid subdirectories/sections for subscriptions.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    33
	SUBSCRIPTION_DIRS = %w[ deny mod digest allow ]
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    34
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    51
		@name = self.read( 'outlocal' ) unless @name
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    59
		@host = self.read( 'outhost' ) unless @host
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    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
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    72
	### Return the email address of the list's owner.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    73
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    74
	def owner
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    75
		owner = self.read( 'owner' )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    76
		return owner =~ /@/ ? owner : nil
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    77
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    78
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    79
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    80
	### Return the number of messages in the list archive.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    81
	###
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    82
	def message_count
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    83
		count = self.read( 'archnum' )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    84
		return count ? Integer( count ) : 0
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    85
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    86
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    87
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    88
	### Fetch a sorted Array of the email addresses for all of the list's
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    89
	### subscribers.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    90
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    91
	def subscribers
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    92
		return self.read_subscriber_dir
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    93
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    94
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    95
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    96
	### Returns an Array of email addresses of people responsible for
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    97
	### moderating subscription of a closed list.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    98
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    99
	def moderators
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   100
		return self.read_subscriber_dir( 'mod' )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   101
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   102
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   103
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   104
	### Subscribe +addr+ to the list as a Moderator.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   105
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   106
	def add_moderator( *addr )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   107
		return self.subscribe( *addr, section: 'mod' )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   108
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   109
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   110
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   111
	### Remove +addr+ from the list as a Moderator.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   112
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   113
	def remove_moderator( *addr )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   114
		return self.unsubscribe( *addr, section: 'mod' )
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   115
	end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   116
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   117
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   118
	### Returns +true+ if +address+ is a subscriber to this list.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   119
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   120
	def include?( addr )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   121
		addr.downcase!
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   122
		file = self.subscription_dir + self.hashchar( addr )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   123
		return false unless file.exist?
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   124
		return file.read.scan( /T([^\0]+)\0/ ).flatten.include?( addr )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   125
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   126
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   127
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   128
	### Subscribe +addr+ to the list within +section+.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   129
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   130
	def subscribe( *addr, section: nil )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   131
		addr.each do |address|
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   132
			next unless address.index( '@' )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   133
			address.downcase!
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   134
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   135
			file = self.subscription_dir( section ) + self.hashchar( address )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   136
			self.with_safety do
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   137
				if file.exist?
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   138
					addresses = file.read.scan( /T([^\0]+)\0/ ).flatten
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   139
					addresses << address
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   140
					file.open( 'w' ) do |f|
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   141
						f.print addresses.uniq.sort.map{|a| "T#{a}\0" }.join
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   142
					end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   143
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   144
				else
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   145
					file.open( 'w' ) do |f|
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   146
						f.print "T%s\0" % [ address ]
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   147
					end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   148
				end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   149
			end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   150
		end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   151
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   152
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   153
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   154
	### Unsubscribe +addr+ from the list within +section+.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   155
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   156
	def unsubscribe( *addr, section: nil )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   157
		addr.each do |address|
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   158
			address.downcase!
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   159
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   160
			file = self.subscribers_dir( section ) + self.hashchar( address )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   161
			self.with_safety do
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   162
				next unless file.exist?
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   163
				addresses = file.read.scan( /T([^\0]+)\0/ ).flatten
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   164
				addresses = addresses - [ address ]
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   165
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   166
				if addresses.empty?
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   167
					file.unlink
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   168
				else
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   169
					file.open( 'w' ) do |f|
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   170
						f.print addresses.uniq.sort.map{|a| "T#{a}\0" }.join
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   171
					end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   172
				end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   173
			end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   174
		end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   175
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   176
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   177
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   178
=begin
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   179
	### Return the Date parsed from the last post to the list.
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   180
	###
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   181
	def last_message_date
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   182
		mail = self.last_post or return nil
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   183
		return mail.date
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   184
	end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   185
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   186
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   187
	### Return the author of the last post to the list.
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   188
	###
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   189
	def last_message_author
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   190
		mail = self.last_post or return nil
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   191
		return mail.from
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   192
	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
   193
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
   194
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   195
	### Returns +true+ if subscription to the list is moderated.
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   196
	###
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   197
	def closed?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   198
		return (self.listdir + 'modsub').exist? || (self.listdir + 'remote').exist?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   199
	end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   200
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   201
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   202
	### Returns +true+ if posting to the list is moderated.
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   203
	###
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   204
	def moderated?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   205
		return (self.listdir + 'modpost').exist?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   206
	end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   207
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   208
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   209
	### Return a Mail::Message object loaded from the last post to the list. Returns
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   210
	### +nil+ if there are no archived posts.
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   211
	###
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   212
	def last_post
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   213
		archivedir = self.listdir + 'archive'
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   214
		return nil unless archivedir.exist?
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   215
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   216
		# Find the last numbered directory under the archive dir
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   217
		last_archdir = Pathname.glob( archivedir + '[0-9]*' ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   218
			sort_by {|pn| Integer(pn.basename.to_s) }.last
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   219
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   220
		return nil unless last_archdir
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   221
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   222
		# Find the last numbered file under the last numbered directory we found
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   223
		# above.
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   224
		last_post_path = Pathname.glob( last_archdir + '[0-9]*' ).
5
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
   225
			sort_by {|pn| pn.basename.to_s }.last
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   226
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   227
		raise RuntimeError, "unexpectedly empty archive directory '%s'" % [ last_archdir ] \
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   228
			unless last_post_path
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   229
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   230
				require 'pry'
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   231
				binding.pry
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   232
		last_post = TMail::Mail.load( last_post_path.to_s )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   233
	end
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   234
=end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   235
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   236
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   237
	#########
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   238
	protected
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   239
	#########
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   240
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   241
	### Hash an email address, using the ezmlm algorithm for
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   242
	### fast user lookups.  Returns the hashed integer.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   243
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   244
	### Older ezmlm didn't lowercase addresses, anything within the last
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   245
	### decade did.  We're not going to worry about compatibility there.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   246
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   247
	### (See subhash.c in the ezmlm source.)
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   248
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   249
	def subhash( addr )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   250
		h = 5381
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   251
		over = 2 ** ADDRESS_SPACE
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   252
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   253
		addr = 'T' + addr
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   254
		addr.each_char do |c|
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   255
			h = ( h + ( h << 5 ) ) ^ c.ord
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   256
			h = h % over if h > over # emulate integer overflow
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   257
		end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   258
		return h % 53
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   259
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   260
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   261
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   262
	### Given an email address, return the ascii character.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   263
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   264
	def hashchar( addr )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   265
		return ( self.subhash(addr) + 64 ).chr
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   266
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   267
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   268
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   269
	### Just return the contents of the provided +file+, rooted
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   270
	### in the list directory.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   271
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   272
	def read( file )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   273
		file = self.listdir + file unless file.is_a?( Pathname )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   274
		return file.read.chomp
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   275
	rescue
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   276
		nil
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   277
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   278
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   279
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   280
	### Return a Pathname to a subscription directory.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   281
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   282
	def subscription_dir( section=nil )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   283
		section = nil if section && ! SUBSCRIPTION_DIRS.include?( section )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   284
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   285
		if section
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   286
			return self.listdir + section + 'subscribers'
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   287
		else
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   288
			return self.listdir + 'subscribers'
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   289
		end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   290
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   291
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   292
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   293
	### Read the hashed subscriber email addresses from the specified +directory+ and return them in
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   294
	### an Array.
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   295
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   296
	def read_subscriber_dir( section=nil )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   297
		directory = self.subscription_dir( section )
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   298
		rval = []
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   299
		Pathname.glob( directory + '*' ) do |hashfile|
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   300
			rval.push( hashfile.read.scan(/T([^\0]+)\0/) )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   301
		end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   302
13
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   303
		return rval.flatten.sort
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   304
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   305
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   306
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   307
	### Return a Pathname object for the list owner's home directory.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   308
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   309
	def homedir
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   310
		user = Etc.getpwuid( self.listdir.stat.uid )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   311
		return Pathname( user.dir )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   312
	end
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   313
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   314
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   315
	### Safely make modifications to a file within a list directory.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   316
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   317
	### Mail can come in at any time.  Make changes within a list
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   318
	### atomic -- if an incoming message hits when a sticky
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   319
	### is set, it is deferred to the Qmail queue.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   320
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   321
	###   - Set sticky bit on the list directory owner's homedir
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   322
	###   - Make changes with the block
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   323
	###   - Unset sticky (just back to what it was previously)
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   324
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   325
	### All writes should be wrapped in this method.
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   326
	###
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   327
	def with_safety( &block )
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   328
		home = self.homedir
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   329
		mode = home.stat.mode
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   330
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   331
		home.chmod( mode | 01000 ) # enable sticky
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   332
		yield
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   333
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   334
	ensure
a03c08c289e9 Multiple changes.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
   335
		home.chmod( mode )
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   336
	end
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   337
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   338
end # class Ezmlm::List
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   339