lib/ezmlm/list.rb
author Mahlon E. Smith <mahlon@martini.nu>
Wed, 01 Feb 2017 15:35:35 -0800
changeset 12 3cc813140c80
parent 5 804e1c2b9a40
child 13 a03c08c289e9
permissions -rw-r--r--
First round of modernizing after a long absence. Much work to be done.
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'
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    13
require 'ezmlm'
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    14
require 'mail'
1
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
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    17
### 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
    18
###
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    19
class Ezmlm::List
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    20
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    21
	### 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
    22
	### 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
	###
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    24
	def initialize( listdir )
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    25
		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
    26
		@listdir = listdir
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    27
	end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    28
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    29
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    30
	######
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    31
	public
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    32
	######
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)
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    39
	def name
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    40
		return self.config[ 'L' ]
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    41
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    42
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
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    44
	### Return the configured host of the list
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    45
	def host
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 self.config[ 'H' ]
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    47
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    48
5
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    49
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    50
	### Return the configured address of the list (in list@host form)
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    51
	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
    52
		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
    53
	end
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    54
	alias_method :fullname, :address
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    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
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    57
	### Return the number of messages in the list archive
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    58
	def message_count
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    59
		numfile = self.listdir + 'num'
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    60
		return 0 unless numfile.exist?
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    61
		return Integer( numfile.read[/^(\d+):/, 1] )
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    62
	end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    63
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    64
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    65
	### Return the Date parsed from the last post to the list.
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    66
	def last_message_date
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    67
		mail = self.last_post or return nil
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    68
		return mail.date
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    69
	end
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    70
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    71
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    72
	### Return the author of the last post to the list.
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    73
	def last_message_author
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    74
		mail = self.last_post or return nil
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    75
		return mail.from
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    76
	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
    77
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    78
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    79
	### Return the list config as a Hash
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    80
	def config
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    81
		unless @config
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    82
			configfile = self.listdir + 'config'
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    83
			raise "List config file %p does not exist" % [ configfile ] unless configfile.exist?
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    84
5
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    85
			@config = configfile.read.scan( /^(\S):([^\n]*)$/m ).inject({}) do |h,pair|
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    86
				key,val = *pair
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    87
				h[key] = val
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    88
				h
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    89
			end
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    90
		end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    91
5
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    92
		return @config
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    93
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
    94
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
    95
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    96
	### Return the email address of the list's owner.
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    97
	def owner
5
804e1c2b9a40 * Added rdoc-generation to the cruise task and the artifacts that get saved
Michael Granger <mgranger@laika.com>
parents: 4
diff changeset
    98
		self.config['5']
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
    99
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   100
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   101
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   102
	### Fetch an Array of the email addresses for all of the list's subscribers.
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   103
	def subscribers
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   104
		subscribers_dir = self.listdir + 'subscribers'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   105
		return self.read_subscriber_dir( subscribers_dir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   106
	end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   107
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   108
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   109
	### Returns +true+ if subscription to the list is moderated.
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   110
	def closed?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   111
		return (self.listdir + 'modsub').exist? || (self.listdir + 'remote').exist?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   112
	end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   113
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   114
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   115
	### Returns +true+ if posting to the list is moderated.
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   116
	def moderated?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   117
		return (self.listdir + 'modpost').exist?
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   118
	end
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   119
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   120
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   121
	### Returns an Array of email addresses of people responsible for moderating subscription
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   122
	### of a closed list.
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   123
	def subscription_moderators
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   124
		return [] unless self.closed?
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   125
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   126
		modsubfile = self.listdir + 'modsub'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   127
		remotefile = self.listdir + 'remote'
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   128
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   129
		subdir = nil
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   130
		if modsubfile.exist? && modsubfile.read(1) == '/'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   131
			subdir = Pathname.new( modsubfile.read.chomp )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   132
		elsif remotefile.exist? && remotefile.read(1) == '/'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   133
			subdir = Pathname.new( remotefile.read.chomp )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   134
		else
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   135
			subdir = self.listdir + 'mod/subscribers'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   136
		end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   137
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   138
		return self.read_subscriber_dir( subdir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   139
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   140
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   141
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   142
	### Returns an Array of email addresses of people responsible for moderating posts
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   143
	### sent to the list.
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   144
	def message_moderators
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   145
		return [] unless self.moderated?
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   146
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   147
		modpostfile = self.listdir + 'modpost'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   148
		subdir = nil
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   149
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   150
		if modpostfile.exist? && modpostfile.read(1) == '/'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   151
			subdir = Pathname.new( modpostfile.read.chomp )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   152
		else
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   153
			subdir = self.listdir + 'mod/subscribers'
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   154
		end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   155
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   156
		return self.read_subscriber_dir( subdir )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   157
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   158
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   159
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   160
	### Return a TMail::Mail object loaded from the last post to the list. Returns
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   161
	### +nil+ if there are no archived posts.
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   162
	def last_post
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   163
		archivedir = self.listdir + 'archive'
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   164
		return nil unless archivedir.exist?
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   165
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   166
		# Find the last numbered directory under the archive dir
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   167
		last_archdir = Pathname.glob( archivedir + '[0-9]*' ).
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   168
			sort_by {|pn| Integer(pn.basename.to_s) }.last
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   169
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   170
		return nil unless last_archdir
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   171
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   172
		# 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
   173
		# above.
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   174
		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
   175
			sort_by {|pn| pn.basename.to_s }.last
4
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   176
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   177
		raise RuntimeError, "unexpectedly empty archive directory '%s'" % [ last_archdir ] \
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   178
			unless last_post_path
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   179
8c4ae0797d5f Added more archive-related functions:
Michael Granger <mgranger@laika.com>
parents: 2
diff changeset
   180
		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
   181
	end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   182
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   183
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   184
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   185
	#########
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   186
	protected
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   187
	#########
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   188
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   189
	### 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
   190
	### an Array.
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   191
	def read_subscriber_dir( directory )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   192
		rval = []
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   193
		Pathname.glob( directory + '*' ) do |hashfile|
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   194
			rval.push( hashfile.read.scan(/T([^\0]+)\0/) )
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   195
		end
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   196
2
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   197
		return rval.flatten
7b5a0131d5cd Added more list-config accessors
Michael Granger <mgranger@laika.com>
parents: 1
diff changeset
   198
	end
1
1d3cfd4837a8 Filled out the project, added Ezmlm module + spec.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
   199
12
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   200
end # class Ezmlm::List
3cc813140c80 First round of modernizing after a long absence.
Mahlon E. Smith <mahlon@martini.nu>
parents: 5
diff changeset
   201