lib/ezmlm/list.rb
changeset 2 7b5a0131d5cd
parent 1 1d3cfd4837a8
child 4 8c4ae0797d5f
equal deleted inserted replaced
1:1d3cfd4837a8 2:7b5a0131d5cd
    23 
    23 
    24 
    24 
    25 ### A Ruby interface to an ezmlm-idx mailing list directory
    25 ### A Ruby interface to an ezmlm-idx mailing list directory
    26 class Ezmlm::List
    26 class Ezmlm::List
    27 	
    27 	
       
    28 	### Create a new Ezmlm::List object for the specified +listdir+, which should be
       
    29 	### an ezmlm-idx mailing list directory.
       
    30 	def initialize( listdir )
       
    31 		listdir = Pathname.new( listdir ) if !listdir.is_a?( Pathname )
       
    32 		@listdir = listdir
       
    33 	end
       
    34 
       
    35 
       
    36 	######
       
    37 	public
       
    38 	######
       
    39 
       
    40 	# The Pathname object for the list directory
       
    41 	attr_reader :listdir
       
    42 
       
    43 
       
    44 	### Return the email address of the list's owner.
       
    45 	def owner
       
    46 		config = self.listdir + 'config'
       
    47 		if config.read =~ /^5:([^\n]+)$/m
       
    48 			return $1
       
    49 		else
       
    50 			return nil
       
    51 		end
       
    52 	end
       
    53 	
       
    54 
       
    55 	### Fetch an Array of the email addresses for all of the list's subscribers.
       
    56 	def subscribers
       
    57 		subscribers_dir = self.listdir + 'subscribers'
       
    58 		return self.read_subscriber_dir( subscribers_dir )
       
    59 	end
       
    60 
       
    61 
       
    62 	### Returns +true+ if subscription to the list is moderated.
       
    63 	def closed?
       
    64 		return (self.listdir + 'modsub').exist? || (self.listdir + 'remote').exist?
       
    65 	end
       
    66 
       
    67 
       
    68 	### Returns +true+ if posting to the list is moderated.
       
    69 	def moderated?
       
    70 		return (self.listdir + 'modpost').exist?
       
    71 	end
       
    72 
       
    73 
       
    74 	### Returns an Array of email addresses of people responsible for moderating subscription
       
    75 	### of a closed list.
       
    76 	def subscription_moderators
       
    77 		return [] unless self.closed?
       
    78 		
       
    79 		modsubfile = self.listdir + 'modsub'
       
    80 		remotefile = self.listdir + 'remote'
       
    81 		
       
    82 		subdir = nil
       
    83 		if modsubfile.exist? && modsubfile.read(1) == '/'
       
    84 			subdir = Pathname.new( modsubfile.read.chomp )
       
    85 		elsif remotefile.exist? && remotefile.read(1) == '/'
       
    86 			subdir = Pathname.new( remotefile.read.chomp )
       
    87 		else
       
    88 			subdir = self.listdir + 'mod/subscribers'
       
    89 		end
       
    90 		
       
    91 		return self.read_subscriber_dir( subdir )
       
    92 	end
       
    93 	
       
    94 	
       
    95 	### Returns an Array of email addresses of people responsible for moderating posts
       
    96 	### sent to the list.
       
    97 	def message_moderators
       
    98 		return [] unless self.moderated?
       
    99 		
       
   100 		modpostfile = self.listdir + 'modpost'
       
   101 		subdir = nil
       
   102 		
       
   103 		if modpostfile.exist? && modpostfile.read(1) == '/'
       
   104 			subdir = Pathname.new( modpostfile.read.chomp )
       
   105 		else
       
   106 			subdir = self.listdir + 'mod/subscribers'
       
   107 		end
       
   108 		
       
   109 		return self.read_subscriber_dir( subdir )
       
   110 	end
       
   111 	
       
   112 	
       
   113 
       
   114 	#########
       
   115 	protected
       
   116 	#########
       
   117 
       
   118 	### Read the hashed subscriber email addresses from the specified +directory+ and return them in 
       
   119 	### an Array.
       
   120 	def read_subscriber_dir( directory )
       
   121 		rval = []
       
   122 		Pathname.glob( directory + '*' ) do |hashfile|
       
   123 			rval.push( hashfile.read.scan(/T([^\0]+)\0/) )
       
   124 		end
       
   125 		
       
   126 		return rval.flatten
       
   127 	end
       
   128 	
       
   129 	
    28 end
   130 end
    29 
   131 
    30 # vim: set nosta noet ts=4 sw=4:
   132 # vim: set nosta noet ts=4 sw=4: