From dd5d4ca48b9e7575a0d3a1549ec7eeb4213c0ec1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 13 May 2016 11:32:35 +0200 Subject: [PATCH] Fixed db postmaster filter on follow ups. --- app/models/channel/email_parser.rb | 3 ++ test/unit/email_postmaster_test.rb | 69 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 9bc86c2fb..d922b8ecd 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -551,6 +551,9 @@ retrns # check if attribute exists header = "x-zammad-#{header_name}-#{key}" + if suffix + header = "x-zammad-#{header_name}-#{suffix}-#{key}" + end if mail[ header.to_sym ] Rails.logger.info "header #{header} found #{mail[ header.to_sym ]}" item_object[key] = mail[ header.to_sym ] diff --git a/test/unit/email_postmaster_test.rb b/test/unit/email_postmaster_test.rb index 0ea668a52..47ffedebd 100644 --- a/test/unit/email_postmaster_test.rb +++ b/test/unit/email_postmaster_test.rb @@ -200,6 +200,75 @@ Some Text' assert_equal(false, article.internal) PostmasterFilter.destroy_all + + # follow up with create post master filter test + PostmasterFilter.create( + name: 'used - empty selector', + match: { + from: { + operator: 'contains', + value: 'example.com', + }, + }, + perform: { + 'X-Zammad-Ticket-group_id' => { + value: group2.id, + }, + }, + channel: 'email', + active: true, + created_by_id: 1, + updated_by_id: 1, + ) + + data = 'From: Some Body +To: Bob +Cc: any@example.com +Subject: follow up with create post master filter test + +Some Text' + + parser = Channel::EmailParser.new + ticket, article, user = parser.process( { trusted: false }, data ) + + assert_equal(group2.name, ticket.group.name) + assert_equal('2 normal', ticket.priority.name) + assert_equal('follow up with create post master filter test', ticket.title) + + assert_equal('Customer', article.sender.name) + assert_equal('email', article.type.name) + assert_equal(false, article.internal) + + # move ticket + ticket.group = group1 + ticket.save + Observer::Transaction.commit + + data = "From: me@example.com +To: customer@example.com +Subject: #{ticket.subject_build('some new subject')} + +Some Text" + + article_count = ticket.articles.count + + parser = Channel::EmailParser.new + ticket_followup, article, user = parser.process( { trusted: false }, data ) + + # check if group is still the old one + assert_equal(ticket.id, ticket_followup.id) + assert_equal(group1.name, ticket_followup.group.name) + assert_equal(group1.name, ticket_followup.group.name) + assert_equal('2 normal', ticket_followup.priority.name) + assert_equal('follow up with create post master filter test', ticket_followup.title) + + assert_equal('Customer', article.sender.name) + assert_equal('email', article.type.name) + assert_equal(false, article.internal) + assert_equal(article_count+1, ticket_followup.articles.count) + + PostmasterFilter.destroy_all + end end