123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882 |
- # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
- require 'test_helper'
- class EmailProcessAutoResponseTest < ActiveSupport::TestCase
- include BackgroundJobsHelper
- test 'process auto reply check - 1' do
- roles = Role.where(name: 'Agent')
- agent1 = User.create!(
- login: 'ticket-auto-responder-agent1@example.com',
- firstname: 'AutoReponder',
- lastname: 'Agent1',
- email: 'ticket-auto-responder-agent1@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: Group.all,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Trigger.create!(
- name: '002 auto reply',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'create',
- },
- 'ticket.state_id' => {
- 'operator' => 'is',
- 'value' => Ticket::State.lookup(name: 'new').id.to_s,
- }
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
- },
- 'ticket.priority_id' => {
- 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
- },
- 'ticket.tags' => {
- 'operator' => 'add',
- 'value' => 'aa, kk, auto-reply',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(2, article_p.ticket.articles.count)
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- X-Loop: yes
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Precedence: Bulk
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Auto-Submitted: auto-generated
- Some Text"
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- _ticket_p, _article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- X-Auto-Response-Suppress: All
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- fqdn = Setting.get('fqdn')
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Message-ID: <1234@#{fqdn}>
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- fqdn = Setting.get('fqdn')
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Message-ID: <1234@not_matching.#{fqdn}>
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(2, article_p.ticket.articles.count)
- email_raw_string = "Return-Path: <XX@XX.XX>
- X-Original-To: sales@zammad.com
- Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])
- by mail.zammad.com (Postfix) with ESMTPS id C3AED5FE2E
- for <sales@zammad.com>; Mon, 22 Aug 2016 19:03:15 +0200 (CEST)
- Received: by mail-qk0-f170.example.com with SMTP id t7so87721720qkh.1
- for <sales@zammad.com>; Mon, 22 Aug 2016 10:03:15 -0700 (PDT)
- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
- d=XX.XX; s=example;
- h=to:from:date:message-id:subject:mime-version:precedence
- :auto-submitted:content-transfer-encoding:content-disposition;
- bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
- b=CIk3PLELgjOCagyiFFbd6rlb8ZRDGYRUrg5Dntxa7e5X+PT4cgL+IE13N9TFkK8ZUJ
- GohlaPLGiBymIYLTtYMKUpcf22oiX8ZgGiSu1aEMC1Gsa1ZDf+vpy4kd4+7EecRT3IWF
- 4RafQxeaqe67budhQpO1Z6UAel6BdJj0xguKM=
- X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
- d=1e100.net; s=20130820;
- h=x-gm-message-state:to:from:date:message-id:subject:mime-version
- :precedence:auto-submitted:content-transfer-encoding
- :content-disposition;
- bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
- b=PYULo3xigc4O/cuNZ79OathQ5HDMFWWIwUxz6CHbpXDQR5k3EPy/skJU1992hVz9Rl
- xiGwScBCkMqOjlxHjQSWhFJIxNtdvMk4m0bixBZ79IEvRuQa9cEbqjf6efnV58br5ftQ
- 2osHrtQczoSqLE/d61/o102RfQ0avVyX8XNJik0iepg8MiCY7LTOE9hrbnuDDLxgQecH
- rMEfkR7bafcUj1YEto5Vd7uV11cVZYx8UIQqVAVbfygv8dTSFeOzz3NyM0M41rRexfYH
- 79Yi5i7z/Wk6q2427wkJ3FIR1B7VQVQEmcq/Texbch+gAXPGBNPUHdg2WHt7NXGktrHL
- d3DA==
- X-Gm-Message-State: AE9vXwMCTnihGiG/tc7xNNlhFLcEK6DPp7otypJg5e4alD3xGK2R707BP29druIi/mcdNyaHg1vP5lSZ8EvrwvOF8iA0HNFhECGjBTJ40YrSJAR8E89xVwxFv/er+U3vEpqmPmt+hL4QhxK/+D2gKOcHSxku
- X-Received: by 10.1.1.1 with SMTP id 17mr25015996qkf.279.1471885393931;
- Mon, 22 Aug 2016 10:03:13 -0700 (PDT)
- To: sales@zammad.com
- From: \"XXX\" <XX@XX.XX>
- Date: Mon, 22 Aug 2016 10:03:13 -0700
- Message-ID: <CA+kqV8PH1DU+zcSx3M00Hrm_oJedRLjbgAUdoi9p0+sMwYsyUg@mail.gmail.com>
- Subject: XX PieroXXway - vacation response RE: Callback Request: XX XX [Ticket#1118974]
- MIME-Version: 1.0
- Precedence: bulk
- X-Autoreply: yes
- Auto-Submitted: auto-replied
- Content-Type: text/html; charset=UTF-8
- Content-Transfer-Encoding: quoted-printable
- Content-Disposition: inline
- test"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- # add an agent notification
- Trigger.create!(
- name: '001 additional agent notification',
- condition: {
- 'ticket.state_id' => {
- 'operator' => 'is',
- 'value' => Ticket::State.lookup(name: 'new').id.to_s,
- }
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
- 'recipient' => 'ticket_agents',
- 'subject' => 'New Ticket add. info (#{ticket.title})!',
- },
- 'ticket.priority_id' => {
- 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
- },
- 'ticket.tags' => {
- 'operator' => 'add',
- 'value' => 'aa, kk, agent-notification',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- X-Loop: yes
- Some Text"
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert_equal(3, tags.count)
- assert_equal(2, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles.first
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', true)
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert_equal(3, tags.count)
- assert_equal(2, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles.first
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', false)
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Some Text"
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert(tags.include?('auto-reply'))
- assert_equal(3, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles[0]
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- article_auto_reply = article_p.ticket.articles[2]
- assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
- assert_match(%r{me@example.com}, article_auto_reply.to)
- assert_equal('System', article_auto_reply.sender.name)
- assert_equal('email', article_auto_reply.type.name)
- Setting.set('ticket_trigger_recursive', true)
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert(tags.include?('auto-reply'))
- assert_equal(3, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles[0]
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- article_auto_reply = article_p.ticket.articles[2]
- assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
- assert_match(%r{me@example.com}, article_auto_reply.to)
- assert_equal('System', article_auto_reply.sender.name)
- assert_equal('email', article_auto_reply.type.name)
- end
- test 'process auto reply check - 2' do
- roles = Role.where(name: 'Agent')
- agent1 = User.create!(
- login: 'ticket-auto-responder-agent1@example.com',
- firstname: 'AutoReponder',
- lastname: 'Agent1',
- email: 'ticket-auto-responder-agent1@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: Group.all,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Trigger.create!(
- name: '001 auto reply',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'create',
- },
- 'ticket.state_id' => {
- 'operator' => 'is',
- 'value' => Ticket::State.lookup(name: 'new').id.to_s,
- }
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
- },
- 'ticket.priority_id' => {
- 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
- },
- 'ticket.tags' => {
- 'operator' => 'add',
- 'value' => 'aa, kk, auto-reply',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(2, article_p.ticket.articles.count)
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- X-Loop: yes
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Precedence: Bulk
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Auto-Submitted: auto-generated
- Some Text"
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- _ticket_p, _article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- X-Auto-Response-Suppress: All
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- fqdn = Setting.get('fqdn')
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Message-ID: <1234@#{fqdn}>
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- fqdn = Setting.get('fqdn')
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Message-ID: <1234@not_matching.#{fqdn}>
- Some Text"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(2, article_p.ticket.articles.count)
- email_raw_string = "Return-Path: <XX@XX.XX>
- X-Original-To: sales@zammad.com
- Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])
- by mail.zammad.com (Postfix) with ESMTPS id C3AED5FE2E
- for <sales@zammad.com>; Mon, 22 Aug 2016 19:03:15 +0200 (CEST)
- Received: by mail-qk0-f170.example.com with SMTP id t7so87721720qkh.1
- for <sales@zammad.com>; Mon, 22 Aug 2016 10:03:15 -0700 (PDT)
- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
- d=XX.XX; s=example;
- h=to:from:date:message-id:subject:mime-version:precedence
- :auto-submitted:content-transfer-encoding:content-disposition;
- bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
- b=CIk3PLELgjOCagyiFFbd6rlb8ZRDGYRUrg5Dntxa7e5X+PT4cgL+IE13N9TFkK8ZUJ
- GohlaPLGiBymIYLTtYMKUpcf22oiX8ZgGiSu1aEMC1Gsa1ZDf+vpy4kd4+7EecRT3IWF
- 4RafQxeaqe67budhQpO1Z6UAel6BdJj0xguKM=
- X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
- d=1e100.net; s=20130820;
- h=x-gm-message-state:to:from:date:message-id:subject:mime-version
- :precedence:auto-submitted:content-transfer-encoding
- :content-disposition;
- bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
- b=PYULo3xigc4O/cuNZ79OathQ5HDMFWWIwUxz6CHbpXDQR5k3EPy/skJU1992hVz9Rl
- xiGwScBCkMqOjlxHjQSWhFJIxNtdvMk4m0bixBZ79IEvRuQa9cEbqjf6efnV58br5ftQ
- 2osHrtQczoSqLE/d61/o102RfQ0avVyX8XNJik0iepg8MiCY7LTOE9hrbnuDDLxgQecH
- rMEfkR7bafcUj1YEto5Vd7uV11cVZYx8UIQqVAVbfygv8dTSFeOzz3NyM0M41rRexfYH
- 79Yi5i7z/Wk6q2427wkJ3FIR1B7VQVQEmcq/Texbch+gAXPGBNPUHdg2WHt7NXGktrHL
- d3DA==
- X-Gm-Message-State: AE9vXwMCTnihGiG/tc7xNNlhFLcEK6DPp7otypJg5e4alD3xGK2R707BP29druIi/mcdNyaHg1vP5lSZ8EvrwvOF8iA0HNFhECGjBTJ40YrSJAR8E89xVwxFv/er+U3vEpqmPmt+hL4QhxK/+D2gKOcHSxku
- X-Received: by 10.1.1.1 with SMTP id 17mr25015996qkf.279.1471885393931;
- Mon, 22 Aug 2016 10:03:13 -0700 (PDT)
- To: sales@zammad.com
- From: \"XXX\" <XX@XX.XX>
- Date: Mon, 22 Aug 2016 10:03:13 -0700
- Message-ID: <CA+kqV8PH1DU+zcSx3M00Hrm_oJedRLjbgAUdoi9p0+sMwYsyUg@mail.gmail.com>
- Subject: XX PieroXXway - vacation response RE: Callback Request: XX XX [Ticket#1118974]
- MIME-Version: 1.0
- Precedence: bulk
- X-Autoreply: yes
- Auto-Submitted: auto-replied
- Content-Type: text/html; charset=UTF-8
- Content-Transfer-Encoding: quoted-printable
- Content-Disposition: inline
- test"
- _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- assert_equal(1, article_p.ticket.articles.count)
- # add an agent notification
- Trigger.create!(
- name: '002 additional agent notification',
- condition: {
- 'ticket.state_id' => {
- 'operator' => 'is',
- 'value' => Ticket::State.lookup(name: 'new').id.to_s,
- }
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
- 'recipient' => 'ticket_agents',
- 'subject' => 'New Ticket add. info (#{ticket.title})!',
- },
- 'ticket.priority_id' => {
- 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
- },
- 'ticket.tags' => {
- 'operator' => 'add',
- 'value' => 'aa, kk, agent-notification',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- X-Loop: yes
- Some Text"
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert_equal(3, tags.count)
- assert_equal(2, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles.first
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', true)
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert_equal(3, tags.count)
- assert_equal(2, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles.first
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', false)
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Some Text"
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert(tags.include?('auto-reply'))
- assert_equal(3, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles[0]
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_auto_reply = article_p.ticket.articles[1]
- assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
- assert_match(%r{me@example.com}, article_auto_reply.to)
- assert_equal('System', article_auto_reply.sender.name)
- assert_equal('email', article_auto_reply.type.name)
- article_notification = article_p.ticket.articles[2]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', true)
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('new', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert(tags.include?('auto-reply'))
- assert_equal(3, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles[0]
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_auto_reply = article_p.ticket.articles[1]
- assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
- assert_match(%r{me@example.com}, article_auto_reply.to)
- assert_equal('System', article_auto_reply.sender.name)
- assert_equal('email', article_auto_reply.type.name)
- article_notification = article_p.ticket.articles[2]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- end
- test 'process auto reply check - recursive' do
- roles = Role.where(name: 'Agent')
- agent1 = User.create!(
- login: 'ticket-auto-responder-agent1@example.com',
- firstname: 'AutoReponder',
- lastname: 'Agent1',
- email: 'ticket-auto-responder-agent1@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: Group.all,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Trigger.create!(
- name: '001 auto reply',
- condition: {
- 'ticket.action' => {
- 'operator' => 'is',
- 'value' => 'create',
- },
- 'ticket.state_id' => {
- 'operator' => 'is',
- 'value' => Ticket::State.lookup(name: 'open').id.to_s,
- }
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
- 'recipient' => 'ticket_customer',
- 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
- },
- 'ticket.priority_id' => {
- 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
- },
- 'ticket.tags' => {
- 'operator' => 'add',
- 'value' => 'aa, kk, auto-reply',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- # add an agent notification
- Trigger.create!(
- name: '002 additional agent notification',
- condition: {
- 'ticket.state_id' => {
- 'operator' => 'is',
- 'value' => Ticket::State.lookup(name: 'new').id.to_s,
- }
- },
- perform: {
- 'notification.email' => {
- 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
- 'recipient' => 'ticket_agents',
- 'subject' => 'New Ticket add. info (#{ticket.title})!',
- },
- 'ticket.priority_id' => {
- 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
- },
- 'ticket.state_id' => {
- 'value' => Ticket::State.lookup(name: 'open').id.to_s,
- },
- 'ticket.tags' => {
- 'operator' => 'add',
- 'value' => 'aa, kk, agent-notification',
- },
- },
- disable_notification: true,
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- X-Loop: yes
- Some Text"
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('open', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert_equal(3, tags.count)
- assert_equal(2, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles.first
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', true)
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('open', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert_equal(3, tags.count)
- assert_equal(2, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles.first
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', false)
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: some new subject
- Some Text"
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('open', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert_equal(2, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles[0]
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- Setting.set('ticket_trigger_recursive', true)
- ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail[:'x-zammad-send-auto-response'])
- perform_enqueued_jobs
- tags = ticket_p.tag_list
- assert_equal('open', ticket_p.state.name)
- assert_equal('3 high', ticket_p.priority.name)
- assert(tags.include?('aa'))
- assert(tags.include?('kk'))
- assert(tags.include?('agent-notification'))
- assert(tags.include?('auto-reply'))
- assert_equal(3, article_p.ticket.articles.count)
- article_customer = article_p.ticket.articles[0]
- assert_equal('me@example.com', article_customer.from)
- assert_equal('customer@example.com', article_customer.to)
- assert_equal('Customer', article_customer.sender.name)
- assert_equal('email', article_customer.type.name)
- article_notification = article_p.ticket.articles[1]
- assert_match(%r{New Ticket add. info}, article_notification.subject)
- assert_no_match(%r{me@example.com}, article_notification.to)
- assert_match(%r{#{agent1.email}}, article_notification.to)
- assert_equal('System', article_notification.sender.name)
- assert_equal('email', article_notification.type.name)
- article_auto_reply = article_p.ticket.articles[2]
- assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
- assert_match(%r{me@example.com}, article_auto_reply.to)
- assert_equal('System', article_auto_reply.sender.name)
- assert_equal('email', article_auto_reply.type.name)
- end
- end
|