lib/ezmlm/list.rb
changeset 4 8c4ae0797d5f
parent 2 7b5a0131d5cd
child 5 804e1c2b9a40
equal deleted inserted replaced
3:9b9e85ccf4f9 4:8c4ae0797d5f
    18 # Please see the file LICENSE in the base directory for licensing details.
    18 # Please see the file LICENSE in the base directory for licensing details.
    19 #
    19 #
    20 
    20 
    21 require 'pathname'
    21 require 'pathname'
    22 require 'ezmlm'
    22 require 'ezmlm'
       
    23 require 'tmail'
    23 
    24 
    24 
    25 
    25 ### A Ruby interface to an ezmlm-idx mailing list directory
    26 ### A Ruby interface to an ezmlm-idx mailing list directory
    26 class Ezmlm::List
    27 class Ezmlm::List
    27 	
    28 	
    38 	######
    39 	######
    39 
    40 
    40 	# The Pathname object for the list directory
    41 	# The Pathname object for the list directory
    41 	attr_reader :listdir
    42 	attr_reader :listdir
    42 
    43 
       
    44 
       
    45 	### Return the number of messages in the list archive
       
    46 	def message_count
       
    47 		numfile = self.listdir + 'num'
       
    48 		return 0 unless numfile.exist?
       
    49 		return Integer( numfile.read[/^(\d+):/, 1] )
       
    50 	end
       
    51 
       
    52 
       
    53 	### Return the Date parsed from the last post to the list.
       
    54 	def last_message_date
       
    55 		mail = self.last_post or return nil
       
    56 		return mail.date
       
    57 	end
       
    58 
       
    59 
       
    60 	### Return the author of the last post to the list.
       
    61 	def last_message_author
       
    62 		mail = self.last_post or return nil
       
    63 		return mail.from
       
    64 	end
       
    65 	
    43 
    66 
    44 	### Return the email address of the list's owner.
    67 	### Return the email address of the list's owner.
    45 	def owner
    68 	def owner
    46 		config = self.listdir + 'config'
    69 		config = self.listdir + 'config'
    47 		if config.read =~ /^5:([^\n]+)$/m
    70 		if config.read =~ /^5:([^\n]+)$/m
   108 		
   131 		
   109 		return self.read_subscriber_dir( subdir )
   132 		return self.read_subscriber_dir( subdir )
   110 	end
   133 	end
   111 	
   134 	
   112 	
   135 	
       
   136 	### Return a TMail::Mail object loaded from the last post to the list. Returns
       
   137 	### +nil+ if there are no archived posts.
       
   138 	def last_post
       
   139 		archivedir = self.listdir + 'archive'
       
   140 		return nil unless archivedir.exist?
       
   141 
       
   142 		# Find the last numbered directory under the archive dir
       
   143 		last_archdir = Pathname.glob( archivedir + '[0-9]*' ).
       
   144 			sort_by {|pn| Integer(pn.basename.to_s) }.last
       
   145 
       
   146 		return nil unless last_archdir
       
   147 
       
   148 		# Find the last numbered file under the last numbered directory we found
       
   149 		# above.
       
   150 		last_post_path = Pathname.glob( last_archdir + '[0-9]*' ).
       
   151 			sort_by {|pn| Integer(pn.basename.to_s) }.last
       
   152 
       
   153 		raise RuntimeError, "unexpectedly empty archive directory '%s'" % [ last_archdir ] \
       
   154 			unless last_post_path
       
   155 
       
   156 		last_post = TMail::Mail.load( last_post_path.to_s )
       
   157 	end
       
   158 	
       
   159 	
   113 
   160 
   114 	#########
   161 	#########
   115 	protected
   162 	protected
   116 	#########
   163 	#########
   117 
   164