@@ -0,0 +1,14 | |||
|
1 | x-sender: <jsmith@somenet.foo> | |
|
2 | x-receiver: <redmine@somenet.foo> | |
|
3 | Received: from somenet.foo ([127.0.0.1]) by somenet.foo; | |
|
4 | Sun, 25 Feb 2007 09:57:56 GMT | |
|
5 | Date: Sun, 25 Feb 2007 10:57:56 +0100 | |
|
6 | From: jsmith@somenet.foo | |
|
7 | To: redmine@somenet.foo | |
|
8 | Message-Id: <45e15df440c00_b90238570a27b@osiris.tmail> | |
|
9 | In-Reply-To: <45e15df440c29_b90238570a27b@osiris.tmail> | |
|
10 | Subject: [Cookbook - Feature #2] | |
|
11 | Mime-Version: 1.0 | |
|
12 | Content-Type: text/plain; charset=utf-8 | |
|
13 | ||
|
14 | Note added by mail |
@@ -0,0 +1,57 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
|
19 | ||
|
20 | class MailHandlerTest < Test::Unit::TestCase | |
|
21 | fixtures :users, :projects, :roles, :members, :permissions, :issues, :permissions_roles, :trackers, :enumerations | |
|
22 | ||
|
23 | FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures' | |
|
24 | CHARSET = "utf-8" | |
|
25 | ||
|
26 | include ActionMailer::Quoting | |
|
27 | ||
|
28 | def setup | |
|
29 | ActionMailer::Base.delivery_method = :test | |
|
30 | ActionMailer::Base.perform_deliveries = true | |
|
31 | ActionMailer::Base.deliveries = [] | |
|
32 | ||
|
33 | @expected = TMail::Mail.new | |
|
34 | @expected.set_content_type "text", "plain", { "charset" => CHARSET } | |
|
35 | @expected.mime_version = '1.0' | |
|
36 | end | |
|
37 | ||
|
38 | def test_add_note_to_issue | |
|
39 | raw = read_fixture("add_note_to_issue_2.txt").join | |
|
40 | MailHandler.receive(raw) | |
|
41 | ||
|
42 | issue = Issue.find(2) | |
|
43 | journal = issue.journals.find(:first, :order => "created_on DESC") | |
|
44 | assert journal | |
|
45 | assert_equal User.find_by_mail("jsmith@somenet.foo"), journal.user | |
|
46 | assert_equal "Note added by mail", journal.notes | |
|
47 | end | |
|
48 | ||
|
49 | private | |
|
50 | def read_fixture(action) | |
|
51 | IO.readlines("#{FIXTURES_PATH}/mail_handler/#{action}") | |
|
52 | end | |
|
53 | ||
|
54 | def encode(subject) | |
|
55 | quoted_printable(subject, CHARSET) | |
|
56 | end | |
|
57 | end |
@@ -1,40 +1,40 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class MailHandler < ActionMailer::Base |
|
19 | 19 | |
|
20 | 20 | # Processes incoming emails |
|
21 |
# Currently, it only supports adding note |
|
|
21 | # Currently, it only supports adding a note to an existing issue | |
|
22 | 22 | # by replying to the initial notification message |
|
23 | 23 | def receive(email) |
|
24 | 24 | # find related issue by parsing the subject |
|
25 | 25 | m = email.subject.match %r{\[.*#(\d+)\]} |
|
26 | 26 | return unless m |
|
27 | 27 | issue = Issue.find_by_id(m[1]) |
|
28 | 28 | return unless issue |
|
29 | 29 | |
|
30 | 30 | # find user |
|
31 | 31 | user = User.find_active(:first, :conditions => {:mail => email.from.first}) |
|
32 | 32 | return unless user |
|
33 | 33 | # check permission |
|
34 | 34 | return unless Permission.allowed_to_role("issues/add_note", user.role_for_project(issue.project)) |
|
35 | 35 | |
|
36 |
# add the note |
|
|
37 | issue.init_journal(user, email.body) | |
|
36 | # add the note | |
|
37 | issue.init_journal(user, email.body.chomp) | |
|
38 | 38 | issue.save |
|
39 | 39 | end |
|
40 | 40 | end |
General Comments 0
You need to be logged in to leave comments.
Login now