1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-11 19:53:07 +00:00

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 2007-02-25 11:14:33 +00:00
parent 73e822834d
commit 32f5731947
6 changed files with 45 additions and 0 deletions

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

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

View File

@ -0,0 +1,4 @@
class MailingMessage < ActiveRecord::Base
belongs_to :mailing_list
acts_as_tree :order => 'sent_on'
end

View File

@ -0,0 +1,10 @@
class CreateMailingMessages < ActiveRecord::Migration
def self.up
create_table :mailing_messages do |t|
end
end
def self.down
drop_table :mailing_messages
end
end

View File

@ -0,0 +1,5 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
id: 1
two:
id: 2

View File

@ -0,0 +1,10 @@
require File.dirname(__FILE__) + '/../test_helper'
class MailingMessageTest < Test::Unit::TestCase
fixtures :mailing_messages
# Replace this with your real tests.
def test_truth
assert true
end
end