diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index fe587dbd52..cc77349acb 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -132,22 +132,16 @@ class MailHandler < ActionMailer::Base private - MESSAGE_ID_RE = %r{^ +Subject: [OpenProject - General discussion - msg12559] Test + fields in user stories +Mime-Version: 1.0 +Content-Type: multipart/alternative; + boundary="--==_mimepart_6050cdc2e4db_2257939a87567a"; + charset=UTF-8 +Content-Transfer-Encoding: 7bit +X-OpenProject-Project: openproject +X-OpenProject-Wiki-Page-Id: 12559 +X-OpenProject-Type: Forum + + +----==_mimepart_6050cdc2e4db_2257939a87567a +Content-Type: text/plain; + charset=UTF-8 +Content-Transfer-Encoding: 7bit + + + + + +http://localhost:3000/topics/12559?r=12559#message-12559 +Test User + +Test message + + +-- +You have received this notification because you have either subscribed to it, or are involved in it. +To change your notification preferences, please click here: https://community.openproject.org/my/mail_notifications + +----==_mimepart_6050cdc2e4db_2257939a87567a +Content-Type: text/html; + charset=UTF-8 +Content-Transfer-Encoding: 7bit + + + + + + +

+ OpenProject - General discussion: Ready-If and Done-If fields in user stories +

+Test user + +

Test message

+ + +
+

You have received this notification because you have either subscribed to it, or are involved in it.
+To change your notification preferences, please click here: https://community.openproject.org/my/mail_notifications

+ + + +----==_mimepart_6050cdc2e4db_2257939a87567a-- diff --git a/spec/fixtures/mail_handler/work_package_reply.eml b/spec/fixtures/mail_handler/work_package_reply.eml new file mode 100644 index 0000000000..c1aa58ab53 --- /dev/null +++ b/spec/fixtures/mail_handler/work_package_reply.eml @@ -0,0 +1,108 @@ +Date: Tue, 16 Mar 2021 15:17:04 +0100 +To: notifications@openproject.com +From: user@example.org +Message-ID: +References: +Subject: test - new Task #34540: asdf +Mime-Version: 1.0 +Content-Type: multipart/alternative; + boundary="--==_mimepart_6050bdd0cb97_2257939a8755e5"; + charset=UTF-8 +Content-Transfer-Encoding: 7bit +X-OpenProject-Project: test +X-OpenProject-Issue-Id: 34540 +X-OpenProject-Issue-Author: admin +X-OpenProject-Type: WorkPackage +X-OpenProject-Issue-Assignee: reader + + +----==_mimepart_6050bdd0cb97_2257939a8755e5 +Content-Type: text/plain; + charset=UTF-8 +Content-Transfer-Encoding: 7bit + + + + + +Work package #34540 has been updated by admin lastname. + + Assignee set to reader reader + + +---------------------------------------- + +Task #34540: asdf +http://localhost:3000/work_packages/34540 + +Author: admin lastname +Status: new +Priority: Medium +Assignee: reader reader +Accountable: +Category: +Version: test version +Start date: +Finish date: +Estimated time: +Module: +Onboarding Activity: +Ordered by: +Prio board: + + + + + +-- +You have received this notification because you have either subscribed to it, or are involved in it. +To change your notification preferences, please click here: https://community.openproject.org/my/mail_notifications + +----==_mimepart_6050bdd0cb97_2257939a8755e5 +Content-Type: text/html; + charset=UTF-8 +Content-Transfer-Encoding: 7bit + + + + + + Work package #34540 has been updated by admin lastname. + + +
+ +

Task #34540: asdf

+ + + + + + + +
+

You have received this notification because you have either subscribed to it, or are involved in it.
+To change your notification preferences, please click here: https://community.openproject.org/my/mail_notifications

+ + + +----==_mimepart_6050bdd0cb97_2257939a8755e5-- diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb index f0e6d841d9..d9d28dae05 100644 --- a/spec/models/mail_handler_spec.rb +++ b/spec/models/mail_handler_spec.rb @@ -605,13 +605,46 @@ describe MailHandler, type: :model do end end + describe '#dispatch_target_from_message_id' do + let!(:mail_user) { FactoryBot.create :admin, mail: 'user@example.org' } + let(:instance) do + mh = MailHandler.new + mh.options = {} + mh + end + subject { instance.receive mail } + + context 'receiving reply from work package' do + let(:mail) { Mail.new(read_email('work_package_reply.eml')) } + + it 'calls the work package reply' do + expect(instance).to receive(:receive_work_package_reply).with(34540) + + subject + end + end + + context 'receiving reply from message' do + let(:mail) { Mail.new(read_email('message_reply.eml')) } + + it 'calls the work package reply' do + expect(instance).to receive(:receive_message_reply).with(12559) + + subject + end + end + end + private FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' + def read_email(filename) + IO.read(File.join(FIXTURES_PATH, filename)) + end + def submit_email(filename, options = {}) - raw = IO.read(File.join(FIXTURES_PATH, filename)) - MailHandler.receive(raw, options) + MailHandler.receive(read_email(filename), options) end def work_package_created(work_package)