added mailing_message model and Mailer.receive method

git-svn-id: http://redmine.rubyforge.org/svn/branches/work@265 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang committed 2007-02-25 11:14:33 +00:00
1 parent 73e822834d
commit 32f5731947
6 files changed
+45

No files matched your search

+15
View File
@@ -85,4 +85,19 @@ class Mailer < ActionMailer::Base
@subject = l(:mail_subject_register)
@body['token'] = token
end
def receive(email)
to_names = email.to.collect { |to| to.gsub(/@.*$/,'') }
@mailing_list = MailingList.find_all_by_name(to_names).first
in_reply_to = @mailing_list.messages.find(:first, :conditions => ["messageid=?", email.in_reply_to.first]) if email.in_reply_to
MailingMessage.create(:mailing_list => @mailing_list,
:parent => in_reply_to,
:messageid => email.message_id,
:from => email.from.first,
:subject => email.subject,
:body => email.body,
:sent_on => (email.date || Time.now)) if @mailing_list
end
end
+1
View File
@@ -18,6 +18,7 @@
class MailingList < ActiveRecord::Base
belongs_to :project
belongs_to :admin, :class_name => 'User', :foreign_key => 'admin_id'
has_many :messages, :class_name => 'MailingMessage', :dependent => :delete_all
validates_presence_of :name, :description
@@ -0,0 +1,4 @@
class MailingMessage < ActiveRecord::Base
belongs_to :mailing_list
acts_as_tree :order => 'sent_on'
end