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:
parent
73e822834d
commit
32f5731947
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
4
mailing_lists/app/models/mailing_message.rb
Normal file
4
mailing_lists/app/models/mailing_message.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class MailingMessage < ActiveRecord::Base
|
||||
belongs_to :mailing_list
|
||||
acts_as_tree :order => 'sent_on'
|
||||
end
|
||||
10
mailing_lists/db/migrate/025_create_mailing_messages.rb
Normal file
10
mailing_lists/db/migrate/025_create_mailing_messages.rb
Normal 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
|
||||
5
mailing_lists/test/fixtures/mailing_messages.yml
vendored
Normal file
5
mailing_lists/test/fixtures/mailing_messages.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
one:
|
||||
id: 1
|
||||
two:
|
||||
id: 2
|
||||
10
mailing_lists/test/unit/mailing_message_test.rb
Normal file
10
mailing_lists/test/unit/mailing_message_test.rb
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user