Added check if sender is system address (show sender as agent in ticket zoom).

This commit is contained in:
Martin Edenhofer 2016-08-19 11:07:53 +02:00
parent d3285340e8
commit 136713c45f
4 changed files with 146 additions and 7 deletions

View file

@ -27,12 +27,36 @@ module Channel::Filter::IdentifySender
user = User.find_by(email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email])
end
if !user
user = user_create(
login: mail[ 'x-zammad-customer-login'.to_sym ] || mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
firstname: mail[ 'x-zammad-customer-firstname'.to_sym ] || mail[:from_display_name],
lastname: mail[ 'x-zammad-customer-lastname'.to_sym ],
email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
)
# get correct customer
if mail[ 'x-zammad-ticket-create-article-sender'.to_sym ] == 'Agent'
# get first recipient and set customer
begin
to = 'raw-to'.to_sym
if mail[to] && mail[to].addrs
items = mail[to].addrs
items.each { |item|
user = user_create(
login: item.address,
firstname: item.display_name,
email: item.address,
)
break
}
end
rescue => e
Rails.logger.error 'ERROR: SenderIsSystemAddress: ' + e.inspect
end
end
if !user
user = user_create(
login: mail[ 'x-zammad-customer-login'.to_sym ] || mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
firstname: mail[ 'x-zammad-customer-firstname'.to_sym ] || mail[:from_display_name],
lastname: mail[ 'x-zammad-customer-lastname'.to_sym ],
email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
)
end
end
create_recipients(mail)
@ -77,7 +101,6 @@ module Channel::Filter::IdentifySender
)
}
end
}
end

View file

@ -0,0 +1,15 @@
class UpdateSettingPostmasterFilter2 < ActiveRecord::Migration
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
Setting.create_if_not_exists(
title: 'Define postmaster filter.',
name: '0012_postmaster_filter_sender_is_system_address',
area: 'Postmaster::PreFilter',
description: 'Define postmaster filter to check if email got created via email as Zammad.',
options: {},
state: 'Channel::Filter::SenderIsSystemAddress',
frontend: false
)
end
end

View file

@ -1875,6 +1875,15 @@ Setting.create_if_not_exists(
state: 'Channel::Filter::Trusted',
frontend: false
)
Setting.create_if_not_exists(
title: 'Define postmaster filter.',
name: '0012_postmaster_filter_sender_is_system_address',
area: 'Postmaster::PreFilter',
description: 'Define postmaster filter to check if email got created via email as Zammad.',
options: {},
state: 'Channel::Filter::SenderIsSystemAddress',
frontend: false
)
Setting.create_if_not_exists(
title: 'Define postmaster filter.',
name: '0015_postmaster_filter_identify_sender',

View file

@ -0,0 +1,92 @@
# encoding: utf-8
require 'test_helper'
class EmailProcessSenderIsSystemAddress < ActiveSupport::TestCase
test 'process with ticket creates and system address check' do
EmailAddress.create_or_update(
channel_id: 1,
realname: 'My System',
email: 'my@system.test',
active: true,
updated_by_id: 1,
created_by_id: 1,
)
subject = "some new subject #{rand(9_999_999)}"
email_raw_string = "From: me@example.com
To: customer@example.com
Subject: #{subject}
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id)
assert_equal(subject, ticket.title)
assert_equal('new', ticket.state.name)
assert_equal('Customer', ticket.create_article_sender.name)
assert_equal('Customer', article.sender.name)
assert_equal('me@example.com', ticket.customer.email)
# check article sender + customer of ticket
subject = "some new subject #{rand(9_999_999)}"
email_raw_string = "From: my@system.test
To: me@example.com, customer@example.com
Subject: #{subject}
Message-ID: <123456789-1@linuxhotel.de>
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id)
p "ticket: #{ticket.inspect}"
assert_equal(subject, ticket.title)
assert_equal('open', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name)
assert_equal('me@example.com', ticket.customer.email)
# check if follow up based on inital system sender address
setting_orig = Setting.get('postmaster_follow_up_search_in')
Setting.set('postmaster_follow_up_search_in', [])
# follow up possible because same subject
email_raw_string = "From: me@example.com
To: my@system.test
Subject: #{subject}
Message-ID: <123456789-2@linuxhotel.de>
References: <123456789-1@linuxhotel.de>
Some Text"
ticket_p2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket2 = Ticket.find(ticket_p2.id)
article = Ticket::Article.find(article_p.id)
assert_equal(subject, ticket2.title)
assert_equal(ticket.id, ticket2.id)
# follow up not possible because subject has changed
subject = "new subject without ticket ref #{rand(9_999_999)}"
email_raw_string = "From: me@example.com
To: my@system.test
Subject: #{subject}
Message-ID: <123456789-3@linuxhotel.de>
References: <123456789-1@linuxhotel.de>
Some Text"
ticket_p2, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket2 = Ticket.find(ticket_p2.id)
article = Ticket::Article.find(article_p.id)
assert_not_equal(ticket.id, ticket2.id)
assert_equal(subject, ticket2.title)
assert_equal('new', ticket2.state.name)
Setting.set('postmaster_follow_up_search_in', setting_orig)
end
end