mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
MailHandler: Select project by subaddress (redmine+project@example.com) (#20732).
Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@14687 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
5ad4bee389
commit
3caa882286
@ -364,11 +364,27 @@ class MailHandler < ActionMailer::Base
|
|||||||
keyword
|
keyword
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_project_from_receiver_addresses
|
||||||
|
[:to, :cc, :bcc].each do |field|
|
||||||
|
header = @email[field]
|
||||||
|
next if header.blank? || header.field.blank? || !header.field.respond_to?(:addrs)
|
||||||
|
header.field.addrs.each do |addr|
|
||||||
|
if addr.local.to_s =~ /\+([^+]+)\z/
|
||||||
|
if project = Project.find_by_identifier($1)
|
||||||
|
return project
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def target_project
|
def target_project
|
||||||
# TODO: other ways to specify project:
|
# TODO: other ways to specify project:
|
||||||
# * parse the email To field
|
# * parse the email To field
|
||||||
# * specific project (eg. Setting.mail_handler_target_project)
|
# * specific project (eg. Setting.mail_handler_target_project)
|
||||||
target = Project.find_by_identifier(get_keyword(:project))
|
target = get_project_from_receiver_addresses
|
||||||
|
target ||= Project.find_by_identifier(get_keyword(:project))
|
||||||
if target.nil?
|
if target.nil?
|
||||||
# Invalid project keyword, use the project specified as the default one
|
# Invalid project keyword, use the project specified as the default one
|
||||||
default_project = handler_options[:issue][:project]
|
default_project = handler_options[:issue][:project]
|
||||||
|
|||||||
60
test/fixtures/mail_handler/ticket_on_project_given_by_to_header.eml
vendored
Normal file
60
test/fixtures/mail_handler/ticket_on_project_given_by_to_header.eml
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
Return-Path: <JSmith@somenet.foo>
|
||||||
|
Received: from osiris ([127.0.0.1])
|
||||||
|
by OSIRIS
|
||||||
|
with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
|
||||||
|
Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
|
||||||
|
From: "John Smith" <JSmith@somenet.foo>
|
||||||
|
To: <redmine+onlinestore@somenet.foo>
|
||||||
|
Subject: New ticket on a given project
|
||||||
|
Date: Sun, 22 Jun 2008 12:28:07 +0200
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain;
|
||||||
|
format=flowed;
|
||||||
|
charset="iso-8859-1";
|
||||||
|
reply-type=original
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
X-Priority: 3
|
||||||
|
X-MSMail-Priority: Normal
|
||||||
|
X-Mailer: Microsoft Outlook Express 6.00.2900.2869
|
||||||
|
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
|
||||||
|
|
||||||
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet
|
||||||
|
turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus
|
||||||
|
blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti
|
||||||
|
sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In
|
||||||
|
in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
|
||||||
|
sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
|
||||||
|
id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
|
||||||
|
eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
|
||||||
|
sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et
|
||||||
|
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
|
||||||
|
platea dictumst.
|
||||||
|
|
||||||
|
Status: Resolved
|
||||||
|
due date: 2010-12-31
|
||||||
|
Start Date:2010-01-01
|
||||||
|
Assigned to: John Smith
|
||||||
|
fixed version: alpha
|
||||||
|
estimated hours: 2.5
|
||||||
|
done ratio: 30
|
||||||
|
|
||||||
|
--- This line starts with a delimiter and should not be stripped
|
||||||
|
|
||||||
|
This paragraph is before delimiters.
|
||||||
|
|
||||||
|
BREAK
|
||||||
|
|
||||||
|
This paragraph is between delimiters.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
This paragraph is after the delimiter so it shouldn't appear.
|
||||||
|
|
||||||
|
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque
|
||||||
|
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem.
|
||||||
|
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et,
|
||||||
|
dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed,
|
||||||
|
massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo
|
||||||
|
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +103,19 @@ class MailHandlerTest < ActiveSupport::TestCase
|
|||||||
assert_equal 0, issue.done_ratio
|
assert_equal 0, issue.done_ratio
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_add_issue_to_project_specified_by_subaddress
|
||||||
|
# This email has redmine+onlinestore@somenet.foo as 'To' header
|
||||||
|
issue = submit_email(
|
||||||
|
'ticket_on_project_given_by_to_header.eml',
|
||||||
|
:issue => {:tracker => 'Support request'}
|
||||||
|
)
|
||||||
|
assert issue.is_a?(Issue)
|
||||||
|
assert !issue.new_record?
|
||||||
|
issue.reload
|
||||||
|
assert_equal 'onlinestore', issue.project.identifier
|
||||||
|
assert_equal 'Support request', issue.tracker.name
|
||||||
|
end
|
||||||
|
|
||||||
def test_add_issue_with_default_tracker
|
def test_add_issue_with_default_tracker
|
||||||
# This email contains: 'Project: onlinestore'
|
# This email contains: 'Project: onlinestore'
|
||||||
issue = submit_email(
|
issue = submit_email(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user