From: Jean-Philippe Lang Date: Sun, 22 Jun 2008 10:45:03 +0000 (+0000) Subject: Adds basic support for issue creation via email (#1110). X-Git-Tag: 0.8.0-RC1~426 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a01f976b4cfa4a72deed2d12e9b4b5e897de30ef;p=redmine.git Adds basic support for issue creation via email (#1110). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1568 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 7a1d73244..03e48e170 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -16,25 +16,119 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class MailHandler < ActionMailer::Base + + class UnauthorizedAction < StandardError; end + class MissingInformation < StandardError; end + + attr_reader :email, :user + + def self.receive(email, options={}) + @@handler_options = options + super email + end # Processes incoming emails - # Currently, it only supports adding a note to an existing issue - # by replying to the initial notification message def receive(email) - # find related issue by parsing the subject - m = email.subject.match %r{\[.*#(\d+)\]} - return unless m - issue = Issue.find_by_id(m[1]) + @email = email + @user = User.find_active(:first, :conditions => {:mail => email.from.first}) + unless @user + # Unknown user => the email is ignored + # TODO: ability to create the user's account + logger.info "MailHandler: email submitted by unknown user [#{email.from.first}]" if logger && logger.info + return false + end + User.current = @user + dispatch + end + + private + + ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]+#(\d+)\]} + + def dispatch + if m = email.subject.match(ISSUE_REPLY_SUBJECT_RE) + receive_issue_update(m[1].to_i) + else + receive_issue + end + rescue ActiveRecord::RecordInvalid => e + # TODO: send a email to the user + logger.error e.message if logger + false + rescue MissingInformation => e + logger.error "MailHandler: missing information from #{user}: #{e.message}" if logger + false + rescue UnauthorizedAction => e + logger.error "MailHandler: unauthorized attempt from #{user}" if logger + false + end + + # Creates a new issue + def receive_issue + project = target_project + # TODO: make the tracker configurable + tracker = project.trackers.find(:first) + # check permission + raise UnauthorizedAction unless user.allowed_to?(:add_issues, project) + issue = Issue.new(:author => user, :project => project, :tracker => tracker) + issue.subject = email.subject.chomp + issue.description = email.plain_text_body.chomp + issue.save! + add_attachments(issue) + logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info + Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added') + issue + end + + def target_project + # TODO: other ways to specify project: + # * parse the email To field + # * specific project (eg. Setting.mail_handler_target_project) + identifier = if @@handler_options[:project] + @@handler_options[:project] + elsif email.plain_text_body =~ %r{^Project:[ \t]*(.+)$}i + $1 + end + + target = Project.find_by_identifier(identifier.to_s) + raise MissingInformation.new('Unable to determine target project') if target.nil? + target + end + + # Adds a note to an existing issue + def receive_issue_update(issue_id) + issue = Issue.find_by_id(issue_id) return unless issue - - # find user - user = User.find_active(:first, :conditions => {:mail => email.from.first}) - return unless user # check permission - return unless user.allowed_to?(:add_issue_notes, issue.project) - + raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project) # add the note - issue.init_journal(user, email.body.chomp) - issue.save + journal = issue.init_journal(user, email.plain_text_body.chomp) + add_attachments(journal) + issue.save! + logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info + Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') + journal + end + + def add_attachments(obj) + if email.has_attachments? + email.attachments.each do |attachment| + Attachment.create(:container => obj, + :file => attachment, + :author => user, + :content_type => attachment.content_type) + end + end end end + +class TMail::Mail + # Returns body of the first plain text part found if any + def plain_text_body + return @plain_text_body unless @plain_text_body.nil? + p = self.parts.collect {|c| (c.respond_to?(:parts) && !c.parts.empty?) ? c.parts : c}.flatten + plain = p.detect {|c| c.content_type == 'text/plain'} + @plain_text_body = plain.nil? ? self.body : plain.body + end +end + diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake new file mode 100644 index 000000000..dbdbe71fc --- /dev/null +++ b/lib/tasks/email.rake @@ -0,0 +1,37 @@ +# redMine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +desc <<-END_DESC +Read an email from standard input. + +Available options: + * project => identifier of the project the issue should be added to + +Example: + rake redmine:email:receive project=foo RAILS_ENV="production" +END_DESC + +namespace :redmine do + namespace :email do + task :receive => :environment do + options = {} + options[:project] = ENV['project'] if ENV['project'] + + MailHandler.receive(STDIN.read, options) + end + end +end diff --git a/test/fixtures/enabled_modules.yml b/test/fixtures/enabled_modules.yml index 8d1565534..da63bad5d 100644 --- a/test/fixtures/enabled_modules.yml +++ b/test/fixtures/enabled_modules.yml @@ -39,4 +39,8 @@ enabled_modules_010: name: wiki project_id: 3 id: 10 +enabled_modules_011: + name: issue_tracking + project_id: 2 + id: 11 \ No newline at end of file diff --git a/test/fixtures/enumerations.yml b/test/fixtures/enumerations.yml index 5e2615476..22a581ab9 100644 --- a/test/fixtures/enumerations.yml +++ b/test/fixtures/enumerations.yml @@ -19,6 +19,7 @@ enumerations_005: name: Normal id: 5 opt: IPRI + is_default: true enumerations_006: name: High id: 6 diff --git a/test/fixtures/mail_handler/add_note_to_issue.txt b/test/fixtures/mail_handler/add_note_to_issue.txt deleted file mode 100644 index 4fc6b68fb..000000000 --- a/test/fixtures/mail_handler/add_note_to_issue.txt +++ /dev/null @@ -1,14 +0,0 @@ -x-sender: -x-receiver: -Received: from somenet.foo ([127.0.0.1]) by somenet.foo; - Sun, 25 Feb 2007 09:57:56 GMT -Date: Sun, 25 Feb 2007 10:57:56 +0100 -From: jsmith@somenet.foo -To: redmine@somenet.foo -Message-Id: <45e15df440c00_b90238570a27b@osiris.tmail> -In-Reply-To: <45e15df440c29_b90238570a27b@osiris.tmail> -Subject: [Cookbook - Feature #2] -Mime-Version: 1.0 -Content-Type: text/plain; charset=utf-8 - -Note added by mail diff --git a/test/fixtures/mail_handler/ticket_on_given_project.eml b/test/fixtures/mail_handler/ticket_on_given_project.eml new file mode 100644 index 000000000..07c7f16b2 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_on_given_project.eml @@ -0,0 +1,41 @@ +Return-Path: +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" +To: +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. + +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. + +Project: onlinestore + diff --git a/test/fixtures/mail_handler/ticket_reply.eml b/test/fixtures/mail_handler/ticket_reply.eml new file mode 100644 index 000000000..99fcfa0d1 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_reply.eml @@ -0,0 +1,73 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200 +Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris> +From: "John Smith" +To: +References: <485d0ad366c88_d7014663a025f@osiris.tmail> +Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories +Date: Sat, 21 Jun 2008 18:41:39 +0200 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_0067_01C8D3CE.711F9CC0" +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 + +This is a multi-part message in MIME format. + +------=_NextPart_000_0067_01C8D3CE.711F9CC0 +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: quoted-printable + +This is reply +------=_NextPart_000_0067_01C8D3CE.711F9CC0 +Content-Type: text/html; + charset="utf-8" +Content-Transfer-Encoding: quoted-printable + +=EF=BB=BF + + + + + + +
This is=20 +reply
+ +------=_NextPart_000_0067_01C8D3CE.711F9CC0-- + diff --git a/test/fixtures/mail_handler/ticket_with_attachment.eml b/test/fixtures/mail_handler/ticket_with_attachment.eml new file mode 100644 index 000000000..c85f6b4a2 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_with_attachment.eml @@ -0,0 +1,248 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sat, 21 Jun 2008 15:53:25 +0200 +Message-ID: <002301c8d3a6$2cdf6950$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: Ticket created by email with attachment +Date: Sat, 21 Jun 2008 15:53:25 +0200 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_001F_01C8D3B6.F05C5270" +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 + +This is a multi-part message in MIME format. + +------=_NextPart_000_001F_01C8D3B6.F05C5270 +Content-Type: multipart/alternative; + boundary="----=_NextPart_001_0020_01C8D3B6.F05C5270" + + +------=_NextPart_001_0020_01C8D3B6.F05C5270 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +This is a new ticket with attachments +------=_NextPart_001_0020_01C8D3B6.F05C5270 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + + + + + + + +
This is  a new ticket with=20 +attachments
+ +------=_NextPart_001_0020_01C8D3B6.F05C5270-- + +------=_NextPart_000_001F_01C8D3B6.F05C5270 +Content-Type: image/jpeg; + name="Paella.jpg" +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; + filename="Paella.jpg" + +/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcU +FhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgo +KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCACmAMgDASIA +AhEBAxEB/8QAHQAAAgMBAQEBAQAAAAAAAAAABQYABAcDCAIBCf/EADsQAAEDAwMCBQIDBQcFAQAA +AAECAwQABREGEiExQQcTIlFhcYEUMpEVI0Kh0QhSYrHB4fA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4x3Fat4f6okWOY0qKkFv8AKpCgCFp75qVK +xqfUY+MUENmMmv7bHbDV5tqPJjTFcsK6pVgE4+Kz68xy41vZUEKPvUqUovDyufKjmfrVmYbiHd6n +cbis+/WpUqUcMZKdF44n/9k= + +------=_NextPart_000_001F_01C8D3B6.F05C5270-- + diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index d0fc68de8..6bb638f21 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -20,38 +20,52 @@ require File.dirname(__FILE__) + '/../test_helper' class MailHandlerTest < Test::Unit::TestCase fixtures :users, :projects, :enabled_modules, :roles, :members, :issues, :trackers, :enumerations - FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures' - CHARSET = "utf-8" - - include ActionMailer::Quoting - + FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' + def setup - ActionMailer::Base.delivery_method = :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries = [] - - @expected = TMail::Mail.new - @expected.set_content_type "text", "plain", { "charset" => CHARSET } - @expected.mime_version = '1.0' + ActionMailer::Base.deliveries.clear end - def test_add_note_to_issue - raw = read_fixture("add_note_to_issue.txt").join - MailHandler.receive(raw) - - issue = Issue.find(2) - journal = issue.journals.find(:first, :order => "created_on DESC") - assert journal - assert_equal User.find_by_mail("jsmith@somenet.foo"), journal.user - assert_equal "Note added by mail", journal.notes + def test_add_issue + # This email contains: 'Project: onlinestore' + issue = submit_email('ticket_on_given_project.eml') + assert issue.is_a?(Issue) + assert !issue.new_record? + issue.reload + assert_equal 'New ticket on a given project', issue.subject + assert_equal User.find_by_login('jsmith'), issue.author + assert_equal Project.find(2), issue.project + assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') + end + + def test_add_issue_with_attachment_to_specific_project + issue = submit_email('ticket_with_attachment.eml', :project => 'onlinestore') + assert issue.is_a?(Issue) + assert !issue.new_record? + issue.reload + assert_equal 'Ticket created by email with attachment', issue.subject + assert_equal User.find_by_login('jsmith'), issue.author + assert_equal Project.find(2), issue.project + assert_equal 'This is a new ticket with attachments', issue.description + # Attachment properties + assert_equal 1, issue.attachments.size + assert_equal 'Paella.jpg', issue.attachments.first.filename + assert_equal 'image/jpeg', issue.attachments.first.content_type + assert_equal 10790, issue.attachments.first.filesize + end + + def test_add_issue_note + journal = submit_email('ticket_reply.eml') + assert journal.is_a?(Journal) + assert_equal User.find_by_login('jsmith'), journal.user + assert_equal Issue.find(2), journal.journalized + assert_equal 'This is reply', journal.notes end private - def read_fixture(action) - IO.readlines("#{FIXTURES_PATH}/mail_handler/#{action}") - end - - def encode(subject) - quoted_printable(subject, CHARSET) - end + + def submit_email(filename, options={}) + raw = IO.read(File.join(FIXTURES_PATH, filename)) + MailHandler.receive(raw, options) + end end