email_process_auto_response_test.rb 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'test_helper'
  3. class EmailProcessAutoResponseTest < ActiveSupport::TestCase
  4. include BackgroundJobsHelper
  5. test 'process auto reply check - 1' do
  6. roles = Role.where(name: 'Agent')
  7. agent1 = User.create!(
  8. login: 'ticket-auto-responder-agent1@example.com',
  9. firstname: 'AutoReponder',
  10. lastname: 'Agent1',
  11. email: 'ticket-auto-responder-agent1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. roles: roles,
  15. groups: Group.all,
  16. updated_by_id: 1,
  17. created_by_id: 1,
  18. )
  19. Trigger.create!(
  20. name: '002 auto reply',
  21. condition: {
  22. 'ticket.action' => {
  23. 'operator' => 'is',
  24. 'value' => 'create',
  25. },
  26. 'ticket.state_id' => {
  27. 'operator' => 'is',
  28. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  29. }
  30. },
  31. perform: {
  32. 'notification.email' => {
  33. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  34. 'recipient' => 'ticket_customer',
  35. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  36. },
  37. 'ticket.priority_id' => {
  38. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  39. },
  40. 'ticket.tags' => {
  41. 'operator' => 'add',
  42. 'value' => 'aa, kk, auto-reply',
  43. },
  44. },
  45. disable_notification: true,
  46. active: true,
  47. created_by_id: 1,
  48. updated_by_id: 1,
  49. )
  50. email_raw_string = "From: me@example.com
  51. To: customer@example.com
  52. Subject: some new subject
  53. Some Text"
  54. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  55. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  56. perform_enqueued_jobs
  57. assert_equal(2, article_p.ticket.articles.count)
  58. email_raw_string = "From: me@example.com
  59. To: customer@example.com
  60. Subject: some new subject
  61. X-Loop: yes
  62. Some Text"
  63. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  64. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  65. perform_enqueued_jobs
  66. assert_equal(1, article_p.ticket.articles.count)
  67. email_raw_string = "From: me@example.com
  68. To: customer@example.com
  69. Subject: some new subject
  70. Precedence: Bulk
  71. Some Text"
  72. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  73. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  74. email_raw_string = "From: me@example.com
  75. To: customer@example.com
  76. Subject: some new subject
  77. Auto-Submitted: auto-generated
  78. Some Text"
  79. perform_enqueued_jobs
  80. assert_equal(1, article_p.ticket.articles.count)
  81. _ticket_p, _article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  82. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  83. email_raw_string = "From: me@example.com
  84. To: customer@example.com
  85. Subject: some new subject
  86. X-Auto-Response-Suppress: All
  87. Some Text"
  88. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  89. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  90. perform_enqueued_jobs
  91. assert_equal(1, article_p.ticket.articles.count)
  92. fqdn = Setting.get('fqdn')
  93. email_raw_string = "From: me@example.com
  94. To: customer@example.com
  95. Subject: some new subject
  96. Message-ID: <1234@#{fqdn}>
  97. Some Text"
  98. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  99. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  100. perform_enqueued_jobs
  101. assert_equal(1, article_p.ticket.articles.count)
  102. fqdn = Setting.get('fqdn')
  103. email_raw_string = "From: me@example.com
  104. To: customer@example.com
  105. Subject: some new subject
  106. Message-ID: <1234@not_matching.#{fqdn}>
  107. Some Text"
  108. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  109. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  110. perform_enqueued_jobs
  111. assert_equal(2, article_p.ticket.articles.count)
  112. email_raw_string = "Return-Path: <XX@XX.XX>
  113. X-Original-To: sales@zammad.com
  114. Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])
  115. by mail.zammad.com (Postfix) with ESMTPS id C3AED5FE2E
  116. for <sales@zammad.com>; Mon, 22 Aug 2016 19:03:15 +0200 (CEST)
  117. Received: by mail-qk0-f170.example.com with SMTP id t7so87721720qkh.1
  118. for <sales@zammad.com>; Mon, 22 Aug 2016 10:03:15 -0700 (PDT)
  119. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  120. d=XX.XX; s=example;
  121. h=to:from:date:message-id:subject:mime-version:precedence
  122. :auto-submitted:content-transfer-encoding:content-disposition;
  123. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  124. b=CIk3PLELgjOCagyiFFbd6rlb8ZRDGYRUrg5Dntxa7e5X+PT4cgL+IE13N9TFkK8ZUJ
  125. GohlaPLGiBymIYLTtYMKUpcf22oiX8ZgGiSu1aEMC1Gsa1ZDf+vpy4kd4+7EecRT3IWF
  126. 4RafQxeaqe67budhQpO1Z6UAel6BdJj0xguKM=
  127. X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  128. d=1e100.net; s=20130820;
  129. h=x-gm-message-state:to:from:date:message-id:subject:mime-version
  130. :precedence:auto-submitted:content-transfer-encoding
  131. :content-disposition;
  132. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  133. b=PYULo3xigc4O/cuNZ79OathQ5HDMFWWIwUxz6CHbpXDQR5k3EPy/skJU1992hVz9Rl
  134. xiGwScBCkMqOjlxHjQSWhFJIxNtdvMk4m0bixBZ79IEvRuQa9cEbqjf6efnV58br5ftQ
  135. 2osHrtQczoSqLE/d61/o102RfQ0avVyX8XNJik0iepg8MiCY7LTOE9hrbnuDDLxgQecH
  136. rMEfkR7bafcUj1YEto5Vd7uV11cVZYx8UIQqVAVbfygv8dTSFeOzz3NyM0M41rRexfYH
  137. 79Yi5i7z/Wk6q2427wkJ3FIR1B7VQVQEmcq/Texbch+gAXPGBNPUHdg2WHt7NXGktrHL
  138. d3DA==
  139. X-Gm-Message-State: AE9vXwMCTnihGiG/tc7xNNlhFLcEK6DPp7otypJg5e4alD3xGK2R707BP29druIi/mcdNyaHg1vP5lSZ8EvrwvOF8iA0HNFhECGjBTJ40YrSJAR8E89xVwxFv/er+U3vEpqmPmt+hL4QhxK/+D2gKOcHSxku
  140. X-Received: by 10.1.1.1 with SMTP id 17mr25015996qkf.279.1471885393931;
  141. Mon, 22 Aug 2016 10:03:13 -0700 (PDT)
  142. To: sales@zammad.com
  143. From: \"XXX\" <XX@XX.XX>
  144. Date: Mon, 22 Aug 2016 10:03:13 -0700
  145. Message-ID: <CA+kqV8PH1DU+zcSx3M00Hrm_oJedRLjbgAUdoi9p0+sMwYsyUg@mail.gmail.com>
  146. Subject: XX PieroXXway - vacation response RE: Callback Request: XX XX [Ticket#1118974]
  147. MIME-Version: 1.0
  148. Precedence: bulk
  149. X-Autoreply: yes
  150. Auto-Submitted: auto-replied
  151. Content-Type: text/html; charset=UTF-8
  152. Content-Transfer-Encoding: quoted-printable
  153. Content-Disposition: inline
  154. test"
  155. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  156. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  157. perform_enqueued_jobs
  158. assert_equal(1, article_p.ticket.articles.count)
  159. # add an agent notification
  160. Trigger.create!(
  161. name: '001 additional agent notification',
  162. condition: {
  163. 'ticket.state_id' => {
  164. 'operator' => 'is',
  165. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  166. }
  167. },
  168. perform: {
  169. 'notification.email' => {
  170. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  171. 'recipient' => 'ticket_agents',
  172. 'subject' => 'New Ticket add. info (#{ticket.title})!',
  173. },
  174. 'ticket.priority_id' => {
  175. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  176. },
  177. 'ticket.tags' => {
  178. 'operator' => 'add',
  179. 'value' => 'aa, kk, agent-notification',
  180. },
  181. },
  182. disable_notification: true,
  183. active: true,
  184. created_by_id: 1,
  185. updated_by_id: 1,
  186. )
  187. email_raw_string = "From: me@example.com
  188. To: customer@example.com
  189. Subject: some new subject
  190. X-Loop: yes
  191. Some Text"
  192. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  193. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  194. perform_enqueued_jobs
  195. tags = ticket_p.tag_list
  196. assert_equal('new', ticket_p.state.name)
  197. assert_equal('3 high', ticket_p.priority.name)
  198. assert(tags.include?('aa'))
  199. assert(tags.include?('kk'))
  200. assert(tags.include?('agent-notification'))
  201. assert_equal(3, tags.count)
  202. assert_equal(2, article_p.ticket.articles.count)
  203. article_customer = article_p.ticket.articles.first
  204. assert_equal('me@example.com', article_customer.from)
  205. assert_equal('customer@example.com', article_customer.to)
  206. assert_equal('Customer', article_customer.sender.name)
  207. assert_equal('email', article_customer.type.name)
  208. article_notification = article_p.ticket.articles[1]
  209. assert_match(%r{New Ticket add. info}, article_notification.subject)
  210. assert_no_match(%r{me@example.com}, article_notification.to)
  211. assert_match(%r{#{agent1.email}}, article_notification.to)
  212. assert_equal('System', article_notification.sender.name)
  213. assert_equal('email', article_notification.type.name)
  214. Setting.set('ticket_trigger_recursive', true)
  215. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  216. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  217. perform_enqueued_jobs
  218. tags = ticket_p.tag_list
  219. assert_equal('new', ticket_p.state.name)
  220. assert_equal('3 high', ticket_p.priority.name)
  221. assert(tags.include?('aa'))
  222. assert(tags.include?('kk'))
  223. assert(tags.include?('agent-notification'))
  224. assert_equal(3, tags.count)
  225. assert_equal(2, article_p.ticket.articles.count)
  226. article_customer = article_p.ticket.articles.first
  227. assert_equal('me@example.com', article_customer.from)
  228. assert_equal('customer@example.com', article_customer.to)
  229. assert_equal('Customer', article_customer.sender.name)
  230. assert_equal('email', article_customer.type.name)
  231. article_notification = article_p.ticket.articles[1]
  232. assert_match(%r{New Ticket add. info}, article_notification.subject)
  233. assert_no_match(%r{me@example.com}, article_notification.to)
  234. assert_match(%r{#{agent1.email}}, article_notification.to)
  235. assert_equal('System', article_notification.sender.name)
  236. assert_equal('email', article_notification.type.name)
  237. Setting.set('ticket_trigger_recursive', false)
  238. email_raw_string = "From: me@example.com
  239. To: customer@example.com
  240. Subject: some new subject
  241. Some Text"
  242. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  243. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  244. perform_enqueued_jobs
  245. tags = ticket_p.tag_list
  246. assert_equal('new', ticket_p.state.name)
  247. assert_equal('3 high', ticket_p.priority.name)
  248. assert(tags.include?('aa'))
  249. assert(tags.include?('kk'))
  250. assert(tags.include?('agent-notification'))
  251. assert(tags.include?('auto-reply'))
  252. assert_equal(3, article_p.ticket.articles.count)
  253. article_customer = article_p.ticket.articles[0]
  254. assert_equal('me@example.com', article_customer.from)
  255. assert_equal('customer@example.com', article_customer.to)
  256. assert_equal('Customer', article_customer.sender.name)
  257. assert_equal('email', article_customer.type.name)
  258. article_notification = article_p.ticket.articles[1]
  259. assert_match(%r{New Ticket add. info}, article_notification.subject)
  260. assert_no_match(%r{me@example.com}, article_notification.to)
  261. assert_match(%r{#{agent1.email}}, article_notification.to)
  262. assert_equal('System', article_notification.sender.name)
  263. assert_equal('email', article_notification.type.name)
  264. article_auto_reply = article_p.ticket.articles[2]
  265. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  266. assert_match(%r{me@example.com}, article_auto_reply.to)
  267. assert_equal('System', article_auto_reply.sender.name)
  268. assert_equal('email', article_auto_reply.type.name)
  269. Setting.set('ticket_trigger_recursive', true)
  270. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  271. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  272. perform_enqueued_jobs
  273. tags = ticket_p.tag_list
  274. assert_equal('new', ticket_p.state.name)
  275. assert_equal('3 high', ticket_p.priority.name)
  276. assert(tags.include?('aa'))
  277. assert(tags.include?('kk'))
  278. assert(tags.include?('agent-notification'))
  279. assert(tags.include?('auto-reply'))
  280. assert_equal(3, article_p.ticket.articles.count)
  281. article_customer = article_p.ticket.articles[0]
  282. assert_equal('me@example.com', article_customer.from)
  283. assert_equal('customer@example.com', article_customer.to)
  284. assert_equal('Customer', article_customer.sender.name)
  285. assert_equal('email', article_customer.type.name)
  286. article_notification = article_p.ticket.articles[1]
  287. assert_match(%r{New Ticket add. info}, article_notification.subject)
  288. assert_no_match(%r{me@example.com}, article_notification.to)
  289. assert_match(%r{#{agent1.email}}, article_notification.to)
  290. assert_equal('System', article_notification.sender.name)
  291. assert_equal('email', article_notification.type.name)
  292. article_auto_reply = article_p.ticket.articles[2]
  293. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  294. assert_match(%r{me@example.com}, article_auto_reply.to)
  295. assert_equal('System', article_auto_reply.sender.name)
  296. assert_equal('email', article_auto_reply.type.name)
  297. end
  298. test 'process auto reply check - 2' do
  299. roles = Role.where(name: 'Agent')
  300. agent1 = User.create!(
  301. login: 'ticket-auto-responder-agent1@example.com',
  302. firstname: 'AutoReponder',
  303. lastname: 'Agent1',
  304. email: 'ticket-auto-responder-agent1@example.com',
  305. password: 'agentpw',
  306. active: true,
  307. roles: roles,
  308. groups: Group.all,
  309. updated_by_id: 1,
  310. created_by_id: 1,
  311. )
  312. Trigger.create!(
  313. name: '001 auto reply',
  314. condition: {
  315. 'ticket.action' => {
  316. 'operator' => 'is',
  317. 'value' => 'create',
  318. },
  319. 'ticket.state_id' => {
  320. 'operator' => 'is',
  321. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  322. }
  323. },
  324. perform: {
  325. 'notification.email' => {
  326. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  327. 'recipient' => 'ticket_customer',
  328. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  329. },
  330. 'ticket.priority_id' => {
  331. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  332. },
  333. 'ticket.tags' => {
  334. 'operator' => 'add',
  335. 'value' => 'aa, kk, auto-reply',
  336. },
  337. },
  338. disable_notification: true,
  339. active: true,
  340. created_by_id: 1,
  341. updated_by_id: 1,
  342. )
  343. email_raw_string = "From: me@example.com
  344. To: customer@example.com
  345. Subject: some new subject
  346. Some Text"
  347. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  348. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  349. perform_enqueued_jobs
  350. assert_equal(2, article_p.ticket.articles.count)
  351. email_raw_string = "From: me@example.com
  352. To: customer@example.com
  353. Subject: some new subject
  354. X-Loop: yes
  355. Some Text"
  356. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  357. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  358. perform_enqueued_jobs
  359. assert_equal(1, article_p.ticket.articles.count)
  360. email_raw_string = "From: me@example.com
  361. To: customer@example.com
  362. Subject: some new subject
  363. Precedence: Bulk
  364. Some Text"
  365. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  366. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  367. email_raw_string = "From: me@example.com
  368. To: customer@example.com
  369. Subject: some new subject
  370. Auto-Submitted: auto-generated
  371. Some Text"
  372. perform_enqueued_jobs
  373. assert_equal(1, article_p.ticket.articles.count)
  374. _ticket_p, _article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  375. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  376. email_raw_string = "From: me@example.com
  377. To: customer@example.com
  378. Subject: some new subject
  379. X-Auto-Response-Suppress: All
  380. Some Text"
  381. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  382. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  383. perform_enqueued_jobs
  384. assert_equal(1, article_p.ticket.articles.count)
  385. fqdn = Setting.get('fqdn')
  386. email_raw_string = "From: me@example.com
  387. To: customer@example.com
  388. Subject: some new subject
  389. Message-ID: <1234@#{fqdn}>
  390. Some Text"
  391. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  392. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  393. perform_enqueued_jobs
  394. assert_equal(1, article_p.ticket.articles.count)
  395. fqdn = Setting.get('fqdn')
  396. email_raw_string = "From: me@example.com
  397. To: customer@example.com
  398. Subject: some new subject
  399. Message-ID: <1234@not_matching.#{fqdn}>
  400. Some Text"
  401. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  402. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  403. perform_enqueued_jobs
  404. assert_equal(2, article_p.ticket.articles.count)
  405. email_raw_string = "Return-Path: <XX@XX.XX>
  406. X-Original-To: sales@zammad.com
  407. Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])
  408. by mail.zammad.com (Postfix) with ESMTPS id C3AED5FE2E
  409. for <sales@zammad.com>; Mon, 22 Aug 2016 19:03:15 +0200 (CEST)
  410. Received: by mail-qk0-f170.example.com with SMTP id t7so87721720qkh.1
  411. for <sales@zammad.com>; Mon, 22 Aug 2016 10:03:15 -0700 (PDT)
  412. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  413. d=XX.XX; s=example;
  414. h=to:from:date:message-id:subject:mime-version:precedence
  415. :auto-submitted:content-transfer-encoding:content-disposition;
  416. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  417. b=CIk3PLELgjOCagyiFFbd6rlb8ZRDGYRUrg5Dntxa7e5X+PT4cgL+IE13N9TFkK8ZUJ
  418. GohlaPLGiBymIYLTtYMKUpcf22oiX8ZgGiSu1aEMC1Gsa1ZDf+vpy4kd4+7EecRT3IWF
  419. 4RafQxeaqe67budhQpO1Z6UAel6BdJj0xguKM=
  420. X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  421. d=1e100.net; s=20130820;
  422. h=x-gm-message-state:to:from:date:message-id:subject:mime-version
  423. :precedence:auto-submitted:content-transfer-encoding
  424. :content-disposition;
  425. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  426. b=PYULo3xigc4O/cuNZ79OathQ5HDMFWWIwUxz6CHbpXDQR5k3EPy/skJU1992hVz9Rl
  427. xiGwScBCkMqOjlxHjQSWhFJIxNtdvMk4m0bixBZ79IEvRuQa9cEbqjf6efnV58br5ftQ
  428. 2osHrtQczoSqLE/d61/o102RfQ0avVyX8XNJik0iepg8MiCY7LTOE9hrbnuDDLxgQecH
  429. rMEfkR7bafcUj1YEto5Vd7uV11cVZYx8UIQqVAVbfygv8dTSFeOzz3NyM0M41rRexfYH
  430. 79Yi5i7z/Wk6q2427wkJ3FIR1B7VQVQEmcq/Texbch+gAXPGBNPUHdg2WHt7NXGktrHL
  431. d3DA==
  432. X-Gm-Message-State: AE9vXwMCTnihGiG/tc7xNNlhFLcEK6DPp7otypJg5e4alD3xGK2R707BP29druIi/mcdNyaHg1vP5lSZ8EvrwvOF8iA0HNFhECGjBTJ40YrSJAR8E89xVwxFv/er+U3vEpqmPmt+hL4QhxK/+D2gKOcHSxku
  433. X-Received: by 10.1.1.1 with SMTP id 17mr25015996qkf.279.1471885393931;
  434. Mon, 22 Aug 2016 10:03:13 -0700 (PDT)
  435. To: sales@zammad.com
  436. From: \"XXX\" <XX@XX.XX>
  437. Date: Mon, 22 Aug 2016 10:03:13 -0700
  438. Message-ID: <CA+kqV8PH1DU+zcSx3M00Hrm_oJedRLjbgAUdoi9p0+sMwYsyUg@mail.gmail.com>
  439. Subject: XX PieroXXway - vacation response RE: Callback Request: XX XX [Ticket#1118974]
  440. MIME-Version: 1.0
  441. Precedence: bulk
  442. X-Autoreply: yes
  443. Auto-Submitted: auto-replied
  444. Content-Type: text/html; charset=UTF-8
  445. Content-Transfer-Encoding: quoted-printable
  446. Content-Disposition: inline
  447. test"
  448. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  449. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  450. perform_enqueued_jobs
  451. assert_equal(1, article_p.ticket.articles.count)
  452. # add an agent notification
  453. Trigger.create!(
  454. name: '002 additional agent notification',
  455. condition: {
  456. 'ticket.state_id' => {
  457. 'operator' => 'is',
  458. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  459. }
  460. },
  461. perform: {
  462. 'notification.email' => {
  463. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  464. 'recipient' => 'ticket_agents',
  465. 'subject' => 'New Ticket add. info (#{ticket.title})!',
  466. },
  467. 'ticket.priority_id' => {
  468. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  469. },
  470. 'ticket.tags' => {
  471. 'operator' => 'add',
  472. 'value' => 'aa, kk, agent-notification',
  473. },
  474. },
  475. disable_notification: true,
  476. active: true,
  477. created_by_id: 1,
  478. updated_by_id: 1,
  479. )
  480. email_raw_string = "From: me@example.com
  481. To: customer@example.com
  482. Subject: some new subject
  483. X-Loop: yes
  484. Some Text"
  485. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  486. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  487. perform_enqueued_jobs
  488. tags = ticket_p.tag_list
  489. assert_equal('new', ticket_p.state.name)
  490. assert_equal('3 high', ticket_p.priority.name)
  491. assert(tags.include?('aa'))
  492. assert(tags.include?('kk'))
  493. assert(tags.include?('agent-notification'))
  494. assert_equal(3, tags.count)
  495. assert_equal(2, article_p.ticket.articles.count)
  496. article_customer = article_p.ticket.articles.first
  497. assert_equal('me@example.com', article_customer.from)
  498. assert_equal('customer@example.com', article_customer.to)
  499. assert_equal('Customer', article_customer.sender.name)
  500. assert_equal('email', article_customer.type.name)
  501. article_notification = article_p.ticket.articles[1]
  502. assert_match(%r{New Ticket add. info}, article_notification.subject)
  503. assert_no_match(%r{me@example.com}, article_notification.to)
  504. assert_match(%r{#{agent1.email}}, article_notification.to)
  505. assert_equal('System', article_notification.sender.name)
  506. assert_equal('email', article_notification.type.name)
  507. Setting.set('ticket_trigger_recursive', true)
  508. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  509. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  510. perform_enqueued_jobs
  511. tags = ticket_p.tag_list
  512. assert_equal('new', ticket_p.state.name)
  513. assert_equal('3 high', ticket_p.priority.name)
  514. assert(tags.include?('aa'))
  515. assert(tags.include?('kk'))
  516. assert(tags.include?('agent-notification'))
  517. assert_equal(3, tags.count)
  518. assert_equal(2, article_p.ticket.articles.count)
  519. article_customer = article_p.ticket.articles.first
  520. assert_equal('me@example.com', article_customer.from)
  521. assert_equal('customer@example.com', article_customer.to)
  522. assert_equal('Customer', article_customer.sender.name)
  523. assert_equal('email', article_customer.type.name)
  524. article_notification = article_p.ticket.articles[1]
  525. assert_match(%r{New Ticket add. info}, article_notification.subject)
  526. assert_no_match(%r{me@example.com}, article_notification.to)
  527. assert_match(%r{#{agent1.email}}, article_notification.to)
  528. assert_equal('System', article_notification.sender.name)
  529. assert_equal('email', article_notification.type.name)
  530. Setting.set('ticket_trigger_recursive', false)
  531. email_raw_string = "From: me@example.com
  532. To: customer@example.com
  533. Subject: some new subject
  534. Some Text"
  535. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  536. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  537. perform_enqueued_jobs
  538. tags = ticket_p.tag_list
  539. assert_equal('new', ticket_p.state.name)
  540. assert_equal('3 high', ticket_p.priority.name)
  541. assert(tags.include?('aa'))
  542. assert(tags.include?('kk'))
  543. assert(tags.include?('agent-notification'))
  544. assert(tags.include?('auto-reply'))
  545. assert_equal(3, article_p.ticket.articles.count)
  546. article_customer = article_p.ticket.articles[0]
  547. assert_equal('me@example.com', article_customer.from)
  548. assert_equal('customer@example.com', article_customer.to)
  549. assert_equal('Customer', article_customer.sender.name)
  550. assert_equal('email', article_customer.type.name)
  551. article_auto_reply = article_p.ticket.articles[1]
  552. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  553. assert_match(%r{me@example.com}, article_auto_reply.to)
  554. assert_equal('System', article_auto_reply.sender.name)
  555. assert_equal('email', article_auto_reply.type.name)
  556. article_notification = article_p.ticket.articles[2]
  557. assert_match(%r{New Ticket add. info}, article_notification.subject)
  558. assert_no_match(%r{me@example.com}, article_notification.to)
  559. assert_match(%r{#{agent1.email}}, article_notification.to)
  560. assert_equal('System', article_notification.sender.name)
  561. assert_equal('email', article_notification.type.name)
  562. Setting.set('ticket_trigger_recursive', true)
  563. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  564. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  565. perform_enqueued_jobs
  566. tags = ticket_p.tag_list
  567. assert_equal('new', ticket_p.state.name)
  568. assert_equal('3 high', ticket_p.priority.name)
  569. assert(tags.include?('aa'))
  570. assert(tags.include?('kk'))
  571. assert(tags.include?('agent-notification'))
  572. assert(tags.include?('auto-reply'))
  573. assert_equal(3, article_p.ticket.articles.count)
  574. article_customer = article_p.ticket.articles[0]
  575. assert_equal('me@example.com', article_customer.from)
  576. assert_equal('customer@example.com', article_customer.to)
  577. assert_equal('Customer', article_customer.sender.name)
  578. assert_equal('email', article_customer.type.name)
  579. article_auto_reply = article_p.ticket.articles[1]
  580. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  581. assert_match(%r{me@example.com}, article_auto_reply.to)
  582. assert_equal('System', article_auto_reply.sender.name)
  583. assert_equal('email', article_auto_reply.type.name)
  584. article_notification = article_p.ticket.articles[2]
  585. assert_match(%r{New Ticket add. info}, article_notification.subject)
  586. assert_no_match(%r{me@example.com}, article_notification.to)
  587. assert_match(%r{#{agent1.email}}, article_notification.to)
  588. assert_equal('System', article_notification.sender.name)
  589. assert_equal('email', article_notification.type.name)
  590. end
  591. test 'process auto reply check - recursive' do
  592. roles = Role.where(name: 'Agent')
  593. agent1 = User.create!(
  594. login: 'ticket-auto-responder-agent1@example.com',
  595. firstname: 'AutoReponder',
  596. lastname: 'Agent1',
  597. email: 'ticket-auto-responder-agent1@example.com',
  598. password: 'agentpw',
  599. active: true,
  600. roles: roles,
  601. groups: Group.all,
  602. updated_by_id: 1,
  603. created_by_id: 1,
  604. )
  605. Trigger.create!(
  606. name: '001 auto reply',
  607. condition: {
  608. 'ticket.action' => {
  609. 'operator' => 'is',
  610. 'value' => 'create',
  611. },
  612. 'ticket.state_id' => {
  613. 'operator' => 'is',
  614. 'value' => Ticket::State.lookup(name: 'open').id.to_s,
  615. }
  616. },
  617. perform: {
  618. 'notification.email' => {
  619. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  620. 'recipient' => 'ticket_customer',
  621. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  622. },
  623. 'ticket.priority_id' => {
  624. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  625. },
  626. 'ticket.tags' => {
  627. 'operator' => 'add',
  628. 'value' => 'aa, kk, auto-reply',
  629. },
  630. },
  631. disable_notification: true,
  632. active: true,
  633. created_by_id: 1,
  634. updated_by_id: 1,
  635. )
  636. # add an agent notification
  637. Trigger.create!(
  638. name: '002 additional agent notification',
  639. condition: {
  640. 'ticket.state_id' => {
  641. 'operator' => 'is',
  642. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  643. }
  644. },
  645. perform: {
  646. 'notification.email' => {
  647. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  648. 'recipient' => 'ticket_agents',
  649. 'subject' => 'New Ticket add. info (#{ticket.title})!',
  650. },
  651. 'ticket.priority_id' => {
  652. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  653. },
  654. 'ticket.state_id' => {
  655. 'value' => Ticket::State.lookup(name: 'open').id.to_s,
  656. },
  657. 'ticket.tags' => {
  658. 'operator' => 'add',
  659. 'value' => 'aa, kk, agent-notification',
  660. },
  661. },
  662. disable_notification: true,
  663. active: true,
  664. created_by_id: 1,
  665. updated_by_id: 1,
  666. )
  667. email_raw_string = "From: me@example.com
  668. To: customer@example.com
  669. Subject: some new subject
  670. X-Loop: yes
  671. Some Text"
  672. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  673. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  674. perform_enqueued_jobs
  675. tags = ticket_p.tag_list
  676. assert_equal('open', ticket_p.state.name)
  677. assert_equal('3 high', ticket_p.priority.name)
  678. assert(tags.include?('aa'))
  679. assert(tags.include?('kk'))
  680. assert(tags.include?('agent-notification'))
  681. assert_equal(3, tags.count)
  682. assert_equal(2, article_p.ticket.articles.count)
  683. article_customer = article_p.ticket.articles.first
  684. assert_equal('me@example.com', article_customer.from)
  685. assert_equal('customer@example.com', article_customer.to)
  686. assert_equal('Customer', article_customer.sender.name)
  687. assert_equal('email', article_customer.type.name)
  688. article_notification = article_p.ticket.articles[1]
  689. assert_match(%r{New Ticket add. info}, article_notification.subject)
  690. assert_no_match(%r{me@example.com}, article_notification.to)
  691. assert_match(%r{#{agent1.email}}, article_notification.to)
  692. assert_equal('System', article_notification.sender.name)
  693. assert_equal('email', article_notification.type.name)
  694. Setting.set('ticket_trigger_recursive', true)
  695. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  696. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  697. perform_enqueued_jobs
  698. tags = ticket_p.tag_list
  699. assert_equal('open', ticket_p.state.name)
  700. assert_equal('3 high', ticket_p.priority.name)
  701. assert(tags.include?('aa'))
  702. assert(tags.include?('kk'))
  703. assert(tags.include?('agent-notification'))
  704. assert_equal(3, tags.count)
  705. assert_equal(2, article_p.ticket.articles.count)
  706. article_customer = article_p.ticket.articles.first
  707. assert_equal('me@example.com', article_customer.from)
  708. assert_equal('customer@example.com', article_customer.to)
  709. assert_equal('Customer', article_customer.sender.name)
  710. assert_equal('email', article_customer.type.name)
  711. article_notification = article_p.ticket.articles[1]
  712. assert_match(%r{New Ticket add. info}, article_notification.subject)
  713. assert_no_match(%r{me@example.com}, article_notification.to)
  714. assert_match(%r{#{agent1.email}}, article_notification.to)
  715. assert_equal('System', article_notification.sender.name)
  716. assert_equal('email', article_notification.type.name)
  717. Setting.set('ticket_trigger_recursive', false)
  718. email_raw_string = "From: me@example.com
  719. To: customer@example.com
  720. Subject: some new subject
  721. Some Text"
  722. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  723. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  724. perform_enqueued_jobs
  725. tags = ticket_p.tag_list
  726. assert_equal('open', ticket_p.state.name)
  727. assert_equal('3 high', ticket_p.priority.name)
  728. assert(tags.include?('aa'))
  729. assert(tags.include?('kk'))
  730. assert(tags.include?('agent-notification'))
  731. assert_equal(2, article_p.ticket.articles.count)
  732. article_customer = article_p.ticket.articles[0]
  733. assert_equal('me@example.com', article_customer.from)
  734. assert_equal('customer@example.com', article_customer.to)
  735. assert_equal('Customer', article_customer.sender.name)
  736. assert_equal('email', article_customer.type.name)
  737. article_notification = article_p.ticket.articles[1]
  738. assert_match(%r{New Ticket add. info}, article_notification.subject)
  739. assert_no_match(%r{me@example.com}, article_notification.to)
  740. assert_match(%r{#{agent1.email}}, article_notification.to)
  741. assert_equal('System', article_notification.sender.name)
  742. assert_equal('email', article_notification.type.name)
  743. Setting.set('ticket_trigger_recursive', true)
  744. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  745. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  746. perform_enqueued_jobs
  747. tags = ticket_p.tag_list
  748. assert_equal('open', ticket_p.state.name)
  749. assert_equal('3 high', ticket_p.priority.name)
  750. assert(tags.include?('aa'))
  751. assert(tags.include?('kk'))
  752. assert(tags.include?('agent-notification'))
  753. assert(tags.include?('auto-reply'))
  754. assert_equal(3, article_p.ticket.articles.count)
  755. article_customer = article_p.ticket.articles[0]
  756. assert_equal('me@example.com', article_customer.from)
  757. assert_equal('customer@example.com', article_customer.to)
  758. assert_equal('Customer', article_customer.sender.name)
  759. assert_equal('email', article_customer.type.name)
  760. article_notification = article_p.ticket.articles[1]
  761. assert_match(%r{New Ticket add. info}, article_notification.subject)
  762. assert_no_match(%r{me@example.com}, article_notification.to)
  763. assert_match(%r{#{agent1.email}}, article_notification.to)
  764. assert_equal('System', article_notification.sender.name)
  765. assert_equal('email', article_notification.type.name)
  766. article_auto_reply = article_p.ticket.articles[2]
  767. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  768. assert_match(%r{me@example.com}, article_auto_reply.to)
  769. assert_equal('System', article_auto_reply.sender.name)
  770. assert_equal('email', article_auto_reply.type.name)
  771. end
  772. end