Class: MList::MailList

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

Constant Summary collapse

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

Constants included from Util::EmailHelpers

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

#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.



31
32
33
# File 'lib/mlist/mail_list.rb', line 31

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.



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

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'


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

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/mlist/mail_list.rb', line 76

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.



101
102
103
# File 'lib/mlist/mail_list.rb', line 101

def list
  @list ||= manager_list
end

#manager_list_with_dual_type=(list) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/mlist/mail_list.rb', line 105

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.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mlist/mail_list.rb', line 36

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.



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

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