class MailManager::List
The List
class represents mailing lists in Mailman. Typically you get them by doing one of these things: mm = MailManager.init
('/mailman/root') mylist = mm.get_list('list_name') OR mylist = mm.create_list(:name => 'list_name', :admin_email => 'foo@bar.com', :admin_password => 'supersecret')
Attributes
The name of the list
Public Class Methods
This doesn't do any checking to see whether or not the requested list exists or not. Better to use MailManager::Base#get_list
instead.
# File lib/mailmanager/list.rb, line 18 def initialize(name) @name = name end
Public Instance Methods
Adds a new list member, subject to the list's subscription rules
# File lib/mailmanager/list.rb, line 71 def add_member(email, name='') add_member_using(:add_member, email, name) end
Adds a new moderator to the list. Returns :already_a_moderator if the requested new moderator is already a moderator.
# File lib/mailmanager/list.rb, line 98 def add_moderator(email) result = lib.add_moderator(self, email) result['result'].to_sym end
Returns the list's email address
# File lib/mailmanager/list.rb, line 48 def address result = lib.list_address(self) result['return'] end
Adds a new list member, bypassing the list's subscription rules
# File lib/mailmanager/list.rb, line 76 def approved_add_member(email, name='') add_member_using(:approved_add_member, email, name) end
Deletes a list member, bypassing the list's unsubscription rules
# File lib/mailmanager/list.rb, line 86 def approved_delete_member(email, name='') delete_member_using(:approved_delete_member, email) end
Deletes the list, but not the archives
# File lib/mailmanager/list.rb, line 43 def delete self.class.delete(self.name) end
Deletes a list member, subject to the list's unsubscription rules
# File lib/mailmanager/list.rb, line 81 def delete_member(email) delete_member_using(:delete_member, email) end
Deletes a moderator from the list. Raises a ModeratorNotFoundError
if the requested deletion isn't a moderator.
# File lib/mailmanager/list.rb, line 105 def delete_moderator(email) result = lib.delete_moderator(self, email) result['result'].to_sym end
Returns the list description
# File lib/mailmanager/list.rb, line 153 def description result = lib.description(self) result['return'] end
Sets the list description to a new value
# File lib/mailmanager/list.rb, line 159 def description=(desc) result = lib.set_description(self, desc) result['result'].to_sym end
Returns just the digest list members (no regular members) as an array
# File lib/mailmanager/list.rb, line 65 def digest_members result = lib.digest_members(self) result['return'] end
Returns the list's host name
# File lib/mailmanager/list.rb, line 178 def host_name result = lib.host_name(self) result['return'] end
Sets the list's host name
# File lib/mailmanager/list.rb, line 184 def host_name=(host_name) result = lib.set_host_name(self, host_name) result['result'].to_sym end
Returns the info URL for the list
# File lib/mailmanager/list.rb, line 139 def info_url result = lib.web_page_url(self) root = result['return'] root += "/" unless root[-1,1] == '/' "#{root}listinfo/#{name}" end
Injects a message into the list.
# File lib/mailmanager/list.rb, line 111 def inject(from, subj, message, custom_headers=nil) inject_message =<<EOF From: #{from} To: #{address} Subject: #{subj} EOF if !custom_headers.nil? raise ArgumentError, "custom headers arg should be a hash" unless custom_headers.respond_to?(:each_pair) headers = [] custom_headers.each_pair { |hdr, val| headers << "#{hdr}: #{val}" } inject_message += headers.join("\n") end inject_message += "\n#{message}" result = lib.inject(self, inject_message) result['result'].to_sym end
Injects a raw message into the list. You must send a properly formatted email to this method. You probably want to set the To: header to the list's address. You can get that from MailManager::List#address
# File lib/mailmanager/list.rb, line 133 def inject_raw(message) result = lib.inject(self, message) result['result'].to_sym end
Returns all list members (regular & digest) as an array
# File lib/mailmanager/list.rb, line 54 def members regular_members + digest_members end
Returns the list of moderators as an array of email addresses
# File lib/mailmanager/list.rb, line 91 def moderators result = lib.moderators(self) result['return'] end
Returns just the regular list members (no digest members) as an array
# File lib/mailmanager/list.rb, line 59 def regular_members result = lib.regular_members(self) result['return'] end
Returns the request email address for the list
# File lib/mailmanager/list.rb, line 147 def request_email result = lib.request_email(self) result['return'] end
Returns the list's subject prefix
# File lib/mailmanager/list.rb, line 165 def subject_prefix result = lib.subject_prefix(self) result['return'] end
Sets the list's subject prefix to a new value. Remember to leave a space at the end (assuming you want one, and you probably do).
# File lib/mailmanager/list.rb, line 172 def subject_prefix=(sp) result = lib.set_subject_prefix(self, sp) result['result'].to_sym end
Private Instance Methods
# File lib/mailmanager/list.rb, line 191 def add_member_using(method, email, name) if name.length > 0 member = "#{name} <#{email}>" else member = email end result = lib.send(method, self, member) result['result'].to_sym end
# File lib/mailmanager/list.rb, line 201 def delete_member_using(method, email) result = lib.send(method, self, email) result['result'].to_sym end