]> source.dussan.org Git - redmine.git/commitdiff
Accept email from anonymous users with an empty from address. #5604
authorEric Davis <edavis@littlestreamsoftware.com>
Sat, 19 Jun 2010 19:24:17 +0000 (19:24 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Sat, 19 Jun 2010 19:24:17 +0000 (19:24 +0000)
Contributed by Andrew Fenn

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3783 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/fixtures/mail_handler/ticket_by_empty_user.eml [new file with mode: 0644]
test/unit/mail_handler_test.rb

index ae204b4f75077788814a8745aea409ca89c56634..2b57e1ab48d35a750ed0c74fe83e7ee37f09d88a 100644 (file)
@@ -49,7 +49,7 @@ class MailHandler < ActionMailer::Base
       logger.info  "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" if logger && logger.info
       return false
     end
-    @user = User.find_by_mail(sender_email)
+    @user = User.find_by_mail(sender_email) if sender_email.present?
     if @user && !@user.active?
       logger.info  "MailHandler: ignoring email from non-active user [#{@user.login}]" if logger && logger.info
       return false
diff --git a/test/fixtures/mail_handler/ticket_by_empty_user.eml b/test/fixtures/mail_handler/ticket_by_empty_user.eml
new file mode 100644 (file)
index 0000000..e0d168a
--- /dev/null
@@ -0,0 +1,17 @@
+Return-Path: <john.doe@somenet.foo>\r
+Received: from osiris ([127.0.0.1])\r
+       by OSIRIS\r
+       with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200\r
+Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>\r
+To: <redmine@somenet.foo>\r
+Subject: Ticket by unknown user\r
+Date: Sun, 22 Jun 2008 12:28:07 +0200\r
+MIME-Version: 1.0\r
+Content-Type: text/plain;\r
+       format=flowed;\r
+       charset="iso-8859-1";\r
+       reply-type=original\r
+Content-Transfer-Encoding: 7bit\r
+\r
+This is a ticket submitted by an unknown user.\r
+\r
index 29659daae4baf814f1936cd4569fc4b436e6ab72..467084f1b37775551c036d6334e1f9b29058f8c5 100644 (file)
@@ -169,6 +169,15 @@ class MailHandlerTest < ActiveSupport::TestCase
       assert issue.author.anonymous?
     end
   end
+
+  def test_add_issue_by_anonymous_user_with_no_from_address
+    Role.anonymous.add_permission!(:add_issues)
+    assert_no_difference 'User.count' do
+      issue = submit_email('ticket_by_empty_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
+      assert issue.is_a?(Issue)
+      assert issue.author.anonymous?
+    end
+  end
   
   def test_add_issue_by_anonymous_user_on_private_project
     Role.anonymous.add_permission!(:add_issues)