email_process_auto_response_test.rb 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class EmailProcessAutoResponseTest < ActiveSupport::TestCase
  4. test 'process auto reply check' do
  5. roles = Role.where(name: 'Agent')
  6. agent1 = User.create_or_update(
  7. login: 'ticket-auto-responder-agent1@example.com',
  8. firstname: 'AutoReponder',
  9. lastname: 'Agent1',
  10. email: 'ticket-auto-responder-agent1@example.com',
  11. password: 'agentpw',
  12. active: true,
  13. roles: roles,
  14. groups: Group.all,
  15. updated_by_id: 1,
  16. created_by_id: 1,
  17. )
  18. Trigger.create_or_update(
  19. name: 'auto reply',
  20. condition: {
  21. 'ticket.state_id' => {
  22. 'operator' => 'is',
  23. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  24. }
  25. },
  26. perform: {
  27. 'notification.email' => {
  28. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  29. 'recipient' => 'ticket_customer',
  30. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  31. },
  32. 'ticket.priority_id' => {
  33. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  34. },
  35. 'ticket.tags' => {
  36. 'operator' => 'add',
  37. 'value' => 'aa, kk',
  38. },
  39. },
  40. disable_notification: true,
  41. active: true,
  42. created_by_id: 1,
  43. updated_by_id: 1,
  44. )
  45. email_raw_string = "From: me@example.com
  46. To: customer@example.com
  47. Subject: some new subject
  48. Some Text"
  49. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  50. assert_equal(true, mail['x-zammad-send-auto-response'.to_sym])
  51. Scheduler.worker(true)
  52. assert_equal(2, article_p.ticket.articles.count)
  53. email_raw_string = "From: me@example.com
  54. To: customer@example.com
  55. Subject: some new subject
  56. X-Loop: yes
  57. Some Text"
  58. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  59. assert_equal(false, mail['x-zammad-send-auto-response'.to_sym])
  60. Scheduler.worker(true)
  61. assert_equal(1, article_p.ticket.articles.count)
  62. email_raw_string = "From: me@example.com
  63. To: customer@example.com
  64. Subject: some new subject
  65. Precedence: Bulk
  66. Some Text"
  67. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  68. assert_equal(false, mail['x-zammad-send-auto-response'.to_sym])
  69. email_raw_string = "From: me@example.com
  70. To: customer@example.com
  71. Subject: some new subject
  72. Auto-Submitted: auto-generated
  73. Some Text"
  74. Scheduler.worker(true)
  75. assert_equal(1, article_p.ticket.articles.count)
  76. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  77. assert_equal(false, mail['x-zammad-send-auto-response'.to_sym])
  78. email_raw_string = "From: me@example.com
  79. To: customer@example.com
  80. Subject: some new subject
  81. X-Auto-Response-Suppress: All
  82. Some Text"
  83. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  84. assert_equal(false, mail['x-zammad-send-auto-response'.to_sym])
  85. Scheduler.worker(true)
  86. assert_equal(1, article_p.ticket.articles.count)
  87. email_raw_string = "Return-Path: <XX@XX.XX>
  88. X-Original-To: sales@znuny.com
  89. Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])
  90. by arber.znuny.com (Postfix) with ESMTPS id C3AED5FE2E
  91. for <sales@znuny.com>; Mon, 22 Aug 2016 19:03:15 +0200 (CEST)
  92. Received: by mail-qk0-f170.example.com with SMTP id t7so87721720qkh.1
  93. for <sales@znuny.com>; Mon, 22 Aug 2016 10:03:15 -0700 (PDT)
  94. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  95. d=XX.XX; s=example;
  96. h=to:from:date:message-id:subject:mime-version:precedence
  97. :auto-submitted:content-transfer-encoding:content-disposition;
  98. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  99. b=CIk3PLELgjOCagyiFFbd6rlb8ZRDGYRUrg5Dntxa7e5X+PT4cgL+IE13N9TFkK8ZUJ
  100. GohlaPLGiBymIYLTtYMKUpcf22oiX8ZgGiSu1aEMC1Gsa1ZDf+vpy4kd4+7EecRT3IWF
  101. 4RafQxeaqe67budhQpO1Z6UAel6BdJj0xguKM=
  102. X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  103. d=1e100.net; s=20130820;
  104. h=x-gm-message-state:to:from:date:message-id:subject:mime-version
  105. :precedence:auto-submitted:content-transfer-encoding
  106. :content-disposition;
  107. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  108. b=PYULo3xigc4O/cuNZ79OathQ5HDMFWWIwUxz6CHbpXDQR5k3EPy/skJU1992hVz9Rl
  109. xiGwScBCkMqOjlxHjQSWhFJIxNtdvMk4m0bixBZ79IEvRuQa9cEbqjf6efnV58br5ftQ
  110. 2osHrtQczoSqLE/d61/o102RfQ0avVyX8XNJik0iepg8MiCY7LTOE9hrbnuDDLxgQecH
  111. rMEfkR7bafcUj1YEto5Vd7uV11cVZYx8UIQqVAVbfygv8dTSFeOzz3NyM0M41rRexfYH
  112. 79Yi5i7z/Wk6q2427wkJ3FIR1B7VQVQEmcq/Texbch+gAXPGBNPUHdg2WHt7NXGktrHL
  113. d3DA==
  114. X-Gm-Message-State: AE9vXwMCTnihGiG/tc7xNNlhFLcEK6DPp7otypJg5e4alD3xGK2R707BP29druIi/mcdNyaHg1vP5lSZ8EvrwvOF8iA0HNFhECGjBTJ40YrSJAR8E89xVwxFv/er+U3vEpqmPmt+hL4QhxK/+D2gKOcHSxku
  115. X-Received: by 10.1.1.1 with SMTP id 17mr25015996qkf.279.1471885393931;
  116. Mon, 22 Aug 2016 10:03:13 -0700 (PDT)
  117. To: sales@znuny.com
  118. From: \"XXX\" <XX@XX.XX>
  119. Date: Mon, 22 Aug 2016 10:03:13 -0700
  120. Message-ID: <CA+kqV8PH1DU+zcSx3M00Hrm_oJedRLjbgAUdoi9p0+sMwYsyUg@mail.gmail.com>
  121. Subject: XX PieroXXway - vacation response RE: Callback Request: XX XX [Ticket#1118974]
  122. MIME-Version: 1.0
  123. Precedence: bulk
  124. X-Autoreply: yes
  125. Auto-Submitted: auto-replied
  126. Content-Type: text/html; charset=UTF-8
  127. Content-Transfer-Encoding: quoted-printable
  128. Content-Disposition: inline
  129. test"
  130. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  131. assert_equal(false, mail['x-zammad-send-auto-response'.to_sym])
  132. Scheduler.worker(true)
  133. assert_equal(1, article_p.ticket.articles.count)
  134. # add an agent notification
  135. Trigger.create_or_update(
  136. name: 'additional agent notification',
  137. condition: {
  138. 'ticket.state_id' => {
  139. 'operator' => 'is',
  140. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  141. }
  142. },
  143. perform: {
  144. 'notification.email' => {
  145. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  146. 'recipient' => 'ticket_agents',
  147. 'subject' => 'New Ticket add. info (#{ticket.title})!',
  148. },
  149. 'ticket.priority_id' => {
  150. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  151. },
  152. 'ticket.tags' => {
  153. 'operator' => 'add',
  154. 'value' => 'aa, kk',
  155. },
  156. },
  157. disable_notification: true,
  158. active: true,
  159. created_by_id: 1,
  160. updated_by_id: 1,
  161. )
  162. email_raw_string = "From: me@example.com
  163. To: customer@example.com
  164. Subject: some new subject
  165. X-Loop: yes
  166. Some Text"
  167. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  168. assert_equal(false, mail['x-zammad-send-auto-response'.to_sym])
  169. Scheduler.worker(true)
  170. assert_equal(2, article_p.ticket.articles.count)
  171. article_customer = article_p.ticket.articles.first
  172. assert_equal('me@example.com', article_customer.from)
  173. assert_equal('customer@example.com', article_customer.to)
  174. assert_equal('Customer', article_customer.sender.name)
  175. assert_equal('email', article_customer.type.name)
  176. article_notification = article_p.ticket.articles.last
  177. assert_match(/New Ticket add. info/, article_notification.subject)
  178. assert_no_match(/me@example.com/, article_notification.to)
  179. assert_match(/#{agent1.email}/, article_notification.to)
  180. assert_equal('System', article_notification.sender.name)
  181. assert_equal('email', article_notification.type.name)
  182. Trigger.destroy_all
  183. end
  184. end