Class: MList::MailList

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Util::EmailHelpers, Util::Quoting
Defined in:
lib/mlist/mail_list.rb

Constant Summary collapse

"-~----~~----~----~----~----~---~~-~----~------~--~-~-"
"--~--~---~-----~--~----~-----~~~----~---~---~--~----~"

Constants included from Util::EmailHelpers

Util::EmailHelpers::AUTO_LINK_RE, Util::EmailHelpers::BRACKETS, Util::EmailHelpers::BRACKETS_RE, Util::EmailHelpers::HTML_ESCAPE, Util::EmailHelpers::REGARD_RE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::EmailHelpers

#auto_link_urls, #bracket, #escape_once, #header_sanitizer, #html_to_text, #normalize_new_lines, #remove_brackets, #remove_regard, #sanitize_header, #subscriber_name_and_address, #text_to_html, #text_to_quoted

Instance Attribute Details

#outgoing_serverObject

Returns the value of attribute outgoing_server.



45
46
47
# File 'lib/mlist/mail_list.rb', line 45

def outgoing_server
  @outgoing_server
end

Class Method Details

.find_or_create_by_list(list, outgoing_server) ⇒ Object

Provides the MailList for a given implementation of MList::List, connecting it to the provided email server for delivering posts.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mlist/mail_list.rb', line 10

def self.find_or_create_by_list(list, outgoing_server)
  if list.is_a?(ActiveRecord::Base)
    mail_list = find_or_create_by_manager_list_identifier_and_manager_list_type_and_manager_list_id(
      list.list_id, list.class.base_class.name, list.id
    )
  else
    mail_list = find_or_create_by_manager_list_identifier(list.list_id)
    mail_list.manager_list = list
  end
  mail_list.outgoing_server = outgoing_server
  mail_list
end

Instance Method Details

#clean_subject(string) ⇒ Object

Answers the provided subject with superfluous ‘re:’ and this list’s labels removed.

clean_subject('[List Label] Re: The new Chrome Browser from Google') => 'Re: The new Chrome Browser from Google'
clean_subject('Re: [List Label] Re: The new Chrome Browser from Google') => 'Re: The new Chrome Browser from Google'


81
82
83
84
85
86
87
88
# File 'lib/mlist/mail_list.rb', line 81

def clean_subject(string)
  without_label = string.gsub(subject_prefix_regex, '')
  if without_label =~ REGARD_RE
    "Re: #{remove_regard(without_label)}"
  else
    without_label
  end
end

#find_parent_message(email) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/mlist/mail_list.rb', line 90

def find_parent_message(email)
  if in_reply_to = email.header_string('in-reply-to')
    message = messages.find(:first,
      :conditions => ['identifier = ?', remove_brackets(in_reply_to)])
    return message if message
  end

  if email.references
    reference_identifiers = email.references.collect {|rid| remove_brackets(rid)}
    message = messages.find(:first,
      :conditions => ['identifier in (?)', reference_identifiers],
      :order => 'created_at desc')
    return message if message
  end

  if email.subject =~ REGARD_RE
    message = messages.find(:first,
      :conditions => ['subject = ?', remove_regard(clean_subject(email.subject))],
      :order => 'created_at asc')
    return message if message
  end
end

#listObject

The MList::List instance of the list manager.



115
116
117
# File 'lib/mlist/mail_list.rb', line 115

def list
  @list ||= manager_list
end

#manager_list_with_dual_type=(list) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/mlist/mail_list.rb', line 119

def manager_list_with_dual_type=(list)
  if list.is_a?(ActiveRecord::Base)
    self.manager_list_without_dual_type = list
    @list = list
  else
    self.manager_list_without_dual_type = nil
    @list = list
  end
end

#post(email_or_attributes) ⇒ Object

Creates a new MList::Message and delivers it to the subscribers of this list.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mlist/mail_list.rb', line 50

def post(email_or_attributes)
  email = email_or_attributes
  email = MList::EmailPost.new(email_or_attributes) unless email.is_a?(MList::EmailPost)
  process_message messages.build(
    :parent => email.reply_to_message,
    :parent_identifier => email.parent_identifier,
    :mail_list => self,
    :subscriber => email.subscriber,
    :recipients => list.recipients(email.subscriber),
    :email => MList::Email.new(:source => email.to_s)
  ), :search_parent => false, :copy_sender => email.copy_sender
end

#process_email(email, subscriber) ⇒ Object

Processes the email received by the MList::Server.



65
66
67
68
69
70
71
72
73
# File 'lib/mlist/mail_list.rb', line 65

def process_email(email, subscriber)
  recipients = list.recipients(subscriber)
  process_message messages.build(
    :mail_list => self,
    :subscriber => subscriber,
    :recipients => recipients,
    :email => email
  ), :copy_sender => list.copy_sender?(subscriber)
end